dsh-pick 0.5.2 → 0.6.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.
package/lib/overall.js ADDED
@@ -0,0 +1,192 @@
1
+ // lib/overall.js — 综合榜:把几个插件市场合成一个榜,一个插件只出现一次,按综合分排
2
+ //
3
+ // 收录来源(「收录于」):
4
+ // dshmarket awesome-dsh-plugin 社区目录(dshmarket、dsh-m 的社区区用的都是它)
5
+ // dsh-m dsh-m 的人工精选清单(不算作者自己的那个区)
6
+ // shop dsh-plugin-shop 的目录
7
+ // official DeepSeek 官方的可选 / 按需插件
8
+ // npm 本身不算市场:它只是发布渠道。
9
+ //
10
+ // 综合分 0~100,五项加权;使用、关注两项先换成百分位,免得一个几十万星的仓库压倒一切:
11
+ // 使用 40% 日常基线(去噪);没有去噪数据的,用周下载按全目录的「基线 / 日均下载」比例折算
12
+ // 关注 20% GitHub 星标
13
+ // 维护 20% 最近一次发版或提交:今天满分,半年以上 0 分
14
+ // 共识 10% 被几个市场收录:多个市场都收,说明不止一个人觉得它值得列出来
15
+ // 健康 10% 健康度(去噪指标里的综合分);没有的话看有没有许可证
16
+ // 一票否决(不进榜):仓库已归档、没声明 dsh.bundle(DSH 装不了)、终端版插件。
17
+ //
18
+ // 只在 GitHub 上、没发到 npm 的插件也收:按 gh:owner/repo 合并,没有下载数据,使用项是 0。
19
+
20
+ export const MARKETS = ['dshmarket', 'dsh-m', 'shop', 'official']
21
+ /** 市场 → buildBoards 交出来的名单的 key */
22
+ const MEMBER_KEY = { dshmarket: 'community', 'dsh-m': 'picks', shop: 'shop', official: 'official' }
23
+ export const WEIGHTS = { use: 40, stars: 20, maint: 20, consensus: 10, health: 10 }
24
+ const KEEP = 300 // 落盘的行数(面板显示前面的,AI 工具也用它)
25
+ const DAY = 86400000
26
+
27
+ const repoKey = url => {
28
+ const m = /github\.com\/([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)/.exec(String(url || ''))
29
+ return m ? `gh:${m[1]}/${m[2].replace(/\.git$/, '')}`.toLowerCase() : null
30
+ }
31
+ const median = a => {
32
+ if (!a.length) return null
33
+ const s = a.slice().sort((x, y) => x - y)
34
+ const m = s.length >> 1
35
+ return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2
36
+ }
37
+
38
+ /** 一组数 → 每个数的百分位(0~1)。0 和空值算 0;相同的数百分位相同 */
39
+ export function percentiles(values) {
40
+ const pos = values.map((v, i) => [v, i]).filter(([v]) => v > 0).sort((a, b) => a[0] - b[0])
41
+ const out = new Array(values.length).fill(0)
42
+ let i = 0
43
+ while (i < pos.length) {
44
+ let j = i
45
+ while (j + 1 < pos.length && pos[j + 1][0] === pos[i][0]) j++
46
+ const p = pos.length === 1 ? 1 : ((i + j) / 2) / (pos.length - 1)
47
+ for (let k = i; k <= j; k++) out[pos[k][1]] = p
48
+ i = j + 1
49
+ }
50
+ return out
51
+ }
52
+
53
+ /**
54
+ * 使用、关注两项的 0~1:百分位和「对数值 / 最大对数值」各占一半。
55
+ * 只用百分位,头部会饱和(下载量前 1% 的都接近满分,拉不开);只用比例,一个巨型仓库会把其余压扁。
56
+ * 输入已经是对数值
57
+ */
58
+ export function spread(logs) {
59
+ const p = percentiles(logs)
60
+ const max = Math.max(0, ...logs)
61
+ return logs.map((v, i) => (max > 0 ? (p[i] + Math.max(0, v) / max) / 2 : 0))
62
+ }
63
+
64
+ /** 维护分:最近一次发版或提交距今多少天 → 0~1 */
65
+ export function maintScore(dates, now = Date.now()) {
66
+ const ts = dates.map(d => Date.parse(d || '')).filter(Number.isFinite)
67
+ if (!ts.length) return null
68
+ const days = Math.max(0, (now - Math.max(...ts)) / DAY)
69
+ return Math.max(0, 1 - days / 180)
70
+ }
71
+
72
+ /**
73
+ * @param {object} opt
74
+ * @param {Record<string, object>} opt.packages 目录里的 npm 包(会就地写上 sc 综合分、src 收录于)
75
+ * @param {Record<string, {n: string|null, repo: string|null, name: string, s?: number, added?: string}[]|null>} opt.members
76
+ * 各市场的完整收录名单;某个市场这次抓不到就是 null,这时沿用 previousSrc
77
+ * @param {Record<string, string[]>} [opt.previousSrc] 上次每个 npm 包的「收录于」
78
+ * @returns {{ total: number, excluded: Record<string, number>, weights: object, markets: string[], rows: object[] }}
79
+ */
80
+ export function buildOverall({ packages, members, previousSrc = {}, now = Date.now() }) {
81
+ const cands = new Map() // key → 候选
82
+ const npmKey = n => `npm:${n}`
83
+ for (const rec of Object.values(packages)) {
84
+ cands.set(npmKey(rec.n), { key: npmKey(rec.n), n: rec.n, rec, src: new Set(), stars: rec.gh ? rec.gh.s : null, repo: rec.ghUrl || rec.repo || null })
85
+ }
86
+ // 同一个仓库对应的 npm 包:只在 GitHub 上的条目如果其实发了 npm,并到 npm 那条上
87
+ const npmByRepo = new Map()
88
+ for (const c of cands.values()) {
89
+ const k = repoKey(c.rec.gh ? `https://github.com/${c.rec.gh.repo}` : c.repo)
90
+ if (k && !npmByRepo.has(k)) npmByRepo.set(k, c)
91
+ }
92
+
93
+ // 官方先处理:官方插件不在 npm 目录里,先建好候选,后面的市场(比如商店也收了它)才对得上
94
+ for (const market of ['official', ...MARKETS.filter(m => m !== 'official')]) {
95
+ const list = members[MEMBER_KEY[market]]
96
+ if (!list) {
97
+ // 这次抓不到:npm 包沿用上次的「收录于」
98
+ for (const c of cands.values()) if ((previousSrc[c.n] || []).includes(market)) c.src.add(market)
99
+ continue
100
+ }
101
+ for (const m of list) {
102
+ let c = m.n ? cands.get(npmKey(m.n)) : null
103
+ const rk = repoKey(m.repo)
104
+ if (!c && rk) c = npmByRepo.get(rk) || cands.get(rk)
105
+ if (!c && !m.n && rk) {
106
+ // 只在 GitHub 上的插件
107
+ c = { key: rk, n: null, name: m.name || rk.slice(3), repo: `https://github.com/${rk.slice(3)}`, src: new Set(), stars: null, added: null }
108
+ cands.set(rk, c)
109
+ }
110
+ if (!c && m.n && market === 'official') {
111
+ // 官方插件不在 npm 目录里(不带 dsh-plugin 关键字):用官方榜带来的数据建一条
112
+ const rec = { n: m.n, v: m.v || '', d: m.d || '', w: Number.isFinite(m.w) ? m.w : 0, t: m.t || null, official: true }
113
+ c = { key: npmKey(m.n), n: m.n, rec, src: new Set(), stars: null, repo: null, outside: true }
114
+ cands.set(c.key, c)
115
+ }
116
+ if (!c) continue // npm 名字不在目录里(多半是 npm 上已经没有了)
117
+ c.src.add(market)
118
+ if (c.stars == null && Number.isFinite(m.s)) c.stars = m.s
119
+ if (!c.n && m.added && (!c.added || m.added < c.added)) c.added = m.added
120
+ }
121
+ }
122
+
123
+ // 一票否决
124
+ const excluded = {}
125
+ const out = []
126
+ for (const c of cands.values()) {
127
+ const rec = c.rec
128
+ const reason = rec && rec.gh && rec.gh.a ? '仓库已归档'
129
+ : rec && rec.inst && rec.inst.b === false ? '没声明 dsh.bundle'
130
+ : rec && rec.inst && rec.inst.p && rec.inst.p !== 'web' ? '终端版插件'
131
+ : null
132
+ if (reason) { excluded[reason] = (excluded[reason] || 0) + 1; continue }
133
+ out.push(c)
134
+ }
135
+
136
+ // 没有去噪数据的包:周下载按「日常基线 / 日均周下载」的中位比例折算成基线
137
+ const ratios = Object.values(packages).filter(r => r.deep && r.w > 0 && r.deep.base > 0).map(r => r.deep.base / (r.w / 7))
138
+ const ratio = median(ratios) ?? 0.5
139
+ const useOf = c => (c.rec ? (c.rec.deep ? c.rec.deep.base : (c.rec.w || 0) / 7 * ratio) : 0)
140
+ const useP = spread(out.map(c => Math.log1p(useOf(c))))
141
+ const starP = spread(out.map(c => Math.log1p(c.stars || 0)))
142
+
143
+ out.forEach((c, i) => {
144
+ const rec = c.rec
145
+ const d = rec && rec.deep
146
+ const m = maintScore([d && d.lastRelease, rec && rec.t, rec && rec.gh && rec.gh.p], now)
147
+ const parts = {
148
+ use: useP[i],
149
+ stars: starP[i],
150
+ maint: m ?? 0.4, // 不知道就给个中间偏下的分
151
+ consensus: c.src.size / MARKETS.length,
152
+ health: d && Number.isFinite(d.s) ? d.s / 100 : rec && rec.gh && rec.gh.l ? 0.6 : 0.4,
153
+ }
154
+ c.parts = parts
155
+ c.score = Math.round(Object.entries(WEIGHTS).reduce((sum, [k, w]) => sum + parts[k] * w, 0))
156
+ if (rec) {
157
+ rec.sc = c.score
158
+ rec.src = [...c.src]
159
+ }
160
+ })
161
+ out.sort((a, b) => b.score - a.score || (b.rec ? b.rec.w || 0 : 0) - (a.rec ? a.rec.w || 0 : 0))
162
+
163
+ const pct = v => Math.round(v * 100)
164
+ return {
165
+ total: out.length,
166
+ excluded,
167
+ weights: WEIGHTS,
168
+ markets: MARKETS,
169
+ useRatio: Math.round(ratio * 1000) / 1000,
170
+ rows: out.slice(0, KEEP).map(c => {
171
+ const rec = c.rec
172
+ const row = {
173
+ k: c.n || c.key, // npm 包名,或 gh:owner/repo
174
+ n: c.n,
175
+ sc: c.score,
176
+ p: [pct(c.parts.use), pct(c.parts.stars), pct(c.parts.maint), pct(c.parts.consensus), pct(c.parts.health)],
177
+ src: [...c.src],
178
+ }
179
+ if (!c.n) {
180
+ row.name = c.name
181
+ row.repo = c.repo
182
+ if (c.added) row.added = c.added
183
+ }
184
+ // 不在 npm 目录里的(官方插件):面板查不到它的记录,名字、版本、下载量跟着行走
185
+ if (c.outside) Object.assign(row, { name: rec.n, v: rec.v, d: rec.d, w: rec.w })
186
+ if (c.stars != null) row.s = c.stars
187
+ if (rec && rec.deep && rec.deep.lastRelease) row.last = rec.deep.lastRelease
188
+ else if (rec && rec.t) row.last = String(rec.t).slice(0, 10)
189
+ return row
190
+ }),
191
+ }
192
+ }
package/lib/remote.js CHANGED
@@ -70,6 +70,20 @@ export function validCatalog(cat) {
70
70
  return list.length >= 500 && list.slice(0, 50).every(r => r && typeof r.n === 'string' && typeof r.w === 'number')
71
71
  }
72
72
 
73
+ /**
74
+ * 防缩水:和线上上一份比,包数或带安装信息的包少了 10% 以上就不发布,继续用旧的。
75
+ * 构建时被 npm 限流、上游目录抓不到,都可能让一份「看着正常」的目录少掉一大截——宁可晚一天更新。
76
+ * 真要缩小(比如上游清理了一批包)时,设环境变量 ALLOW_SHRINK=1 再跑一次
77
+ */
78
+ export function shrinkProblem(prev, next, ratio = 0.9) {
79
+ if (!prev) return null
80
+ const checks = [['包数', prev.total, next.total], ['带安装信息的包', prev.withInstallFacts, next.withInstallFacts]]
81
+ for (const [label, before, after] of checks) {
82
+ if (Number.isFinite(before) && before > 0 && after < before * ratio) return `${label}从 ${before} 降到 ${after}(少了 ${Math.round((1 - after / before) * 100)}%)`
83
+ }
84
+ return null
85
+ }
86
+
73
87
  /**
74
88
  * 检查并下载更新的目录。
75
89
  * @param {object} [opt]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-pick",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "description": "帮你在 DSH 生态里选对插件:说需求 → 找候选 → 多维比较 → 出结论。下载量是证据,AI 是推理。",
5
5
  "repository": {
6
6
  "type": "git",
@@ -58,6 +58,10 @@
58
58
  ],
59
59
  "license": "MIT",
60
60
  "engines": {
61
- "node": ">=20"
61
+ "node": ">=20",
62
+ "dsh": ">=0.2.0-0"
63
+ },
64
+ "devDependencies": {
65
+ "@deepseek-ai/dsh-plugin-market-index": "0.2.1-alpha.4"
62
66
  }
63
67
  }
package/plugin/client.js CHANGED
@@ -274,10 +274,13 @@ window.__ModuleLoader__.load({
274
274
  function SettingsSection() {
275
275
  const [meta, setMeta] = useState(null)
276
276
  const [openMsg, setOpenMsg] = useState('')
277
+ const [market, setMarket] = useState(null) // { available, added, url }
278
+ const [marketMsg, setMarketMsg] = useState('')
277
279
 
278
280
  useEffect(() => {
279
281
  let alive = true
280
282
  api('meta').then(j => { if (alive) setMeta(j) }).catch(() => {})
283
+ api('market').then(j => { if (alive) setMarket(j) }).catch(() => {})
281
284
  return () => { alive = false }
282
285
  }, [])
283
286
 
@@ -313,6 +316,29 @@ window.__ModuleLoader__.load({
313
316
  : null,
314
317
  ),
315
318
 
319
+ h(Section, { title: L('插件索引源(DSH「插件 → 发现」)', 'Plugin index (DSH Plugins → Discover)') },
320
+ h('div', null, L(
321
+ 'dsh-pick 每天生成一份 DSH 官方格式的插件索引。加进「发现」后,可以在 DSH 的插件页里直接浏览、安装其中的插件。只收声明了 engines.dsh 的插件(官方要求)。',
322
+ 'dsh-pick publishes a daily plugin index in the official DSH format. Add it to Discover to browse and install its plugins on the DSH Plugins page. Only plugins that declare engines.dsh are listed (an official requirement).')),
323
+ !market ? null
324
+ : market.added
325
+ ? h('div', { style: { marginTop: 8, color: C.text } }, L('✓ 已在「发现」的索引源里', '✓ Already in Discover'))
326
+ : h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, marginTop: 8, flexWrap: 'wrap' } },
327
+ h(Btn, {
328
+ onClick: async () => {
329
+ setMarketMsg('')
330
+ try {
331
+ const j = await api('market', 'POST')
332
+ if (j.ok) setMarket({ ...market, available: true, added: true })
333
+ else setMarketMsg(j.message || L('没加上', 'Not added'))
334
+ } catch (e) { setMarketMsg(e.message) }
335
+ },
336
+ }, L('添加到「发现」', 'Add to Discover')),
337
+ !market.available ? h('span', { style: { fontSize: 12, color: C.faint } }, L('需要先在 DSH「插件」页打开实验功能「自定义插件索引」', 'Turn on the experimental "Custom plugin indexes" on the DSH Plugins page first')) : null,
338
+ marketMsg ? h('span', { style: { fontSize: 12, color: C.danger } }, marketMsg) : null),
339
+ market ? h(CommandLine, { command: market.url }) : null,
340
+ ),
341
+
316
342
  h(Section, { title: L('数据口径', 'About the data') },
317
343
  h('div', null, catalog),
318
344
  meta && meta.total ? h('div', { style: { marginTop: 4 } }, meta.source === 'remote'
package/plugin/index.js CHANGED
@@ -15,6 +15,10 @@
15
15
  // POST /api-dsh-pick/uninstall 从 DSH 卸载本插件
16
16
  // GET /api-dsh-pick/installed DSH 里已装的插件名(面板的「已安装」标记)
17
17
  // GET /api-dsh-pick/live?names=a,b 实时查 npm(「我的监控」的刷新,最多 30 个)
18
+ // GET /api-dsh-pick/market dsh-pick 的插件索引在不在 DSH「插件 → 发现」的索引源里
19
+ // POST /api-dsh-pick/market 把它加进去(设置页的按钮)
20
+ //
21
+ // 启动时还会自动把插件索引加进「发现」一次(lib/market-source.js),用户删掉后不再自动加。
18
22
  // POST /api-dsh-pick/install 安装目录里的某个插件 { name }
19
23
  //
20
24
  // 另外注册 4 个 AI 工具(plugin/tools.js):对话里的 AI 能自己查目录、比较插件。
@@ -27,6 +31,7 @@ import { join } from 'node:path'
27
31
  import { registerTools } from './tools.js'
28
32
  import { loadCatalog, liveStats, parseWatchNames } from '../lib/engine.js'
29
33
  import { refreshCatalog, remoteState, CHECK_EVERY_MS } from '../lib/remote.js'
34
+ import { ensureMarketSource, marketStatus } from '../lib/market-source.js'
30
35
 
31
36
  /** 本包根目录:插件就是完整的 dsh-pick 包 */
32
37
  const PKG_ROOT = fileURLToPath(new URL('..', import.meta.url))
@@ -254,6 +259,15 @@ export function apply(ctx) {
254
259
  profile = ctx.get && ctx.get('profileContext') && ctx.get('profileContext').name
255
260
  } catch { profile = undefined }
256
261
 
262
+ // DSH「插件 → 发现」的索引源(实验功能「自定义插件索引」打开时才有这个服务):自动加一次 dsh-pick 的插件索引
263
+ let pluginMarket
264
+ ctx.inject(['pluginMarket'], (mCtx) => {
265
+ pluginMarket = mCtx.pluginMarket || (mCtx.get && mCtx.get('pluginMarket'))
266
+ ensureMarketSource(pluginMarket)
267
+ .then(r => { if (r.status === 'added') console.info('[dsh-pick] 已把插件索引加进「插件 → 发现」') })
268
+ .catch(() => {})
269
+ })
270
+
257
271
  // 每日更新的目录:启动时查一次,之后每 6 小时查一次(查不到就继续用手上的)
258
272
  const refresh = () => refreshCatalog().catch(() => {})
259
273
  const startTimer = setTimeout(refresh, 5000) // 别和 DSH 启动抢网络
@@ -406,6 +420,22 @@ export function apply(ctx) {
406
420
  },
407
421
  }))
