dsh-pick 0.5.3 → 0.6.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/lib/boards.js CHANGED
@@ -11,6 +11,10 @@
11
11
  const OFFICIAL_JS = 'https://cdn.jsdelivr.net/npm/@deepseek-ai/dsh-official-bundles@latest/lib/index.js'
12
12
  const COMMUNITY_URL = 'https://awesome-dsh-plugin.com/plugins.json'
13
13
  const SHOP_BASE = 'https://LivXue.github.io/dsh-plugin-shop/v1/'
14
+ // dsh-m 的精选清单(人工挑的,分「装机必备」等几个区);jsDelivr 比 raw.githubusercontent.com 稳
15
+ const PICKS_URL = 'https://cdn.jsdelivr.net/gh/iasiv5/dsh-m@main/registry.json'
16
+ // 精选清单里这个区是 dsh-m 作者自己的插件,不算「推荐」
17
+ const SELF_PROMO = new Set(['self-dev'])
14
18
  const REGISTRY = 'https://registry.npmjs.org/'
15
19
  const DOWNLOADS = 'https://api.npmjs.org/downloads/point/last-week/'
16
20
  const TOP = 100
@@ -77,7 +81,7 @@ export function communityBoard(doc) {
77
81
  added: date(p && p.added),
78
82
  d: zh(p && p.description),
79
83
  })).filter(r => r.name && (r.n || r.repo))
80
- return { total: rows.length, updated: date(doc && doc.updated), rows: topRows(rows, ['s', 'dl', 'added']) }
84
+ return { total: rows.length, updated: date(doc && doc.updated), rows: topRows(rows, ['s', 'dl', 'added']), all: rows }
81
85
  }
82
86
 
83
87
  /**
@@ -113,7 +117,7 @@ export function shopBoard(plugins, stars) {
113
117
  d: zh(p && p.catalog && p.catalog.summary),
114
118
  }
115
119
  }).filter(r => r.name && (r.n || r.repo))
116
- return { total: rows.length, rows: topRows(rows, ['s', 'added']) }
120
+ return { total: rows.length, rows: topRows(rows, ['s', 'added']), all: rows }
117
121
  }
118
122
 
119
123
  async function getJson(fetchImpl, url, ms) {
@@ -134,19 +138,42 @@ async function loadOfficial(fetchImpl) {
134
138
  getJson(fetchImpl, `${DOWNLOADS}${enc}`, 15000).catch(() => null),
135
139
  ])
136
140
  row.v = meta ? text(meta.version, 40) : ''
141
+ // 最近一次发布的时间:精简版 packument 的 modified(综合榜的维护分要用)
142
+ const brief = await fetchImpl(`${REGISTRY}${enc}`, { headers: { accept: 'application/vnd.npm.install-v1+json' }, signal: AbortSignal.timeout(15000) })
143
+ .then(r => (r.ok ? r.json() : null)).catch(() => null)
144
+ row.t = brief && date(brief.modified) ? brief.modified : null
137
145
  if (!row.d && meta) row.d = text(meta.description)
138
146
  row.w = dl ? count(dl.downloads) : null
139
147
  }))
140
148
  return { total: rows.length, rows }
141
149
  }
142
150
 
143
- async function loadShop(fetchImpl) {
151
+ async function loadShop(fetchImpl, members) {
144
152
  const index = await getJson(fetchImpl, `${SHOP_BASE}index.json`, 30000)
145
153
  const [plugins, stars] = await Promise.all([
146
154
  getJson(fetchImpl, SHOP_BASE + index.plugins.url, 180000),
147
155
  getJson(fetchImpl, SHOP_BASE + index.stars.url, 60000),
148
156
  ])
149
- return shopBoard(plugins, stars)
157
+ const board = shopBoard(plugins, stars)
158
+ members.shop = board.all
159
+ delete board.all
160
+ return board
161
+ }
162
+
163
+ /**
164
+ * dsh-m 精选清单 → 收录名单(不算作者自己那个区)
165
+ * @returns {{n: string|null, repo: string|null, name: string}[]}
166
+ */
167
+ export function picksMembers(doc) {
168
+ const list = doc && Array.isArray(doc.plugins) ? doc.plugins : []
169
+ return list
170
+ .filter(p => p && !(SELF_PROMO.has(p.category) && !(p.alsoCategories || []).some(c => !SELF_PROMO.has(c))))
171
+ .map(p => ({
172
+ n: npmName(p.npm),
173
+ repo: typeof p.github === 'string' && /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(p.github) ? `https://github.com/${p.github}` : null,
174
+ name: text(p.name || p.id, 80),
175
+ }))
176
+ .filter(r => r.n || r.repo)
150
177
  }
