dsh-plugin-explorer 0.1.2 → 0.2.1

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
@@ -9,8 +9,10 @@ window.__ModuleLoader__.load({
9
9
  const NS = 'pluginFinder'
10
10
  /** Results shown per page. */
11
11
  const PAGE_SIZE = 30
12
- /** Exact Fetch route the Host half serves. */
12
+ /** Exact Fetch routes the Host half serves. */
13
13
  const CATALOG_PATH = 'api/plugin-finder/catalog.json'
14
+ const SCAN_PATH = 'api/plugin-finder/scan.json'
15
+ const INSTALLED_PATH = 'api/plugin-finder/installed.json'
14
16
 
15
17
  const zh = {
16
18
  title: '搜索',
@@ -26,9 +28,42 @@ window.__ModuleLoader__.load({
26
28
  empty: '没有匹配的插件',
27
29
  install: '安装',
28
30
  more: '加载更多',
29
- note: '目录来自第三方社区索引(CC0),DSH 只校验格式、不验证内容;安装前请核对确认框中的来源。',
31
+ note: '目录来自第三方社区索引(CC0),DSH 只校验格式、不验证内容;安装前请核对确认框中的来源。安装前会先做静态安全检查。',
30
32
  downloads: '{count} 次下载',
31
33
  stars: '{count} 个 GitHub star',
34
+ all: '全部',
35
+ sort: '排序',
36
+ sortHot: '最热',
37
+ sortNew: '最新',
38
+ sortName: '名称',
39
+ installed: '已安装 v{version}',
40
+ update: '更新到 v{version}',
41
+ updateHint: '打开已安装页,在那里完成更新',
42
+ updateBadge: '有新版',
43
+ scanTitle: '安装前安全检查',
44
+ scanSubtitle: '{name}@{version}',
45
+ scanning: '正在下载并扫描 npm 包…',
46
+ scanFailed: '安全检查失败',
47
+ scanFailedHint: '可以跳过检查直接安装,但请先自行核对来源。',
48
+ skipScan: '跳过检查直接安装',
49
+ verdictPass: '通过',
50
+ verdictWarn: '警告',
51
+ verdictBlock: '高风险',
52
+ verdictLow: '低',
53
+ summaryLine: '高 {high} · 中 {medium} · 低 {low}',
54
+ filesScanned: '扫描 {count} 个文件',
55
+ networkHosts: '网络目标:{hosts}',
56
+ networkNone: '未发现网络目标',
57
+ hitsTitle: '命中规则({count})',
58
+ noHits: '未命中任何规则',
59
+ notesLine: '另有 {count} 条扫描提示',
60
+ confirmInstall: '确认安装',
61
+ installAnyway: '仍然安装',
62
+ riskInstall: '我已知风险,仍要安装',
63
+ cancel: '取消',
64
+ scanDisclaimer: '静态规则扫描(源自 dsh-plugin-gate,MIT)只读、不执行代码;结果是启发式判断,不是安全保证。',
65
+ scanCached: '缓存结果',
66
+ installedFailed: '读取已安装插件失败,仍可安装',
32
67
  }
33
68
 
34
69
  const en = {
@@ -45,9 +80,42 @@ window.__ModuleLoader__.load({
45
80
  empty: 'No matching plugins',
46
81
  install: 'Install',
47
82
  more: 'Show more',
48
- note: 'The catalog is a third-party community index (CC0). DSH checks its format, not its content; verify the source in the confirmation dialog before installing.',
83
+ note: 'The catalog is a third-party community index (CC0). DSH checks its format, not its content; verify the source before installing. A static safety scan runs first.',
49
84
  downloads: '{count} downloads',
50
85
  stars: '{count} GitHub stars',
86
+ all: 'All',
87
+ sort: 'Sort',
88
+ sortHot: 'Popular',
89
+ sortNew: 'Newest',
90
+ sortName: 'Name',
91
+ installed: 'Installed v{version}',
92
+ update: 'Update to v{version}',
93
+ updateHint: 'Open the Installed page and finish the update there',
94
+ updateBadge: 'Update',
95
+ scanTitle: 'Pre-install safety scan',
96
+ scanSubtitle: '{name}@{version}',
97
+ scanning: 'Downloading and scanning the npm package…',
98
+ scanFailed: 'Safety scan failed',
99
+ scanFailedHint: 'You can install without the scan, but verify the source yourself first.',
100
+ skipScan: 'Install without scan',
101
+ verdictPass: 'Pass',
102
+ verdictWarn: 'Warning',
103
+ verdictBlock: 'High risk',
104
+ verdictLow: 'Low',
105
+ summaryLine: 'high {high} · medium {medium} · low {low}',
106
+ filesScanned: 'Scanned {count} files',
107
+ networkHosts: 'Network targets: {hosts}',
108
+ networkNone: 'No network targets found',
109
+ hitsTitle: 'Rule hits ({count})',
110
+ noHits: 'No rules matched',
111
+ notesLine: '{count} additional scan notes',
112
+ confirmInstall: 'Install',
113
+ installAnyway: 'Install anyway',
114
+ riskInstall: 'I understand the risk, install',
115
+ cancel: 'Cancel',
116
+ scanDisclaimer: 'Static rule scan (from dsh-plugin-gate, MIT) only reads; it does not execute code. Heuristic results, not a guarantee.',
117
+ scanCached: 'cached result',
118
+ installedFailed: 'Could not read installed plugins; installing still works',
51
119
  }
52
120
 
53
121
  const CATEGORIES = {
@@ -77,7 +145,7 @@ window.__ModuleLoader__.load({
77
145
  }
78
146
 
79
147
  const CSS = `
80
- .pf-root { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
148
+ .pf-root { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
81
149
  .pf-toolbar { display: flex; align-items: center; gap: 8px; }
82
150
  .pf-search { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; }
83
151
  .pf-search-icon { position: absolute; left: 11px; color: var(--dsw-alias-label-secondary); pointer-events: none; }
@@ -102,6 +170,20 @@ window.__ModuleLoader__.load({
102
170
  }
103
171
  .pf-refresh:hover:not(:disabled) { border-color: var(--dsw-alias-border-l2); color: var(--dsw-alias-label-primary); }
104
172
  .pf-refresh:disabled { opacity: 0.6; cursor: default; }
173
+ .pf-filters { display: flex; align-items: center; gap: 10px; min-width: 0; }
174
+ .pf-chips { display: flex; gap: 6px; overflow-x: auto; flex: 1; min-width: 0; padding-bottom: 2px; scrollbar-width: thin; }
175
+ .pf-chip {
176
+ flex: none; border: 1px solid var(--dsw-alias-border-l1); background: transparent;
177
+ color: var(--dsw-alias-label-secondary); border-radius: 999px; padding: 4px 10px;
178
+ font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap;
179
+ }
180
+ .pf-chip:hover { border-color: var(--dsw-alias-border-l2); color: var(--dsw-alias-label-primary); }
181
+ .pf-chip[data-active="true"] { background: var(--dsw-alias-brand-primary); border-color: transparent; color: #ffffff; }
182
+ .pf-sort {
183
+ flex: none; height: 30px; border-radius: 8px; border: 1px solid var(--dsw-alias-border-l1);
184
+ background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-secondary);
185
+ font: inherit; font-size: 12px; padding: 0 6px; cursor: pointer;
186
+ }
105
187
  .pf-summary { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--dsw-alias-label-secondary); }
106
188
  .pf-warn { color: var(--dsw-alias-state-warn-primary); }
107
189
  .pf-state {
@@ -130,13 +212,18 @@ window.__ModuleLoader__.load({
130
212
  margin: 6px 0 0; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary);
131
213
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
132
214
  }
133
- .pf-side { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; padding-left: 4px; }
215
+ .pf-side { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; padding-left: 4px; }
134
216
  .pf-stat { font-size: 11px; color: var(--dsw-alias-label-secondary); white-space: nowrap; }
135
217
  .pf-install {
136
218
  border: 0; border-radius: 8px; padding: 6px 14px; background: var(--dsw-alias-brand-primary);
137
219
  color: #ffffff; font: inherit; font-size: 12px; cursor: pointer;
138
220
  }
139
221
  .pf-install:hover { filter: brightness(1.08); }
222
+ .pf-badge {
223
+ font-size: 11px; color: var(--dsw-alias-label-secondary);
224
+ border: 1px solid var(--dsw-alias-border-l1); border-radius: 6px; padding: 2px 7px; white-space: nowrap;
225
+ }
226
+ .pf-badge-new { color: var(--dsw-alias-state-warn-primary); border-color: currentColor; }
140
227
  .pf-more {
141
228
  align-self: center; margin-top: 2px; padding: 7px 16px; border-radius: 9px;
142
229
  border: 1px solid var(--dsw-alias-border-l1); background: transparent;
@@ -144,6 +231,55 @@ window.__ModuleLoader__.load({
144
231
  }
145
232
  .pf-more:hover { border-color: var(--dsw-alias-border-l2); color: var(--dsw-alias-label-primary); }
146
233
  .pf-note { font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-secondary); }
234
+ .pf-overlay {
235
+ position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
236
+ padding: 16px; background: rgba(0, 0, 0, 0.45);
237
+ }
238
+ .pf-dialog {
239
+ width: min(720px, 100%); max-height: min(80vh, 760px); overflow: auto;
240
+ background: var(--dsw-alias-bg-layer-1); border: 1px solid var(--dsw-alias-border-l1);
241
+ border-radius: 14px; padding: 20px; box-shadow: 0 16px 48px rgba(0, 0, 0, 0.32);
242
+ display: flex; flex-direction: column; gap: 12px;
243
+ }
244
+ .pf-dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
245
+ .pf-dialog-title { margin: 0; font-size: 15px; font-weight: 600; color: var(--dsw-alias-label-primary); }
246
+ .pf-dialog-sub { margin-top: 4px; font-size: 12px; color: var(--dsw-alias-label-secondary); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
247
+ .pf-close {
248
+ flex: none; width: 28px; height: 28px; border: 0; border-radius: 8px; background: transparent;
249
+ color: var(--dsw-alias-label-secondary); font-size: 18px; line-height: 1; cursor: pointer;
250
+ }
251
+ .pf-close:hover { background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-primary); }
252
+ .pf-verdict { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
253
+ .pf-verdict-badge { font-size: 13px; font-weight: 700; padding: 4px 12px; border-radius: 999px; border: 1px solid currentColor; }
254
+ .pf-verdict-pass { color: light-dark(#1a7f37, #3fb950); }
255
+ .pf-verdict-warn { color: var(--dsw-alias-state-warn-primary); }
256
+ .pf-verdict-block { color: light-dark(#cf222e, #f85149); }
257
+ .pf-scan-meta { font-size: 12px; color: var(--dsw-alias-label-secondary); display: flex; flex-wrap: wrap; gap: 4px 14px; }
258
+ .pf-hits { display: flex; flex-direction: column; gap: 6px; }
259
+ .pf-hits-title { font-size: 12px; font-weight: 600; color: var(--dsw-alias-label-primary); margin-top: 4px; }
260
+ .pf-hit {
261
+ font-size: 11px; line-height: 16px; padding: 8px 10px; border-radius: 8px;
262
+ background: var(--dsw-alias-bg-layer-2); border-left: 3px solid var(--dsw-alias-border-l1);
263
+ }
264
+ .pf-hit[data-sev="high"] { border-left-color: light-dark(#cf222e, #f85149); }
265
+ .pf-hit[data-sev="medium"] { border-left-color: var(--dsw-alias-state-warn-primary); }
266
+ .pf-hit[data-sev="low"] { border-left-color: var(--dsw-alias-border-l2); }
267
+ .pf-hit-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
268
+ .pf-hit-rule { font-weight: 600; color: var(--dsw-alias-label-primary); }
269
+ .pf-hit-file { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; color: var(--dsw-alias-label-secondary); word-break: break-all; }
270
+ .pf-hit-evidence { margin-top: 4px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; color: var(--dsw-alias-label-secondary); word-break: break-all; }
271
+ .pf-hit-hint { margin-top: 4px; color: var(--dsw-alias-label-secondary); }
272
+ .pf-recs { margin: 0; padding-left: 18px; font-size: 11px; line-height: 17px; color: var(--dsw-alias-label-secondary); }
273
+ .pf-disclaimer { font-size: 10px; line-height: 15px; color: var(--dsw-alias-label-secondary); }
274
+ .pf-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
275
+ .pf-button {
276
+ border: 1px solid var(--dsw-alias-border-l1); background: transparent; color: var(--dsw-alias-label-primary);
277
+ border-radius: 8px; padding: 7px 14px; font: inherit; font-size: 12px; cursor: pointer;
278
+ }
279
+ .pf-button:hover { border-color: var(--dsw-alias-border-l2); }
280
+ .pf-button-primary { border: 0; background: var(--dsw-alias-brand-primary); color: #ffffff; }
281
+ .pf-button-primary:hover { filter: brightness(1.08); }
282
+ .pf-button-danger { border: 0; background: light-dark(#cf222e, #f85149); color: #ffffff; }
147
283
  .pf-root :focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }
148
284
  @media (max-width: 640px) {
149
285
  .pf-side { flex-direction: row; align-items: center; }
@@ -151,29 +287,55 @@ window.__ModuleLoader__.load({
151
287
  }
152
288
  `
153
289
 
154
- function catalogUrl(refresh) {
155
- return new URL(CATALOG_PATH + (refresh ? '?refresh=1' : ''), document.baseURI)
290
+ function urlFor(path, params) {
291
+ const url = new URL(path, document.baseURI)
292
+ if (params !== undefined) {
293
+ for (const [key, value] of Object.entries(params)) url.searchParams.set(key, value)
294
+ }
295
+ return url
156
296
  }
157
297
 
158
- async function readCatalog(refresh) {
159
- const response = await fetch(catalogUrl(refresh), { credentials: 'same-origin', cache: 'no-store' })
298
+ async function readJson(url) {
299
+ const response = await fetch(url, { credentials: 'same-origin', cache: 'no-store' })
160
300
  if (!response.ok) {
161
301
  let detail = ''
162
302
  try {
163
303
  const body = await response.json()
164
- if (body && typeof body.error === 'string') detail = body.error
304
+ if (body !== null && typeof body === 'object' && typeof body.error === 'string') detail = body.error
165
305
  } catch {
166
306
  detail = ''
167
307
  }
168
308
  throw new Error(detail === '' ? `HTTP ${response.status}` : detail)
169
309
  }
170
- const data = await response.json()
310
+ return response.json()
311
+ }
312
+
313
+ async function readCatalog(refresh) {
314
+ const data = await readJson(urlFor(CATALOG_PATH, refresh ? { refresh: '1' } : undefined))
171
315
  if (data === null || typeof data !== 'object' || !Array.isArray(data.plugins)) {
172
316
  throw new Error('invalid catalog document')
173
317
  }
174
318
  return data
175
319
  }
176
320
 
321
+ async function readInstalled() {
322
+ const data = await readJson(urlFor(INSTALLED_PATH))
323
+ if (data === null || typeof data !== 'object' || !Array.isArray(data.plugins)) {
324
+ throw new Error('invalid installed document')
325
+ }
326
+ return data
327
+ }
328
+
329
+ async function readScan(name, version) {
330
+ const params = { name }
331
+ if (typeof version === 'string' && version !== '') params.version = version
332
+ const data = await readJson(urlFor(SCAN_PATH, params))
333
+ if (data === null || typeof data !== 'object' || typeof data.verdict !== 'string') {
334
+ throw new Error('invalid scan document')
335
+ }
336
+ return data
337
+ }
338
+
177
339
  /** Lowercased description for the active document language. */
178
340
  function currentLanguage() {
179
341
  const declared = document.documentElement && document.documentElement.lang
@@ -216,6 +378,7 @@ window.__ModuleLoader__.load({
216
378
  haystack: [nameLower, ownerLower, categoryLower, description?.zh, description?.en].filter(Boolean).join('\n').toLowerCase(),
217
379
  downloads: Number.isFinite(item.downloads) ? item.downloads : 0,
218
380
  stars: Number.isFinite(item.stars) ? item.stars : 0,
381
+ added: typeof item.added === 'string' ? item.added : '',
219
382
  })
220
383
  }
221
384
  return entries
@@ -268,6 +431,29 @@ window.__ModuleLoader__.load({
268
431
  return matched.map(match => match.entry)
269
432
  }
270
433
 
434
+ /**
435
+ * Apply a category filter and a sort order to the prepared catalog.
436
+ * @param {Array<object>} entries - prepared entries.
437
+ * @param {{category?: string, sort?: string}} [options] - filter and order.
438
+ * @returns {Array<object>} filtered entries.
439
+ */
440
+ function applyFilters(entries, options = {}) {
441
+ const { category, sort } = options
442
+ let out = entries
443
+ if (category !== undefined && category !== '' && category !== 'all') {
444
+ out = out.filter(entry => entry.category === category)
445
+ }
446
+ if (sort === 'name') return [...out].sort((left, right) => left.name.localeCompare(right.name))
447
+ if (sort === 'newest') {
448
+ return [...out].sort((left, right) => (
449
+ String(right.added).localeCompare(String(left.added))
450
+ || right.downloads - left.downloads
451
+ || left.name.localeCompare(right.name)
452
+ ))
453
+ }
454
+ return [...out].sort((left, right) => right.downloads - left.downloads || left.name.localeCompare(right.name))
455
+ }
456
+
271
457
  const compact = new Intl.NumberFormat(undefined, { notation: 'compact', maximumFractionDigits: 1 })
272
458
 
273
459
  function SearchIcon() {
@@ -277,8 +463,21 @@ window.__ModuleLoader__.load({
277
463
  }, h('circle', { cx: 7, cy: 7, r: 4.5 }), h('path', { d: 'M10.5 10.5 14 14', strokeLinecap: 'round' }))
278
464
  }
279
465
 
466
+ function severityLabel(severity, t) {
467
+ if (severity === 'high') return t('verdictBlock')
468
+ if (severity === 'medium') return t('verdictWarn')
469
+ if (severity === 'low') return t('verdictLow')
470
+ return severity
471
+ }
472
+
473
+ /** Find one entry in the installed-plugin document. */
474
+ function installedOf(installed, name) {
475
+ const list = installed !== null && typeof installed === 'object' && Array.isArray(installed.plugins) ? installed.plugins : []
476
+ return list.find(plugin => plugin !== null && typeof plugin === 'object' && plugin.name === name)
477
+ }
478
+
280
479
  function FinderRow(props) {
281
- const { entry, install, language, t } = props
480
+ const { entry, install, onScan, onOpen, installed, language, t } = props
282
481
  const [broken, setBroken] = useState(false)
283
482
  const description = entry.description?.[language] ?? entry.description?.en ?? entry.description?.zh
284
483
  const meta = [entry.owner, categoryLabel(entry.category, language)].filter(Boolean).join(' · ')
@@ -287,6 +486,14 @@ window.__ModuleLoader__.load({
287
486
  : entry.stars > 0
288
487
  ? { text: `${compact.format(entry.stars)} ★`, title: t('stars', { count: entry.stars.toLocaleString() }) }
289
488
  : undefined
489
+ const record = installedOf(installed, entry.name)
490
+ const current = record !== undefined && typeof record.version === 'string' ? record.version : undefined
491
+ const latest = record !== undefined && typeof record.latest === 'string' ? record.latest : undefined
492
+ const hasUpdate = record !== undefined && record.hasUpdate === true && latest !== undefined
493
+ const startScan = (version) => {
494
+ if (typeof onScan === 'function') onScan({ entry, version, mode: hasUpdate ? 'update' : 'install' })
495
+ else if (typeof install === 'function') install({ spec: entry.name + '@' + version, title: entry.name, version })
496
+ }
290
497
  return h('div', { className: 'pf-row', 'data-plugin': entry.name },
291
498
  h('div', { className: 'pf-avatar' },
292
499
  entry.icon !== undefined && !broken
@@ -303,15 +510,106 @@ window.__ModuleLoader__.load({
303
510
  description === undefined || description === '' ? null : h('p', { className: 'pf-desc', title: description }, description)),
304
511
  h('div', { className: 'pf-side' },
305
512
  metric === undefined ? null : h('span', { className: 'pf-stat', title: metric.title }, metric.text),
306
- h('button', {
307
- type: 'button', className: 'pf-install',
308
- onClick: () => { install({ spec: entry.name + '@' + entry.version, title: entry.name, version: entry.version }) },
309
- }, t('install'))))
513
+ current === undefined
514
+ ? null
515
+ : h('span', {
516
+ className: 'pf-badge' + (hasUpdate ? ' pf-badge-new' : ''),
517
+ title: hasUpdate ? t('installed', { version: current }) + ' → ' + latest : undefined,
518
+ }, hasUpdate ? t('installed', { version: current }) + ' → v' + latest : t('installed', { version: current })),
519
+ current === undefined
520
+ ? h('button', {
521
+ type: 'button', className: 'pf-install',
522
+ onClick: () => { startScan(entry.version) },
523
+ }, t('install'))
524
+ : hasUpdate
525
+ ? h('button', {
526
+ type: 'button', className: 'pf-install', title: t('updateHint'),
527
+ onClick: () => {
528
+ // The page's update slot only handles Git bundles; registry packages update on the
529
+ // Installed page, so jump there and let its own version check offer the update.
530
+ if (typeof onOpen === 'function') onOpen(entry.name)
531
+ else startScan(latest)
532
+ },
533
+ }, t('update', { version: latest }))
534
+ : null))
535
+ }
536
+
537
+ function ScanDialog(props) {
538
+ const { scan, t, onCancel, onConfirm } = props
539
+ if (scan === null || scan === undefined) return null
540
+ const { entry, version, status, result, error } = scan
541
+ const verdict = result?.verdict
542
+ const verdictClass = verdict === 'PASS' ? 'pf-verdict-pass' : verdict === 'WARN' ? 'pf-verdict-warn' : 'pf-verdict-block'
543
+ const verdictText = verdict === 'PASS' ? t('verdictPass') : verdict === 'WARN' ? t('verdictWarn') : t('verdictBlock')
544
+ const confirmLabel = verdict === 'PASS' ? t('confirmInstall') : verdict === 'WARN' ? t('installAnyway') : t('riskInstall')
545
+ const summary = result?.summary ?? { high: 0, medium: 0, low: 0 }
546
+ const hosts = Array.isArray(result?.network?.hosts) ? result.network.hosts : []
547
+ const hits = Array.isArray(result?.hits) ? result.hits : []
548
+ const recommendations = Array.isArray(result?.recommendations) ? result.recommendations : []
549
+ return h('div', {
550
+ className: 'pf-overlay',
551
+ onMouseDown: event => { if (event.target === event.currentTarget) onCancel() },
552
+ },
553
+ h('div', {
554
+ className: 'pf-dialog', role: 'dialog', 'aria-modal': 'true', 'aria-label': t('scanTitle'),
555
+ },
556
+ h('div', { className: 'pf-dialog-head' },
557
+ h('div', null,
558
+ h('h3', { className: 'pf-dialog-title' }, t('scanTitle')),
559
+ h('div', { className: 'pf-dialog-sub' }, entry.name + (version ? '@' + version : ''))),
560
+ h('button', { type: 'button', className: 'pf-close', 'aria-label': t('cancel'), onClick: onCancel }, '×')),
561
+ status === 'scanning'
562
+ ? h('div', { className: 'pf-state', role: 'status' }, t('scanning'))
563
+ : status === 'failed'
564
+ ? h('div', null,
565
+ h('div', { className: 'pf-verdict pf-verdict-block', style: { marginBottom: 6 } }, t('scanFailed')),
566
+ h('div', { className: 'pf-note', style: { marginBottom: 10 } }, t('scanFailedHint')),
567
+ h('div', { className: 'pf-note' }, error ?? ''))
568
+ : h('div', null,
569
+ h('div', { className: 'pf-verdict' },
570
+ h('span', { className: 'pf-verdict-badge ' + verdictClass }, verdictText),
571
+ h('span', { className: 'pf-scan-meta' },
572
+ h('span', null, t('summaryLine', summary)),
573
+ h('span', null, t('filesScanned', { count: result.filesScanned ?? 0 })),
574
+ result.cached === true ? h('span', null, t('scanCached')) : null)),
575
+ h('div', { className: 'pf-scan-meta', style: { marginTop: 8 } },
576
+ h('span', null, hosts.length === 0 ? t('networkNone') : t('networkHosts', { hosts: hosts.join(', ') }))),
577
+ hits.length === 0
578
+ ? h('div', { className: 'pf-notes', style: { marginTop: 8 } }, t('noHits'))
579
+ : h('div', null,
580
+ h('div', { className: 'pf-hits-title' }, t('hitsTitle', { count: hits.length })),
581
+ h('div', { className: 'pf-hits' },
582
+ hits.slice(0, 40).map((hit, index) => h('div', {
583
+ key: index, className: 'pf-hit', 'data-sev': hit.severity,
584
+ },
585
+ h('div', { className: 'pf-hit-head' },
586
+ h('span', { className: 'pf-hit-rule' }, severityLabel(hit.severity, t) + ' · ' + hit.rule),
587
+ h('span', { className: 'pf-hit-file' }, hit.file + ':' + hit.line)),
588
+ h('div', { className: 'pf-hit-evidence' }, hit.evidence ?? ''),
589
+ hit.hint === undefined ? null : h('div', { className: 'pf-hit-hint' }, hit.hint))))),
590
+ (result.notes ?? 0) > 0 ? h('div', { className: 'pf-note', style: { marginTop: 6 } }, t('notesLine', { count: result.notes })) : null,
591
+ recommendations.length === 0 ? null : h('ul', { className: 'pf-recs', style: { marginTop: 8 } },
592
+ recommendations.slice(0, 4).map((text, index) => h('li', { key: index }, text))),
593
+ h('div', { className: 'pf-disclaimer', style: { marginTop: 10 } }, t('scanDisclaimer'))),
594
+ h('div', { className: 'pf-dialog-actions' },
595
+ h('button', { type: 'button', className: 'pf-button', onClick: onCancel }, t('cancel')),
596
+ status === 'scanning'
597
+ ? null
598
+ : status === 'failed'
599
+ ? h('button', {
600
+ type: 'button', className: 'pf-button pf-button-danger',
601
+ onClick: () => onConfirm({ skipScan: true }),
602
+ }, t('skipScan'))
603
+ : h('button', {
604
+ type: 'button', className: 'pf-button ' + (verdict === 'BLOCK' ? 'pf-button-danger' : 'pf-button-primary'),
605
+ onClick: () => onConfirm({ skipScan: false }),
606
+ }, confirmLabel))))
310
607
  }
311
608
 
312
609
  function FinderTab(props) {
313
610
  const t = props.t
314
611
  const install = props.install
612
+ const openPackage = props.openPackage
315
613
  const [catalog, setCatalog] = useState(null)
316
614
  const [status, setStatus] = useState('loading')
317
615
  const [refreshing, setRefreshing] = useState(false)
@@ -319,6 +617,11 @@ window.__ModuleLoader__.load({
319
617
  const [text, setText] = useState('')
320
618
  const [query, setQuery] = useState('')
321
619
  const [limit, setLimit] = useState(PAGE_SIZE)
620
+ const [category, setCategory] = useState('all')
621
+ const [sort, setSort] = useState('hot')
622
+ const [installed, setInstalled] = useState(null)
623
+ const [installedError, setInstalledError] = useState(false)
624
+ const [scan, setScan] = useState(null)
322
625
 
323
626
  async function load(refresh) {
324
627
  if (refresh) {
@@ -339,7 +642,43 @@ window.__ModuleLoader__.load({
339
642
  }
340
643
  }
341
644
 
645
+ async function loadInstalled() {
646
+ try {
647
+ const data = await readInstalled()
648
+ setInstalled(data)
649
+ setInstalledError(false)
650
+ } catch {
651
+ setInstalledError(true)
652
+ }
653
+ }
654
+
655
+ function scanEntry({ entry, version }) {
656
+ setScan({ entry, version, status: 'scanning', result: null, error: null })
657
+ void readScan(entry.name, version)
658
+ .then(result => {
659
+ setScan(current => current === null || current.entry.name !== entry.name
660
+ ? current
661
+ : { entry, version, status: 'ready', result, error: null })
662
+ })
663
+ .catch(error => {
664
+ setScan(current => current === null || current.entry.name !== entry.name
665
+ ? current
666
+ : { ...current, status: 'failed', error: error instanceof Error ? error.message : String(error) })
667
+ })
668
+ }
669
+
670
+ function confirmScan() {
671
+ if (scan === null) return
672
+ const { entry, version } = scan
673
+ setScan(null)
674
+ if (typeof install === 'function') {
675
+ install({ spec: entry.name + '@' + version, title: entry.name, version })
676
+ setTimeout(() => { void loadInstalled() }, 3000)
677
+ }
678
+ }
679
+
342
680
  useEffect(() => { void load(false) }, [])
681
+ useEffect(() => { void loadInstalled() }, [])
343
682
  useEffect(() => {
344
683
  const timer = setTimeout(() => { setQuery(text) }, 150)
345
684
  return () => { clearTimeout(timer) }
@@ -347,8 +686,29 @@ window.__ModuleLoader__.load({
347
686
 
348
687
  const entries = useMemo(() => prepare(catalog?.plugins ?? []), [catalog])
349
688
  const tokens = useMemo(() => tokenize(query), [query])
350
- const results = useMemo(() => searchEntries(entries, tokens), [entries, tokens])
351
- useEffect(() => { setLimit(PAGE_SIZE) }, [query, entries])
689
+ const categories = useMemo(() => {
690
+ const counts = new Map()
691
+ for (const entry of entries) {
692
+ if (entry.category === undefined) continue
693
+ counts.set(entry.category, (counts.get(entry.category) ?? 0) + 1)
694
+ }
695
+ const ranked = [...counts.entries()].sort((left, right) => right[1] - left[1])
696
+ .slice(0, 14)
697
+ .map(([id, count]) => ({ id, count }))
698
+ if (category !== 'all' && !ranked.some(item => item.id === category)) {
699
+ ranked.push({ id: category, count: counts.get(category) ?? 0 })
700
+ }
701
+ return ranked
702
+ }, [entries, category])
703
+ const sortKey = sort === 'hot' ? 'downloads' : sort === 'new' ? 'newest' : 'name'
704
+ const results = useMemo(() => {
705
+ const base = tokens.length === 0
706
+ ? applyFilters(entries, { category, sort: sortKey })
707
+ : searchEntries(entries, tokens)
708
+ if (category === 'all' || tokens.length === 0) return base
709
+ return base.filter(entry => entry.category === category)
710
+ }, [entries, tokens, category, sortKey])
711
+ useEffect(() => { setLimit(PAGE_SIZE) }, [query, entries, category, sort])
352
712
 
353
713
  const shown = results.slice(0, limit)
354
714
  const language = currentLanguage()
@@ -371,8 +731,27 @@ window.__ModuleLoader__.load({
371
731
  type: 'button', className: 'pf-refresh', disabled: refreshing || status === 'loading',
372
732
  onClick: () => { void load(true) },
373
733
  }, refreshing ? t('refreshing') : t('refresh'))),
734
+ h('div', { className: 'pf-filters' },
735
+ h('div', { className: 'pf-chips', role: 'tablist', 'aria-label': t('sort') },
736
+ h('button', {
737
+ type: 'button', className: 'pf-chip', 'data-active': category === 'all' ? 'true' : 'false',
738
+ onClick: () => { setCategory('all') },
739
+ }, t('all')),
740
+ categories.map(item => h('button', {
741
+ key: item.id, type: 'button', className: 'pf-chip',
742
+ 'data-active': category === item.id ? 'true' : 'false',
743
+ onClick: () => { setCategory(category === item.id ? 'all' : item.id) },
744
+ }, categoryLabel(item.id, language) + ' ' + item.count))),
745
+ h('select', {
746
+ className: 'pf-sort', value: sort, 'aria-label': t('sort'),
747
+ onChange: event => { setSort(event.target.value) },
748
+ },
749
+ h('option', { value: 'hot' }, t('sortHot')),
750
+ h('option', { value: 'new' }, t('sortNew')),
751
+ h('option', { value: 'name' }, t('sortName')))),
374
752
  h('div', { className: 'pf-summary' },
375
753
  h('span', null, status === 'ready' ? t('count', { count: results.length }) : ''),
754
+ installedError ? h('span', { className: 'pf-warn' }, t('installedFailed')) : null,
376
755
  refreshError ? h('span', { className: 'pf-warn' }, t('refreshFailed')) : null),
377
756
  status === 'loading'
378
757
  ? h('div', { className: 'pf-state', role: 'status' }, t('loading'))
@@ -384,18 +763,23 @@ window.__ModuleLoader__.load({
384
763
  ? h('div', { className: 'pf-state' }, t('empty'))
385
764
  : h('div', { className: 'pf-list' },
386
765
  shown.map(entry => h(FinderRow, {
387
- key: entry.name, entry, install, language, t,
766
+ key: entry.name, entry, install, onScan: scanEntry, onOpen: openPackage, installed, language, t,
388
767
  }))),
389
768
  results.length > shown.length
390
769
  ? h('button', { type: 'button', className: 'pf-more', onClick: () => { setLimit(limit + PAGE_SIZE) } },
391
770
  `${t('more')} (${results.length - shown.length})`)
392
771
  : null,
393
- h('div', { className: 'pf-note' }, t('note')))
772
+ h('div', { className: 'pf-note' }, t('note')),
773
+ h(ScanDialog, {
774
+ scan, t,
775
+ onCancel: () => { setScan(null) },
776
+ onConfirm: confirmScan,
777
+ }))
394
778
  }
395
779
 
396
780
  return {
397
781
  /** Internal exports used by the package's Node-side checks. */
398
- __test: { prepare, tokenize, searchEntries, FinderTab, FinderRow },
782
+ __test: { prepare, tokenize, searchEntries, applyFilters, FinderTab, FinderRow, ScanDialog },
399
783
  inject: ['slots', 'locale'],
400
784
  apply(ctx) {
401
785
  ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'plugin-finder: dictionaries')