408
422
 
423
+ // 「发现」的索引源:查状态 / 用户点按钮加进去
424
+ track(ws.register({
425
+ kind: 'exact',
426
+ path: '/api-dsh-pick/market',
427
+ handler: async (req, res) => {
428
+ if (req.method === 'GET') return sendJson(res, 200, await marketStatus(pluginMarket))
429
+ if (!isSafePost(req)) return sendJson(res, 403, { ok: false, message: '只接受本页面发出的请求' })
430
+ const r = await ensureMarketSource(pluginMarket, { force: true })
431
+ if (r.status === 'added' || r.status === 'present') return sendJson(res, 200, { ok: true, status: r.status })
432
+ if (r.status === 'unavailable') {
433
+ return sendJson(res, 200, { ok: false, message: '先在 DSH 的「插件」页打开实验功能「自定义插件索引」,「发现」页出来后再点' })
434
+ }
435
+ return sendJson(res, 200, { ok: false, message: `没加上:${r.message || r.status}` })
436
+ },
437
+ }))
438
+
409
439
  // 已装的插件(面板卡片上的「已安装」)
410
440
  track(ws.register({
411
441
  kind: 'exact',
@@ -428,7 +458,10 @@ export function apply(ctx) {
428
458
  if (!isSafePost(req)) return sendJson(res, 403, { ok: false, message: '只接受本页面发出的请求' })
429
459
  const { name } = await readJsonBody(req)
430
460
  if (typeof name !== 'string' || !NAME_RE.test(name)) return sendJson(res, 400, { ok: false, message: '包名不对' })
431
- const rec = (await loadCatalog()).packages[name]
461
+ const cat = await loadCatalog()
462
+ // 目录里的 npm 包,或官方榜里的 DeepSeek 官方插件(官方包不带 dsh-plugin 关键字,不在目录里)
463
+ const official = ((cat.boards && cat.boards.official && cat.boards.official.rows) || []).some(r => r.n === name)
464
+ const rec = cat.packages[name] || (official ? { n: name } : null)
432
465
  if (!rec) return sendJson(res, 400, { ok: false, message: `${name} 不在 DSH 插件目录里,这里不装` })
433
466
  // 没声明 dsh.bundle 的包,DSH 一定拒绝安装:不白跑一趟 pnpm
434
467
  if (rec.inst && rec.inst.b === false) {
package/plugin/tools.js CHANGED
@@ -246,7 +246,7 @@ export async function buildToolDefinitions(deps = {}) {
246
246
  metric: { type: 'string', enum: ['weekly', 'baseline', 'growth', 'score', 'stars', 'pushed', 'downloads', 'newest'], description: '排序指标,默认 baseline(日常基线,最接近真实使用量);stars = GitHub 星标,pushed = GitHub 最近提交' },
247
247
  category: { type: 'string', enum: CATS, description: '只看某一类(可省略)' },
248
248
  limit: { type: 'integer', description: '前几名,默认 10,最多 30' },
249
- board: { type: 'string', enum: ['official', 'community', 'shop'], description: '看别的榜单(可省略,省略就是 npm / GitHub):official = DeepSeek 官方插件;community = awesome-dsh-plugin 社区目录;shop = dsh-plugin-shop 插件商店(第三方)。这时 metric 可填 stars / downloads / newest' },
249
+ board: { type: 'string', enum: ['overall', 'official', 'community', 'shop'], description: '看别的榜单(可省略,省略就是 npm / GitHub):overall = 综合榜(几个插件市场合并去重,按综合分排,用户问「最值得装的」先用它);official = DeepSeek 官方插件;community = awesome-dsh-plugin 社区目录(dshmarket 用的就是它);shop = dsh-plugin-shop 插件商店(第三方)。community / shop 时 metric 可填 stars / downloads / newest' },
250
250
  },
251
251
  output: {
252
252
  schema: ANY_JSON,
@@ -257,6 +257,31 @@ export async function buildToolDefinitions(deps = {}) {
257
257
  },
258
258
  async execute(args) {
259
259
  const cat = await loadCatalog()
260
+ if (args.board === 'overall') {
261
+ const limit = clampInt(args.limit, 1, 30, 10)
262
+ const o = cat.boards && cat.boards.overall
263
+ if (!o) return plain({ header: header(cat), board: '综合榜:还没有数据', rows: [] })
264
+ const W = o.weights
265
+ const LABEL = { dshmarket: 'dshmarket', 'dsh-m': 'dsh-m 精选', shop: 'dsh-plugin-shop', official: 'DeepSeek 官方' }
266
+ const category = CATS.includes(args.category) ? args.category : null
267
+ const have = await installed()
268
+ const rows = o.rows.filter(r => !category || (r.n && cat.packages[r.n] && cat.packages[r.n].cat === category)).slice(0, limit)
269
+ return plain({
270
+ header: header(cat),
271
+ board: `综合榜(${num(o.total)} 个插件参与排名;综合分 = 使用 ${W.use}% + 关注 ${W.stars}% + 维护 ${W.maint}% + 共识 ${W.consensus}% + 健康 ${W.health}%,各项 0~100)`,
272
+ rows: rows.map((r, i) => {
273
+ const rec = r.n ? cat.packages[r.n] : null
274
+ const name = r.n || r.name
275
+ return `${i + 1}. ${name} · 综合分 ${r.sc}(使用 ${r.p[0]} · 关注 ${r.p[1]} · 维护 ${r.p[2]} · 共识 ${r.p[3]} · 健康 ${r.p[4]})` +
276
+ ` · 收录于 ${r.src.map(k => LABEL[k] || k).join('、') || '(只在 npm)'}` +
277
+ (rec ? ` · 周下载 ${num(rec.w)}` : r.w != null ? ` · 周下载 ${num(r.w)}` : '') +
278
+ (r.s != null ? ` · ★${num(r.s)}` : '') +
279
+ (r.n && have.has(r.n) ? ' · (已安装)' : '') +
280
+ (r.n ? '' : ` · 只在 GitHub(${r.repo}),还不能在面板里直接装`) +
281
+ ((rec && rec.d) || r.d ? `\n ${String((rec && rec.d) || r.d).slice(0, 140)}` : '')
282
+ }),
283
+ })
284
+ }
260
285
  if (args.board) {
261
286
  const limit = clampInt(args.limit, 1, 30, 10)
262
287
  const board = cat.boards && cat.boards[args.board]
package/web/panel.html CHANGED
@@ -114,6 +114,12 @@ h1{margin:0;font-size:19px;font-weight:650;letter-spacing:-.2px}
114
114
  .board button.on{background:var(--panel);color:var(--text);box-shadow:0 1px 2px var(--shadow)}
115
115
  table.rank td.nm .sub{font-size:10.5px;color:var(--t3);font-weight:400;margin-top:2px}
116
116
  table.rank td.nm .desc{min-width:150px;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
117
+ /* 综合榜:收录于哪几个市场 */
118
+ .srcchip{display:inline-block;font-size:10px;font-weight:500;color:var(--t2);background:var(--soft);border-radius:4px;padding:0 5px;margin:2px 3px 0 0;white-space:nowrap}
119
+ .srcchip.off{color:var(--accent);background:var(--accent-bg)}
120
+ .srcchip.gh{color:var(--t3)}
121
+ table.rank td .sc{font-size:13px;font-weight:700;color:var(--text);cursor:help}
122
+ table.rank td.lks .inst,table.rank td.lks .badge-in,table.rank td.lks .badge-no{margin-right:4px;vertical-align:top}
117
123
  table.rank td .arch{font-size:10.5px;color:var(--t3);background:var(--soft);border-radius:5px;padding:1px 6px}
118
124
  .section h2 .h2-acts{margin-left:auto;display:inline-flex;gap:8px;align-items:center}
119
125
  .section h2 .h2-acts .ai{margin-left:0}
@@ -378,7 +384,8 @@ td.down{color:var(--bad);font-weight:600}
378
384
  <div class="section">
379
385
  <h2>排行榜</h2>
380
386
  <div class="board" id="rankBoard">
381
- <button data-b="npm" class="on">npm 榜</button>
387
+ <button data-b="overall" class="on">综合榜</button>
388
+ <button data-b="npm">npm 榜</button>
382
389
  <button data-b="gh">GitHub 榜</button>
383
390
  <button data-b="official">官方榜</button>
384
391
  <button data-b="community">社区榜</button>
@@ -386,10 +393,10 @@ td.down{color:var(--bad);font-weight:600}
386
393
  </div>
387
394
  <p class="cap" id="rankCap"></p>
388
395
  <div class="filters" id="rankFilters">
389
- <button class="chip on" data-board="npm" data-m="base">日常基线</button>
390
- <button class="chip" data-board="npm" data-m="w">周下载</button>
391
- <button class="chip" data-board="npm" data-m="growth">增速最快</button>
392
- <button class="chip" data-board="npm" data-m="s">健康度</button>
396
+ <button class="chip on hidden" data-board="npm" data-m="base">日常基线</button>
397
+ <button class="chip hidden" data-board="npm" data-m="w">周下载</button>
398
+ <button class="chip hidden" data-board="npm" data-m="growth">增速最快</button>
399
+ <button class="chip hidden" data-board="npm" data-m="s">健康度</button>
393
400
  <button class="chip on hidden" data-board="gh" data-m="gs">星标</button>
394
401
  <button class="chip hidden" data-board="gh" data-m="gp">最近提交</button>
395
402
  <button class="chip hidden" data-board="gh" data-m="gf">Fork</button>
package/web/panel.js CHANGED
@@ -237,6 +237,7 @@ async function onInstallClick(btn) {
237
237
  INSTALLED.add(name)
238
238
  toast(j.restart ? `${name} 已安装,重启 DSH 后生效` : `${name} 已安装`)
239
239
  renderCands($('#need').value.trim())
240
+ renderRank()
240
241
  return
241
242
  }
242
243
  toast(j.message || '安装失败', j.command)
@@ -397,6 +398,9 @@ function bindEvents() {
397
398
  document.addEventListener('click', e => {
398
399
  const b = e.target.closest('[data-watch]')
399
400
  if (b) toggleWatch(b.dataset.watch)
401
+ // 排行榜里的「安装」(搜索结果卡片上的由卡片自己处理)
402
+ const ib = e.target.closest('#rankBody [data-install]')
403
+ if (ib) onInstallClick(ib)
400
404
  })
401
405
 
402
406
  $('#btnExport').addEventListener('click', exportHtml)
@@ -433,7 +437,8 @@ function renderCands(need, { keepCompat = false } = {}) {
433
437
  `<span class="rel">${esc(rec.cat)}</span>` +
434
438
  (d ? '<span class="ok" title="有去噪指标,可参与健康度比较">✓ 可比较</span>' : '<span class="nook" title="未进入去噪范围(周下载 Top 之外),缺基线/环比/节奏">仅基础</span>') +
435
439
  `</div>` +
436
- `<div class="rk">${rankText(rec)}</div>` +
440
+ `<div class="rk">${rankText(rec)}${rec.sc != null ? ` · 综合分 <b>${rec.sc}</b>` : ''}</div>` +
441
+ (rec.src && rec.src.length ? `<div>${srcChips(rec.src)}</div>` : '') +
437
442
  `<div class="d">${esc(rec.d)}</div>` +
438
443
  `<div class="kv">` +
439
444
  `<span>周 <b>${num(rec.w)}</b></span>` +
@@ -658,8 +663,64 @@ function renderOuterBoard(board) {
658
663
  `<td class="r">${strong(metric === 'added', r.added ? esc(r.added.slice(5)) : '—')}</td>${actions(r)}</tr>`).join('')
659
664
  }
660
665
 
666
+ /** 「收录于」的市场名 */
667
+ const MARKET_LABEL = { dshmarket: 'dshmarket', 'dsh-m': 'dsh-m 精选', shop: '商店', official: '官方' }
668
+ function srcChips(src) {
669
+ return (src || []).map(k => `<span class="srcchip${k === 'official' ? ' off' : ''}" title="收录于 ${esc(MARKET_LABEL[k] || k)}">${esc(MARKET_LABEL[k] || k)}</span>`).join('')
670
+ }
671
+
672
+ /**
673
+ * 综合榜:几个插件市场合成一个榜(每日构建时算好,见 lib/overall.js),一个插件一行。
674
+ * npm 上的插件能直接装;只在 GitHub 上的先只展示
675
+ */
676
+ function renderOverall() {
677
+ const data = CAT.boards && CAT.boards.overall
678
+ const W = (data && data.weights) || { use: 40, stars: 20, maint: 20, consensus: 10, health: 10 }
679
+ $('#rankCap').textContent = `把 dshmarket、dsh-m 精选、dsh-plugin-shop 商店、DeepSeek 官方几个市场合成一个榜,一个插件只出现一次。` +
680
+ `综合分 = 使用 ${W.use}% + 关注 ${W.stars}% + 维护 ${W.maint}% + 共识 ${W.consensus}% + 健康 ${W.health}%(鼠标停在分数上看明细);` +
681
+ `仓库已归档、DSH 装不了的不进榜。${data ? `共 ${num(data.total)} 个插件参与排名。` : ''}`
682
+ if (!data || !data.rows.length) {
683
+ $('#rankHead').innerHTML = ''
684
+ $('#rankBody').innerHTML = '<tr><td class="empty">还没有综合榜的数据(每日更新取到后就有)。</td></tr>'
685
+ return
686
+ }
687
+ const cat = $('#rankCat').value
688
+ const rows = data.rows
689
+ .map(r => ({ r, rec: r.n ? CAT.packages[r.n] : null }))
690
+ .filter(({ rec }) => !cat || (rec && rec.cat === cat))
691
+ .slice(0, 60)
692
+ $('#rankHead').innerHTML = '<tr><th style="width:36px">#</th><th>插件</th>' +
693
+ '<th class="r" title="综合分 0~100">综合</th><th class="r">周下载</th><th class="r">★</th><th class="r" title="最近一次发版或提交">最近</th><th></th></tr>'
694
+ $('#rankBody').innerHTML = rows.map(({ r, rec }, i) => {
695
+ const name = r.n || r.name
696
+ const v = rec ? rec.v : r.v
697
+ const w = rec ? rec.w : r.w
698
+ const desc = rec ? rec.d : r.d
699
+ const [pu, ps, pm, pc, ph] = r.p
700
+ const why = `使用 ${pu} · 关注 ${ps} · 维护 ${pm} · 共识 ${pc} · 健康 ${ph}(各项 0~100)`
701
+ const age = daysSince(r.last)
702
+ // 能装的:目录里的 npm 包按装前检查给按钮;官方插件不在目录里,名字核对过,也能装
703
+ const inst = r.n ? installArea(rec || { n: r.n }) : ''
704
+ const links = linkBtns(rec || { n: r.n || '', ghUrl: r.repo || '' }, { icon: true })
705
+ return `<tr><td style="color:var(--t3)">${i + 1}</td>` +
706
+ `<td class="nm">${esc(name)}${v ? ` <span style="color:var(--t3);font-weight:400;font-size:11px">v${esc(v)}</span>` : ''}` +
707
+ `<div>${srcChips(r.src)}${r.n ? '' : '<span class="srcchip gh">只在 GitHub</span>'}</div>` +
708
+ (desc ? `<div class="sub desc" title="${esc(desc)}">${esc(desc)}</div>` : '') + `</td>` +
709
+ `<td class="r"><span class="sc" title="${why}">${r.sc}</span></td>` +
710
+ `<td class="r">${w != null ? short(w) : '—'}</td>` +
711
+ `<td class="r">${r.s != null ? short(r.s) : '—'}</td>` +
712
+ `<td class="r" title="${esc(r.last || '')}"><span${age != null && age > 90 ? ' class="stale"' : ''}>${age != null ? ageText(age) : '—'}</span></td>` +
713
+ `<td class="lks">${watchBtn(r.k)}${inst}${links}</td></tr>`
714
+ }).join('')
715
+ }
716
+
661
717
  function renderRank() {
662
718
  const board = rankBoard()
719
+ if (board === 'overall') {
720
+ $('#rankCat').classList.remove('hidden')
721
+ renderOverall()
722
+ return
723
+ }
663
724
  const onChip = document.querySelector(`#rankFilters .chip.on[data-board="${board}"]`)
664
725
  const metric = onChip ? onChip.dataset.m : ''
665
726
  const cat = $('#rankCat').value