151
178
 
152
179
  /**
@@ -155,11 +182,32 @@ async function loadShop(fetchImpl) {
155
182
  * @param {object} [opt.previous] 上一次的 boards
156
183
  * @param {object} [opt.communityDoc] 已经下载好的社区目录,有就不再下一次
157
184
  */
158
- export async function buildBoards({ fetchImpl = globalThis.fetch, previous = {}, communityDoc = null, onProgress = () => {} } = {}) {
185
+ export async function buildBoards({ fetchImpl = globalThis.fetch, previous = {}, communityDoc = null, members = {}, onProgress = () => {} } = {}) {
186
+ // members:各市场的完整收录名单(综合榜算「收录于」要用),不落盘;抓不到的那个市场留 null
187
+ members.community = null
188
+ members.shop = null
189
+ members.official = null
190
+ members.picks = null
159
191
  const sources = {
160
- official: () => loadOfficial(fetchImpl),
161
- community: async () => communityBoard(communityDoc || await loadCommunity(fetchImpl)),
162
- shop: () => loadShop(fetchImpl),
192
+ official: async () => {
193
+ const board = await loadOfficial(fetchImpl)
194
+ // 官方包大多不带 dsh-plugin 关键字,不在 npm 目录里:把周下载、版本、说明带上,综合榜直接用
195
+ members.official = board.rows.map(r => ({ n: r.n, repo: null, name: r.n, w: r.w, v: r.v, d: r.d, t: r.t }))
196
+ return board
197
+ },
198
+ community: async () => {
199
+ const board = communityBoard(communityDoc || await loadCommunity(fetchImpl))
200
+ members.community = board.all
201
+ delete board.all
202
+ return board
203
+ },
204
+ shop: () => loadShop(fetchImpl, members),
205
+ }
206
+ try {
207
+ members.picks = picksMembers(await getJson(fetchImpl, PICKS_URL, 30000))
208
+ onProgress(` dsh-m 精选:${members.picks.length} 个(不含作者自己的)`)
209
+ } catch (e) {
210
+ onProgress(` dsh-m 精选抓不到(${e.message})`)
163
211
  }
164
212
  const boards = {}
165
213
  for (const [key, load] of Object.entries(sources)) {
package/lib/engine.js CHANGED
@@ -14,6 +14,7 @@ import { expandWords } from './words.js'
14
14
  import { baselineWithStart, growth, cadence, ageDays, score, sum } from './metrics.js'
15
15
  import { parseRepo, fetchRepos, fetchRepoLive, countsForPlugin } from './github.js'
16
16
  import { buildBoards, communityPackages, loadCommunity, repoUrl } from './boards.js'
17
+ import { buildOverall } from './overall.js'
17
18
 
18
19
  const PKG_ROOT = fileURLToPath(new URL('..', import.meta.url))
19
20
  /** 随包自带的目录(发版时的快照;dsh-pick build 也写这里) */
@@ -36,6 +37,43 @@ const REG_API = 'https://registry.npmjs.org'
36
37
 
37
38
  /* ---------------------------------------------------------------- 网络 */
38
39
 
40
+ /**
41
+ * 和 jget 一样,但分得清「没有这个包」(404/410)和「这次没拿到」(限流、5xx、网络)。
42
+ * 在 GitHub Actions 上读几千个 manifest 会被 npm 限流,把两者混为一谈就会把一大批好好的包当成不存在丢掉
43
+ * @returns {Promise<{status: 'ok', data: any} | {status: 'gone'} | {status: 'failed'}>}
44
+ */
45
+ async function jgetStatus(url, { tries = 4, wait = 800 } = {}) {
46
+ for (let i = 0; i < tries; i++) {
47
+ try {
48
+ const r = await fetch(url, { headers: { accept: 'application/json' } })
49
+ if (r.status === 404 || r.status === 410) return { status: 'gone' }
50
+ if (r.ok) return { status: 'ok', data: await r.json() }
51
+ } catch { /* 网络错误:等一下再试 */ }
52
+ await sleep(wait * (i + 1))
53
+ }
54
+ return { status: 'failed' }
55
+ }
56
+
57
+ /**
58
+ * 读一批 npm manifest(/latest),分轮降速:第一轮并发 8,没拿到的第二轮并发 2,再没拿到的第三轮逐个慢慢来
59
+ * @returns {Promise<Map<string, {status: string, data?: any}>>}
60
+ */
61
+ export async function fetchManifests(names, { wait = 800, onProgress = () => {} } = {}) {
62
+ const out = new Map()
63
+ let pending = names.slice()
64
+ const rounds = [{ conc: 8, pause: 0 }, { conc: 2, pause: 200 }, { conc: 1, pause: 600 }]
65
+ for (let round = 0; round < rounds.length && pending.length; round++) {
66
+ const { conc, pause } = rounds[round]
67
+ if (round > 0) onProgress(` manifest 第 ${round + 1} 轮(并发 ${conc}),${pending.length} 个上一轮没拿到…`)
68
+ await pool(pending, conc, async n => {
69
+ out.set(n, await jgetStatus(`${REG_API}/${enc(n)}/latest`, { wait }))
70
+ if (pause) await sleep(pause * wait / 800)
71
+ })
72
+ pending = pending.filter(n => out.get(n).status === 'failed')
73
+ }
74
+ return out
75
+ }
76
+
39
77
  async function jget(url, tries = 4) {
40
78
  for (let i = 0; i < tries; i++) {
41
79
  try {
@@ -251,8 +289,17 @@ export async function buildCatalog({ deep = 200, max = 2250, pages = 9, deepOnly
251
289
  // 已经有的不再抓:deepOnly 沿用的,和社区目录补进来时读过 manifest 的
252
290
  const needFacts = [...records.values()].filter(r => !r.inst)
253
291
  onProgress(`安装信息 ${needFacts.length} 个…`)
254
- const manifests = await pool(needFacts, 8, rec => jget(`${REG_API}/${enc(rec.n)}/latest`, 2))
255
- needFacts.forEach((rec, i) => { if (manifests[i]) rec.inst = installFacts(manifests[i]) })
292
+ const facts = await fetchManifests(needFacts.map(r => r.n), { onProgress })
293
+ let factsReused = 0
294
+ for (const rec of needFacts) {
295
+ const res = facts.get(rec.n)
296
+ if (res.status === 'ok') rec.inst = installFacts(res.data)
297
+ else if (res.status === 'failed' && previous && previous.packages && previous.packages[rec.n] && previous.packages[rec.n].inst) {
298
+ rec.inst = previous.packages[rec.n].inst // 被限流没读到:沿用上次的
299
+ factsReused++
300
+ }
301
+ }
302
+ if (factsReused) onProgress(` ${factsReused} 个安装信息这次没读到,沿用上次的`)
256
303
 
257
304
  // GitHub:星标、Fork、未关闭 issue / PR、最近提交、归档。要令牌(Actions 自带的就够),没有就跳过
258
305
  if (githubToken) {
@@ -277,7 +324,14 @@ export async function buildCatalog({ deep = 200, max = 2250, pages = 9, deepOnly
277
324
 
278
325
  // npm、GitHub 之外的榜单:官方、社区、插件商店(抓不到的沿用上次)
279
326
  onProgress('其他榜单…')
280
- const boards = await buildBoards({ previous: previous && previous.boards, communityDoc, onProgress })
327
+ const members = {}
328
+ const boards = await buildBoards({ previous: previous && previous.boards, communityDoc, members, onProgress })
329
+
330
+ // 综合榜:几个市场合成一个榜,一个插件一行;顺带给每个 npm 包写上综合分 sc 和「收录于」src
331
+ const previousSrc = {}
332
+ for (const r of Object.values((previous && previous.packages) || {})) if (r && r.src) previousSrc[r.n] = r.src
333
+ boards.overall = buildOverall({ packages: Object.fromEntries(records), members, previousSrc })
334
+ onProgress(` 综合榜:${boards.overall.total} 个插件参与排名(${Object.entries(boards.overall.excluded).map(([k, v]) => `${k} ${v}`).join('、') || '无'}不进榜)`)
281
335
 
282
336
  for (const rec of records.values()) slimRecord(rec)
283
337
 
@@ -310,14 +364,31 @@ export async function buildCatalog({ deep = 200, max = 2250, pages = 9, deepOnly
310
364
  * @param {string} [opt.today] YYYY-MM-DD,决定今天轮到哪些带 scope 的包(见 weeklyDue)
311
365
  * @returns {Promise<number>} 补进去几个
312
366
  */
313
- export async function addCommunity(records, rows, { previous = {}, today = new Date().toISOString().slice(0, 10), onProgress = () => {} } = {}) {
367
+ export async function addCommunity(records, rows, { previous = {}, today = new Date().toISOString().slice(0, 10), wait = 800, onProgress = () => {} } = {}) {
314
368
  const missing = rows.filter(r => !records.has(r.n))
315
369
  onProgress(`社区目录 ${rows.length} 个 npm 包,其中 ${missing.length} 个搜索接口没翻到,逐个读 manifest…`)
316
- const manifests = await pool(missing, 8, r => jget(`${REG_API}/${enc(r.n)}/latest`))
317
- const added = missing
318
- .map((row, i) => communityRecord(row, manifests[i]))
319
- .filter(Boolean)
320
- if (added.length < missing.length) onProgress(` ${missing.length - added.length} 个在 npm 上查不到,不收`)
370
+ const got = await fetchManifests(missing.map(r => r.n), { wait, onProgress })
371
+ const added = []
372
+ let gone = 0, reused = 0, lost = 0
373
+ for (const row of missing) {
374
+ const res = got.get(row.n)
375
+ if (res.status === 'ok') {
376
+ const rec = communityRecord(row, res.data)
377
+ if (rec) added.push(rec)
378
+ else gone++ // 名字对不上,当不存在
379
+ } else if (res.status === 'gone') {
380
+ gone++
381
+ } else if (previous && previous[row.n]) {
382
+ // 三轮都没拿到(多半被限流):沿用上次目录里的,别因为一次网络问题就把包丢了
383
+ added.push({ ...previous[row.n] })
384
+ reused++
385
+ } else {
386
+ lost++
387
+ }
388
+ }
389
+ if (gone) onProgress(` ${gone} 个在 npm 上不存在,不收`)
390
+ if (reused) onProgress(` ${reused} 个这次没读到 manifest,沿用上次目录里的`)
391
+ if (lost) onProgress(` ${lost} 个这次没读到、上次目录里也没有,先不收`)
321
392
 
322
393
  // 不带 scope 的批量查,每天全查;带 scope 的只能逐个查,下载量接口经不起(几百个包在 Actions 上要排队二十多分钟),
323
394
  // 所以每天只查轮到的那组和上次没有数的,其余沿用上次的
@@ -490,6 +561,10 @@ export async function loadCatalog({ env = process.env } = {}) {
490
561
  if (cache) return cache
491
562
  const [bundled, cached] = await Promise.all([readJson(CATALOG_PATH), readJson(cachePath(env))])
492
563
  const pick = newerCatalog(cached, bundled) ? { ...cached, source: 'remote' } : bundled ? { ...bundled, source: 'bundled' } : null
564
+ // 每日目录是旧代码构建的、还没有某个榜(比如刚加的综合榜):先用随包自带的那份顶上,下次每日构建后就齐了
565
+ if (pick && pick.source === 'remote' && bundled && bundled.boards) {
566
+ pick.boards = { ...bundled.boards, ...(pick.boards || {}) }
567
+ }
493
568
  cache = pick ? normalize(pick) : { asOf: null, anchor: null, packages: {}, total: 0, source: 'none' }
494
569
  return cache
495
570
  }
package/lib/github.js CHANGED
@@ -13,6 +13,7 @@
13
13
 
14
14
  const GRAPHQL = 'https://api.github.com/graphql'
15
15
  const REST = 'https://api.github.com/repos/'
16
+ // 一次 50 个。试过 100 个:每批会有一部分仓库返回空(200 个只查到 147 个,50 个一批是 196 个),时间也省不了多少
16
17
  const BATCH = 50
17
18
 
18
19
  /** 从各种写法的仓库地址里取出 owner/name;不是 GitHub 仓库返回 null */
@@ -32,6 +32,7 @@ const CATEGORY_IDS = {
32
32
  }
33
33
 
34
34
  const SORT_KEYS = {
35
+ overall: { title: { en: 'dsh-pick overall score', zh: '综合分' }, order: 'desc' },
35
36
  downloads: { title: { en: 'Weekly downloads', zh: '周下载' }, order: 'desc' },
36
37
  baseline: { title: { en: 'Daily baseline (denoised)', zh: '日常基线(去噪)' }, order: 'desc' },
37
38
  stars: { title: { en: 'GitHub stars', zh: 'GitHub 星标' }, order: 'desc' },
@@ -49,8 +50,8 @@ export function indexRoot() {
49
50
  format: 1,
50
51
  title: { en: 'dsh-pick · DSH plugin picks', zh: 'dsh-pick 选插件' },
51
52
  description: {
52
- en: 'Every npm DSH plugin that declares engines.dsh and a bundle, sorted by weekly downloads, with denoised download metrics and GitHub stars. Rebuilt daily; a community index, not an official DeepSeek one.',
53
- zh: '所有声明了 engines.dsh 和 bundle 的 npm DSH 插件,按周下载排,带去噪后的下载指标和 GitHub 星标。每天重建;社区索引,不是 DeepSeek 官方的。',
53
+ en: 'Every npm DSH plugin that declares engines.dsh and a bundle, ordered by the dsh-pick overall score (merging dshmarket, dsh-m picks, dsh-plugin-shop and the DeepSeek official list), with denoised download metrics and GitHub stars. Rebuilt daily; a community index, not an official DeepSeek one.',
54
+ zh: '所有声明了 engines.dsh 和 bundle 的 npm DSH 插件,默认按 dsh-pick 综合分排(合并 dshmarket、dsh-m 精选、dsh-plugin-shop、DeepSeek 官方几个市场),带去噪后的下载指标和 GitHub 星标。每天重建;社区索引,不是 DeepSeek 官方的。',
54
55
  },
55
56
  metadata: { categories, sortKeys: SORT_KEYS },
56
57
  }
@@ -77,6 +78,7 @@ export function indexEntry(rec, publishedAt) {
77
78
  if (repo) entry.repository = { url: `https://github.com/${repo}` }
78
79
 
79
80
  const sortKeys = {}
81
+ if (finite(rec.sc) !== undefined) sortKeys.overall = rec.sc
80
82
  const d = rec.deep
81
83
  if (finite(rec.w) !== undefined) sortKeys.downloads = rec.w
82
84
  if (d && finite(d.base ?? d.baseline) !== undefined) sortKeys.baseline = d.base ?? d.baseline
@@ -106,11 +108,12 @@ export function indexEntry(rec, publishedAt) {
106
108
  * @returns {{ index: object, skipped: Record<string, number>, rejected: {name: string, reason: string}[] }}
107
109
  */
108
110
  export function buildMarketIndex(catalog, { parse, times = {} }) {
111
+ // 默认顺序按综合分(没有的按周下载):「发现」页不选排序时,最值得装的在前面
109
112
  const root = indexRoot()
110
113
  const skipped = {}
111
114
  const rejected = []
112
115
  const plugins = []
113
- const recs = Object.values(catalog.packages || {}).sort((a, b) => (b.w || 0) - (a.w || 0))
116
+ const recs = Object.values(catalog.packages || {}).sort((a, b) => (b.sc ?? -1) - (a.sc ?? -1) || (b.w || 0) - (a.w || 0))
114
117
  for (const rec of recs) {
115
118
  const { entry, skip } = indexEntry(rec, times[rec.n])
116
119
  if (skip) {
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.3",
3
+ "version": "0.6.1",
4
4
  "description": "帮你在 DSH 生态里选对插件:说需求 → 找候选 → 多维比较 → 出结论。下载量是证据,AI 是推理。",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,6 +30,22 @@
30
30
  },
31
31
  "client": {
32
32
  "platform": "web"
33
+ },
34
+ "catalog": {
35
+ "category": "tool",
36
+ "summary": {
37
+ "en": "Pick DSH plugins: an overall ranking that merges several plugin markets, denoised download metrics, GitHub data, one-click install.",
38
+ "zh": "选 DSH 插件:合并几个插件市场的综合榜、去噪后的下载指标、GitHub 数据,榜上一键安装。"
39
+ },
40
+ "capabilities": [
41
+ "webServer",
42
+ "pluginManager",
43
+ "pluginMarket",
44
+ "tools",
45
+ "sidebarRight",
46
+ "sessions",
47
+ "network"
48
+ ]
33
49
  }
34
50
  },
35
51
  "files": [
@@ -54,7 +70,9 @@
54
70
  "plugin-advisor",
55
71
  "pick",
56
72
  "npm-stats",
57
- "plugin-market"
73
+ "plugin-market",
74
+ "marketplace",
75
+ "plugin-manager"
58
76
  ],
59
77
  "license": "MIT",
60
78
  "engines": {
package/plugin/index.js CHANGED
@@ -458,7 +458,10 @@ export function apply(ctx) {
458
458
  if (!isSafePost(req)) return sendJson(res, 403, { ok: false, message: '只接受本页面发出的请求' })
459
459
  const { name } = await readJsonBody(req)
460
460
  if (typeof name !== 'string' || !NAME_RE.test(name)) return sendJson(res, 400, { ok: false, message: '包名不对' })
461
- 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)
462
465
  if (!rec) return sendJson(res, 400, { ok: false, message: `${name} 不在 DSH 插件目录里,这里不装` })
463
466
  // 没声明 dsh.bundle 的包,DSH 一定拒绝安装:不白跑一趟 pnpm
464
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>