dsh-pick 0.4.3 → 0.5.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/plugin/tools.js CHANGED
@@ -49,8 +49,10 @@ function line(r) {
49
49
  r.relevance != null ? `相关度 ${r.relevance}%` : '',
50
50
  ].filter(Boolean).join(' · ')
51
51
  const desc = r.description ? `\n ${String(r.description).slice(0, 160)}` : ''
52
+ const g = r.gh
53
+ const gh = g ? `\n GitHub ★${num(g.s)} · Fork ${num(g.f)} · 未关闭 issue/PR ${num(g.i)} · 最近提交 ${g.p || '—'}${g.a ? ' · 已归档' : ''}${g.l ? ` · ${g.l}` : ''}` : ''
52
54
  const notes = r.notes && r.notes.length ? `\n ⚠ ${r.notes.join(';')}` : ''
53
- return `- ${parts}\n ${nums}${desc}${notes}`
55
+ return `- ${parts}\n ${nums}${gh}${desc}${notes}`
54
56
  }
55
57
 
56
58
  /**
@@ -72,9 +74,10 @@ export function annotate(rows, cat, have) {
72
74
  if (inst && !inst.b) notes.push('没声明 dsh.bundle,DSH 不能把它当插件安装')
73
75
  if (inst && inst.p && inst.p !== 'web') notes.push(`这是 ${inst.p} 客户端插件,装进桌面版 / 网页版可能让 DSH 起不来`)
74
76
  if (inst && inst.r) notes.push(`声明需要 DSH ${inst.r}`)
77
+ if (rec.gh && rec.gh.a) notes.push('GitHub 仓库已归档,作者不再维护')
75
78
  const same = (installedByCat.get(rec.cat || r.category) || []).filter(n => n !== r.name)
76
79
  if (same.length && !have.has(r.name)) notes.push(`你已装了同类插件:${same.join('、')},功能可能重叠`)
77
- return { ...r, installed: have.has(r.name), notes }
80
+ return { ...r, gh: rec.gh || r.gh || null, installed: have.has(r.name), notes }
78
81
  })
79
82
  }
80
83
 
@@ -124,10 +127,10 @@ const cleanNames = (names, max) =>
124
127
  */
125
128
  export async function buildToolDefinitions(deps = {}) {
126
129
  const defineTool = await loadDefineTool()
127
- const installed = () => {
128
- try { return deps.installed ? deps.installed() : new Set() } catch { return new Set() }
130
+ const installed = async () => {
131
+ try { return deps.installed ? await deps.installed() : new Set() } catch { return new Set() }
129
132
  }
130
- const header = cat => `目录数据截止 ${cat.anchor || '未知'}(npm 统计约滞后 5 天),共 ${num(cat.total)} 个插件。`
133
+ const header = cat => `目录数据截止 ${cat.anchor || '未知'}(npm 最近有数据的一天;npm 每日下载只在一天结束后汇总,常晚几天),共 ${num(cat.total)} 个插件。`
131
134
  const CATS = allCategories()
132
135
 
133
136
  return [
@@ -156,7 +159,7 @@ export async function buildToolDefinitions(deps = {}) {
156
159
  limit: clampInt(args.limit, 1, 20, 8),
157
160
  category: CATS.includes(args.category) ? args.category : null,
158
161
  })
159
- return plain({ header: header(cat), need, candidates: annotate(candidates, cat, installed()) })
162
+ return plain({ header: header(cat), need, candidates: annotate(candidates, cat, await installed()) })
160
163
  },
161
164
  }),
162
165
 
@@ -181,7 +184,7 @@ export async function buildToolDefinitions(deps = {}) {
181
184
  const names = cleanNames(args.names, 8)
182
185
  if (!names.length) throw new Error('names 里没有合法的 npm 包名')
183
186
  const rows = (await stats(cat, names)).map(withCatalogFields(cat))
184
- return plain({ header: header(cat), rows: annotate(rows, cat, installed()) })
187
+ return plain({ header: header(cat), rows: annotate(rows, cat, await installed()) })
185
188
  },
186
189
  }),
187
190
 
@@ -231,33 +234,50 @@ export async function buildToolDefinitions(deps = {}) {
231
234
  return { label: m.label, winner: vals[0][0], value: m.fmt(vals[0][1]) }
232
235
  })
233
236
  rows.sort((a, b) => ((b.deep && b.deep.score) ?? -1) - ((a.deep && a.deep.score) ?? -1))
234
- return plain({ header: header(cat), best, rows: annotate(rows, cat, installed()), missing })
237
+ return plain({ header: header(cat), best, rows: annotate(rows, cat, await installed()), missing })
235
238
  },
236
239
  }),
237
240
 
238
241
  defineTool({
239
242
  name: 'pick_rank',
240
243
  description:
241
- '插件排行榜:全部或某一类,可按周下载、日常基线、环比增速、健康度排。用户问「哪些插件最火 / 某类里谁最好」时用它。',
244
+ '插件排行榜:全部或某一类,可按周下载、日常基线、环比增速、健康度、GitHub 星标、GitHub 最近提交排。用户问「哪些插件最火 / 某类里谁最好 / 谁还在维护 / 官方有哪些插件 / 社区最近新上了什么」时用它。',
242
245
  parameters: {
243
- metric: { type: 'string', enum: ['weekly', 'baseline', 'growth', 'score'], description: '排序指标,默认 baseline(日常基线,最接近真实使用量)' },
246
+ metric: { type: 'string', enum: ['weekly', 'baseline', 'growth', 'score', 'stars', 'pushed', 'downloads', 'newest'], description: '排序指标,默认 baseline(日常基线,最接近真实使用量);stars = GitHub 星标,pushed = GitHub 最近提交' },
244
247
  category: { type: 'string', enum: CATS, description: '只看某一类(可省略)' },
245
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' },
246
250
  },
247
251
  output: {
248
252
  schema: ANY_JSON,
249
253
  render: (_a, v) => [{
250
254
  type: 'text',
251
- text: `${v.header}\n排行:${v.category || '全部'} · 按${v.metricLabel}\n${v.rows.map((r, i) => `${i + 1}.${line(r).slice(1)}`).join('\n')}\n\n${NOTE}`,
255
+ text: v.board ? `${v.header}\n${v.board}\n${v.rows.join('\n')}\n\n只引用这里的数字,不要自己推算。下载量含 CI、镜像流量,不等于用户数。` : `${v.header}\n排行:${v.category || '全部'} · 按${v.metricLabel}\n${v.rows.map((r, i) => `${i + 1}.${line(r).slice(1)}`).join('\n')}\n\n${NOTE}`,
252
256
  }],
253
257
  },
254
258
  async execute(args) {
255
259
  const cat = await loadCatalog()
256
- const LABELS = { weekly: '周下载', baseline: '日常基线', growth: '环比增速', score: '健康度' }
260
+ if (args.board) {
261
+ const limit = clampInt(args.limit, 1, 30, 10)
262
+ const board = cat.boards && cat.boards[args.board]
263
+ const TITLE = { official: 'DeepSeek 官方插件', community: 'awesome-dsh-plugin 社区目录', shop: 'dsh-plugin-shop 插件商店(第三方,非官方)' }
264
+ if (!board) return plain({ header: header(cat), board: `${TITLE[args.board]}:还没有这个榜单的数据`, rows: [] })
265
+ const key = args.board === 'official' ? 'w' : args.metric === 'downloads' ? 'dl' : args.metric === 'newest' ? 'added' : 's'
266
+ const rows = board.rows.filter(r => r[key] != null)
267
+ .sort((a, b) => (b[key] > a[key] ? 1 : b[key] < a[key] ? -1 : 0)).slice(0, limit)
268
+ return plain({
269
+ header: header(cat),
270
+ board: `${TITLE[args.board]}(共 ${num(board.total)} 个)`,
271
+ rows: rows.map((r, i) => `${i + 1}. ${r.n || r.name}` +
272
+ (r.s != null ? ` · ★${num(r.s)}` : '') + (r.dl != null ? ` · 30 天下载 ${num(r.dl)}` : '') + (r.w != null ? ` · 周下载 ${num(r.w)}` : '') +
273
+ (r.added ? ` · 收录 ${r.added}` : '') + (r.n ? '' : ` · 只在 GitHub(${r.repo})`) + (r.d ? `\n ${r.d}` : '')),
274
+ })
275
+ }
276
+ const LABELS = { weekly: '周下载', baseline: '日常基线', growth: '环比增速', score: '健康度', stars: 'GitHub 星标', pushed: 'GitHub 最近提交' }
257
277
  const metric = LABELS[args.metric] ? args.metric : 'baseline'
258
278
  const category = CATS.includes(args.category) ? args.category : null
259
279
  const rows = rank(cat, { metric, category, limit: clampInt(args.limit, 1, 30, 10) }).map(fromRec)
260
- return plain({ header: header(cat), metric, metricLabel: LABELS[metric], category, rows: annotate(rows, cat, installed()) })
280
+ return plain({ header: header(cat), metric, metricLabel: LABELS[metric], category, rows: annotate(rows, cat, await installed()) })
261
281
  },
262
282
  }),
263
283
  ]
package/web/panel.html CHANGED
@@ -107,6 +107,14 @@ h1{margin:0;font-size:19px;font-weight:650;letter-spacing:-.2px}
107
107
  .ai:hover{border-color:color-mix(in srgb,var(--ai) 62%,transparent);
108
108
  background:linear-gradient(135deg,color-mix(in srgb,var(--accent) 22%,transparent),color-mix(in srgb,var(--ai) 28%,transparent))}
109
109
  .section h2 .ai{margin-left:auto;font-weight:650}
110
+ /* 排行榜:npm 榜 / GitHub 榜 */
111
+ .board{display:flex;flex-wrap:wrap;width:fit-content;max-width:100%;gap:2px;background:var(--soft);border-radius:9px;padding:3px;margin:8px 0 6px}
112
+ .board button{appearance:none;border:none;background:transparent;font-family:inherit;font-size:12.5px;font-weight:600;
113
+ color:var(--t3);padding:6px 14px;border-radius:6px;cursor:pointer}
114
+ .board button.on{background:var(--panel);color:var(--text);box-shadow:0 1px 2px var(--shadow)}
115
+ table.rank td.nm .sub{font-size:10.5px;color:var(--t3);font-weight:400;margin-top:2px}
116
+ table.rank td.nm .desc{min-width:150px;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
117
+ table.rank td .arch{font-size:10.5px;color:var(--t3);background:var(--soft);border-radius:5px;padding:1px 6px}
110
118
  .section h2 .h2-acts{margin-left:auto;display:inline-flex;gap:8px;align-items:center}
111
119
  .section h2 .h2-acts .ai{margin-left:0}
112
120
  .btn.sm{font-size:11.5px;padding:0 10px;height:24px;border-radius:7px}
@@ -205,7 +213,14 @@ table.rank td.mt{line-height:1.35}
205
213
  table.rank td.mt .sub{font-size:10.5px;color:var(--t3)}
206
214
  table.rank td.mt .stale{color:var(--warn-text);font-weight:600}
207
215
  /* 只有图标的外链(排行榜) */
208
- table.rank td.lks{white-space:nowrap;width:1%}
216
+ table.rank td.lks{white-space:nowrap;width:1%;position:sticky;right:0;background:var(--panel);box-shadow:-6px 0 6px -6px var(--shadow)}
217
+ table.rank tbody tr:hover td.lks{background:var(--panel)}
218
+ /* 彩色 + 号:一键加入我的监控;已加入显示 ✓,再点取消 */
219
+ .wadd{appearance:none;display:inline-flex;align-items:center;justify-content:center;width:24px;height:22px;padding:0;margin-right:4px;
220
+ border:none;border-radius:6px;cursor:pointer;font-family:inherit;font-size:15px;font-weight:700;line-height:1;color:#fff;vertical-align:top;
221
+ background:linear-gradient(135deg,#ff7a45,#f5317f 55%,#7c4dff)}
222
+ .wadd:hover{filter:brightness(1.1)}
223
+ .wadd.on{background:var(--ok-bg);color:var(--ok-text);font-size:12px}
209
224
  .lk.ic{padding:0;width:24px;height:22px;justify-content:center;gap:0}
210
225
  .lk.ic + .lk.ic{margin-left:4px}
211
226
  td.up{color:var(--ok);font-weight:600}
@@ -353,21 +368,33 @@ td.down{color:var(--bad);font-weight:600}
353
368
  <div id="tab-rank" class="hidden">
354
369
  <div class="section">
355
370
  <h2>排行榜</h2>
356
- <p class="cap">换一种方式发现:按去噪后的指标看整个生态。</p>
371
+ <div class="board" id="rankBoard">
372
+ <button data-b="npm" class="on">npm 榜</button>
373
+ <button data-b="gh">GitHub 榜</button>
374
+ <button data-b="official">官方榜</button>
375
+ <button data-b="community">社区榜</button>
376
+ <button data-b="shop">商店榜</button>
377
+ </div>
378
+ <p class="cap" id="rankCap"></p>
357
379
  <div class="filters" id="rankFilters">
358
- <button class="chip on" data-m="base">日常基线</button>
359
- <button class="chip" data-m="w">周下载</button>
360
- <button class="chip" data-m="growth">增速最快</button>
361
- <button class="chip" data-m="s">健康度</button>
380
+ <button class="chip on" data-board="npm" data-m="base">日常基线</button>
381
+ <button class="chip" data-board="npm" data-m="w">周下载</button>
382
+ <button class="chip" data-board="npm" data-m="growth">增速最快</button>
383
+ <button class="chip" data-board="npm" data-m="s">健康度</button>
384
+ <button class="chip on hidden" data-board="gh" data-m="gs">星标</button>
385
+ <button class="chip hidden" data-board="gh" data-m="gp">最近提交</button>
386
+ <button class="chip hidden" data-board="gh" data-m="gf">Fork</button>
387
+ <button class="chip hidden" data-board="gh" data-m="gi">讨论最多</button>
388
+ <button class="chip on hidden" data-board="community" data-m="s">星标</button>
389
+ <button class="chip hidden" data-board="community" data-m="dl">下载</button>
390
+ <button class="chip hidden" data-board="community" data-m="added">新上架</button>
391
+ <button class="chip on hidden" data-board="shop" data-m="s">星标</button>
392
+ <button class="chip hidden" data-board="shop" data-m="added">新上架</button>
362
393
  <select id="rankCat"></select>
363
394
  </div>
364
395
  <div class="tblwrap">
365
396
  <table class="rank">
366
- <thead><tr>
367
- <th style="width:44px">#</th><th>插件</th><th>分类</th>
368
- <th class="r">基线</th><th class="r">周下载</th><th class="r">环比</th>
369
- <th class="r" title="最近一次发版 · 平均几天发一个版本">更新</th><th></th>
370
- </tr></thead>
397
+ <thead id="rankHead"></thead>
371
398
  <tbody id="rankBody"></tbody>
372
399
  </table>
373
400
  </div>
@@ -378,7 +405,7 @@ td.down{color:var(--bad);font-weight:600}
378
405
  <div id="tab-watch" class="hidden">
379
406
  <div class="section">
380
407
  <h2>我的监控<span class="h2-acts"><button class="btn ghost sm" id="btnWatchRefresh" title="去 npm 实时查这些插件的最新数据">↻ 刷新</button><button class="ai hidden" id="aiWatch" title="把监控列表发到对话里,让 AI 看看谁在涨、谁停更了">+AI 看看近况</button></span></h2>
381
- <p class="cap"><span id="watchAsOf"></span>监控列表存在浏览器本地,不上传。点「刷新」去 npm 查最新:版本号、发版时间是即时的;下载量 npm 大约一天更新一次,日常基线和环比按 npm 下载统计算(滞后约 5 天)。</p>
408
+ <p class="cap"><span id="watchAsOf"></span>监控列表存在浏览器本地,不上传。点「刷新」去 npm 和 GitHub 查最新:版本号、发版时间、GitHub 数据是即时的;周下载 npm 大约一天更新一次;日常基线和环比按 npm 已经出数据的最近 30 天算(npm 只在一天结束后才汇总,最近还常晚几天)。</p>
382
409
  <div id="watchList"></div>
383
410
  </div>
384
411
  <div class="section">
package/web/panel.js CHANGED
@@ -61,13 +61,14 @@ function askAI(text) {
61
61
  function factLine(r) {
62
62
  const d = r.deep
63
63
  return [
64
- `周下载 ${num(r.w)}`,
65
- d ? `日常基线 ${num(d.base)}` : '无去噪指标(周下载 Top 之外)',
64
+ r.w != null ? `周下载 ${num(r.w)}` : '',
65
+ d ? `日常基线 ${num(d.base)}` : (r.w != null ? '无去噪指标(周下载 Top 之外)' : '只在 GitHub,没有 npm 数据'),
66
66
  d ? `近 7 日环比 ${pct(d.growth)}` : '',
67
67
  d && d.cadence != null ? `${d.cadence} 天/版` : '',
68
68
  d && d.age != null ? `${d.age} 天前更新` : '',
69
69
  d ? `健康度 ${d.s}` : '',
70
70
  r.rank ? `总榜 #${r.rank}` : '',
71
+ r.gh ? [`GitHub ★${r.gh.s}`, r.gh.f != null ? `Fork ${r.gh.f}` : '', r.gh.i != null ? `未关闭 issue/PR ${r.gh.i}` : '', r.gh.p ? `最近提交 ${r.gh.p}` : '', r.gh.a ? '已归档' : ''].filter(Boolean).join('、') : '',
71
72
  ].filter(Boolean).join(' · ')
72
73
  }
73
74
  const needLine = () => {
@@ -112,6 +113,7 @@ function askVerdict() {
112
113
 
113
114
  function askWatch() {
114
115
  const rows = watch().map(watchRec).filter(Boolean)
116
+ rows.forEach(r => { if (r.label) r.n = r.label })
115
117
  const live = LIVE.at ? `(npm 实时数据,${new Date(LIVE.at).toLocaleString()} 刷新;下载量含 CI / 镜像流量,不等于用户数)` : dataAsOf()
116
118
  return [
117
119
  `帮我看看我关注的这些 DSH 插件最近怎么样${live}:`,
@@ -183,6 +185,8 @@ function installCheck(r) {
183
185
  // 已经装不了(没 bundle、终端版)就不说「兼容」:版本对得上不等于装得上,两句放一起让人困惑
184
186
  good.push(`兼容你的 DSH${HOST_VERSION ? ' ' + HOST_VERSION : ''}`)
185
187
  }
188
+ if (r.gh && r.gh.a) warn.push('GitHub 仓库已归档,作者不再维护')
189
+ else if (r.gh && daysSince(r.gh.p) > 180) warn.push(`仓库 ${Math.round(daysSince(r.gh.p) / 30)} 个月没有提交`)
186
190
  const same = sameKindInstalled(r)
187
191
  if (same.length) warn.push(`你已装同类:${same.join('、')}`)
188
192
  return { ok, warn, good }
@@ -266,7 +270,7 @@ function linkBtns(rec, { icon = false } = {}) {
266
270
  if (rec.ghUrl) {
267
271
  h += `<a class="${cls}" href="${esc(rec.ghUrl)}" target="_blank" rel="noopener" title="GitHub:${esc(rec.ghUrl)}" aria-label="GitHub">${GH_SVG}${icon ? '' : 'GitHub'}</a>`
268
272
  }
269
- h += `<a class="${cls}" href="${esc(npm)}" target="_blank" rel="noopener" title="npm:${esc(npm)}" aria-label="npm">${NPM_SVG}${icon ? '' : 'npm'}</a>`
273
+ if (rec.n) h += `<a class="${cls}" href="${esc(npm)}" target="_blank" rel="noopener" title="npm:${esc(npm)}" aria-label="npm">${NPM_SVG}${icon ? '' : 'npm'}</a>`
270
274
  return h
271
275
  }
272
276
 
@@ -322,14 +326,18 @@ async function boot() {
322
326
  const deepN = Object.values(CAT.packages).filter(p => p.deep).length
323
327
  $('#meta').innerHTML =
324
328
  `目录 <b>${num(CAT.total)}</b> 个插件 · 去噪指标 <b>${num(deepN)}</b> 个<br>` +
325
- `数据截止 <b>${CAT.anchor}</b>(npm 统计滞后约 5 天)`
329
+ `数据截止 <b>${CAT.anchor}</b>(npm 最近有数据的一天)`
326
330
 
331
+ const gapNote = CAT.gaps && CAT.gaps.length
332
+ ? `<br><b>npm 缺数据的日子:</b>${CAT.gaps.map(esc).join('、')}(那几天全 npm 的下载统计都是 0,是 npm 自己没出数据),不参与日常基线和环比的计算。`
333
+ : ''
327
334
  $('#foot').innerHTML =
328
335
  `<b>口径:</b>下载量含 CI、镜像、爬虫等非人类流量,不等于用户数;<b>日常基线</b>= 扣掉版本发布日与次日后的每日中位数,比原始下载量更接近真实使用量。<br>` +
329
336
  `<b>覆盖范围:</b>npm 上带 <code>dsh-plugin</code> 关键字的 ${num(CAT.total)} 个包;去噪指标只算了周下载 Top ${num(deepN)}。目录每天重建一次,重跑 <code>dsh-pick build</code> 即可。<br>` +
330
337
  (IN_DSH
331
338
  ? `<b>当前结论由本地规则生成</b>(依据就是对比表里的数字)。点各处的「+AI」,把数据发到对话里让 AI 结合你的场景分析;在对话里也可以直接问「哪个插件能做某某」,AI 会自己查这份目录。`
332
- : `<b>当前结论由本地规则生成</b>(依据就是对比表里的数字)。装上 DSH 插件版后,可以一键交给 AI,结合你的具体场景解释取舍。`)
339
+ : `<b>当前结论由本地规则生成</b>(依据就是对比表里的数字)。装上 DSH 插件版后,可以一键交给 AI,结合你的具体场景解释取舍。`) +
340
+ gapNote
333
341
 
334
342
  await loadInstalled()
335
343
  if (IN_DSH) {
@@ -367,9 +375,16 @@ function bindEvents() {
367
375
  })
368
376
  })
369
377
 
378
+ document.querySelectorAll('#rankBoard button').forEach(bt => {
379
+ bt.addEventListener('click', () => {
380
+ document.querySelectorAll('#rankBoard button').forEach(x => x.classList.toggle('on', x === bt))
381
+ document.querySelectorAll('#rankFilters .chip').forEach(c => c.classList.toggle('hidden', c.dataset.board !== bt.dataset.b))
382
+ renderRank()
383
+ })
384
+ })
370
385
  document.querySelectorAll('#rankFilters .chip').forEach(c => {
371
386
  c.addEventListener('click', () => {
372
- document.querySelectorAll('#rankFilters .chip').forEach(x => x.classList.toggle('on', x === c))
387
+ document.querySelectorAll(`#rankFilters .chip[data-board="${c.dataset.board}"]`).forEach(x => x.classList.toggle('on', x === c))
373
388
  renderRank()
374
389
  })
375
390
  })
@@ -379,6 +394,10 @@ function bindEvents() {
379
394
  $('#aiVerdict').addEventListener('click', () => picked.length >= 2 && askAI(askVerdict()))
380
395
  $('#aiWatch').addEventListener('click', () => watch().length && askAI(askWatch()))
381
396
  $('#btnWatchRefresh').addEventListener('click', refreshWatch)
397
+ document.addEventListener('click', e => {
398
+ const b = e.target.closest('[data-watch]')
399
+ if (b) toggleWatch(b.dataset.watch)
400
+ })
382
401
 
383
402
  $('#btnExport').addEventListener('click', exportHtml)
384
403
  $('#btnWatch').addEventListener('click', addPickedToWatch)
@@ -420,9 +439,10 @@ function renderCands(need, { keepCompat = false } = {}) {
420
439
  `<span>周 <b>${num(rec.w)}</b></span>` +
421
440
  `<span>月 <b>${num(rec.m)}</b></span>` +
422
441
  (d ? `<span>基线 <b>${num(d.base)}</b></span><span>环比 <b>${pct(d.growth)}</b></span>` : '') +
442
+ (rec.gh ? `<span title="GitHub 星标 · 最近提交 ${esc(rec.gh.p || '—')}">★ <b>${short(rec.gh.s)}</b></span>` : '') +
423
443
  `</div>` +
424
444
  checkRow(rec) +
425
- `<div class="links">${linkBtns(rec)}<span class="sp"></span>${installArea(rec)}` +
445
+ `<div class="links">${watchBtn(rec.n)}${linkBtns(rec)}<span class="sp"></span>${installArea(rec)}` +
426
446
  (IN_DSH ? `<button class="ai" data-ask title="把这个插件的数据发到对话里问 AI">+AI</button>` : '') +
427
447
  `</div>` +
428
448
  `</div>`
@@ -432,7 +452,7 @@ function renderCands(need, { keepCompat = false } = {}) {
432
452
  if (ask) { e.stopPropagation(); askAI(askCard(rec)); return }
433
453
  const inst = e.target.closest('[data-install]')
434
454
  if (inst) { e.stopPropagation(); onInstallClick(inst); return }
435
- if (e.target.closest('a')) return
455
+ if (e.target.closest('a, [data-watch]')) return
436
456
  togglePick(rec.n)
437
457
  })
438
458
  host.appendChild(el)
@@ -462,6 +482,8 @@ const ROWS = [
462
482
  { k: 'cad', label: '版本节奏', get: r => r.deep && r.deep.cadence, fmt: r => r == null ? '—' : r + ' 天/版', best: 'min' },
463
483
  { k: 'age', label: '最近更新', get: r => r.deep && r.deep.age, fmt: r => r == null ? '—' : r + ' 天前', best: 'min' },
464
484
  { k: 's', label: '健康度', get: r => r.deep && r.deep.s, fmt: num, best: 'max' },
485
+ { k: 'gs', label: 'GitHub 星标', get: r => r.gh && r.gh.s, fmt: num, best: 'max' },
486
+ { k: 'gp', label: '最近提交', get: r => r.gh && daysSince(r.gh.p), fmt: r => r == null ? '—' : ageText(r), best: 'min' },
465
487
  ]
466
488
 
467
489
  function renderCompare() {
@@ -571,31 +593,148 @@ function buildCategoryFilter() {
571
593
  sel.innerHTML = '<option value="">全部分类</option>' + cats.map(c => `<option>${esc(c)}</option>`).join('')
572
594
  }
573
595
 
596
+ /** 距今几天(ISO 日期);没有日期返回 null */
597
+ function daysSince(iso) {
598
+ if (!iso) return null
599
+ return Math.max(0, Math.floor((Date.now() - Date.parse(iso + 'T00:00:00Z')) / 86400000))
600
+ }
601
+
602
+ /** 1234 → 1.2k:星标、Fork 这种数放在窄列里 */
603
+ const short = n => (n == null ? '—' : n >= 10000 ? Math.round(n / 1000) + 'k' : n >= 1000 ? (n / 1000).toFixed(1).replace(/\.0$/, '') + 'k' : String(n))
604
+
605
+ function rankBoard() {
606
+ return document.querySelector('#rankBoard button.on').dataset.b
607
+ }
608
+
609
+ /** 官方 / 社区 / 商店榜:数据来自别人维护的目录,每个榜只存头部 */
610
+ function renderOuterBoard(board) {
611
+ const data = CAT.boards && CAT.boards[board]
612
+ const CAPS = {
613
+ official: '来自 DeepSeek 官方包 dsh-official-bundles:官方提供的可选、按需插件。按周下载排,数字含 DSH 安装时的自动拉取,不等于主动选择的人数。',
614
+ community: `来自社区目录 awesome-dsh-plugin${data ? `(共 ${num(data.total)} 个${data.updated ? `,${esc(data.updated)} 更新` : ''})` : ''},不是 DeepSeek 官方。下载是近 30 天。`,
615
+ shop: `来自第三方插件商店 dsh-plugin-shop${data ? `(共 ${num(data.total)} 个)` : ''},不是 DeepSeek 官方,商店不提供下载量。`,
616
+ }
617
+ $('#rankCap').textContent = CAPS[board]
618
+ const empty = text => {
619
+ $('#rankHead').innerHTML = ''
620
+ $('#rankBody').innerHTML = `<tr><td class="empty">${text}</td></tr>`
621
+ }
622
+ if (!data || !data.rows.length) return empty('还没有这个榜单的数据(每日更新取到后就有)。')
623
+
624
+ const nameCell = r => `<td class="nm">${esc(r.t || r.n || r.name)}${r.v ? ` <span style="color:var(--t3);font-weight:400;font-size:11px">v${esc(r.v)}</span>` : ''}` +
625
+ (r.t ? `<div class="sub">${esc(r.n)}</div>` : '') +
626
+ (!r.n ? '<div class="sub">只在 GitHub,没发到 npm</div>' : '') +
627
+ (r.d ? `<div class="sub desc" title="${esc(r.d)}">${esc(r.d)}</div>` : '') + `</td>`
628
+ const actions = r => `<td class="lks">${watchBtn(watchKey(r))}${linkBtns({ n: r.n || '', ghUrl: r.repo || '' }, { icon: true })}</td>`
629
+
630
+ if (board === 'official') {
631
+ const rows = data.rows.slice().sort((x, y) => (y.w || 0) - (x.w || 0))
632
+ $('#rankHead').innerHTML = '<tr><th style="width:44px">#</th><th>插件</th><th class="r">周下载</th><th></th></tr>'
633
+ $('#rankBody').innerHTML = rows.map((r, i) => `<tr><td style="color:var(--t3)">${i + 1}</td>${nameCell(r)}<td class="r"><b>${num(r.w)}</b></td>${actions(r)}</tr>`).join('')
634
+ return
635
+ }
636
+
637
+ const metric = document.querySelector(`#rankFilters .chip.on[data-board="${board}"]`).dataset.m
638
+ let rows = data.rows.filter(r => r[metric] != null)
639
+ .sort((x, y) => (y[metric] > x[metric] ? 1 : y[metric] < x[metric] ? -1 : 0))
640
+ // 按星标排时一个仓库只留一行(优先留发到 npm 的那条),不然同仓库的条目数字一样、刷屏
641
+ if (metric === 's') {
642
+ const best = new Map()
643
+ for (const r of rows) {
644
+ const k = (r.repo || r.name).toLowerCase()
645
+ if (!best.has(k) || (!best.get(k).n && r.n)) best.set(k, r)
646
+ }
647
+ const keep = new Set(best.values())
648
+ rows = rows.filter(r => keep.has(r))
649
+ }
650
+ rows = rows.slice(0, 40)
651
+ const hasDl = board === 'community'
652
+ $('#rankHead').innerHTML = '<tr><th style="width:44px">#</th><th>插件</th><th class="r">★ 星标</th>' +
653
+ (hasDl ? '<th class="r" title="近 30 天">下载</th>' : '') + '<th class="r">收录</th><th></th></tr>'
654
+ const strong = (on, t) => (on ? `<b>${t}</b>` : t)
655
+ $('#rankBody').innerHTML = rows.map((r, i) => `<tr><td style="color:var(--t3)">${i + 1}</td>${nameCell(r)}` +
656
+ `<td class="r">${strong(metric === 's', num(r.s))}</td>` +
657
+ (hasDl ? `<td class="r">${strong(metric === 'dl', num(r.dl))}</td>` : '') +
658
+ `<td class="r">${strong(metric === 'added', r.added ? esc(r.added.slice(5)) : '—')}</td>${actions(r)}</tr>`).join('')
659
+ }
660
+
574
661
  function renderRank() {
575
- const metric = document.querySelector('#rankFilters .chip.on').dataset.m
662
+ const board = rankBoard()
663
+ const onChip = document.querySelector(`#rankFilters .chip.on[data-board="${board}"]`)
664
+ const metric = onChip ? onChip.dataset.m : ''
576
665
  const cat = $('#rankCat').value
577
- const onlyDeep = metric !== 'w'
666
+ const inCat = r => !cat || r.cat === cat
667
+ const nameCell = r => `<td class="nm">${esc(r.n)} <span style="color:var(--t3);font-weight:400;font-size:11px">v${esc(r.v)}</span></td>`
668
+ const b = (on, text) => (on ? `<b>${text}</b>` : text)
669
+ // 分类是 npm 目录自己算的,别的榜没有这个字段
670
+ $('#rankCat').classList.toggle('hidden', board !== 'npm' && board !== 'gh')
671
+
672
+ if (board === 'official' || board === 'community' || board === 'shop') {
673
+ renderOuterBoard(board)
674
+ return
675
+ }
676
+
677
+ if (board === 'gh') {
678
+ $('#rankCap').textContent = '按 GitHub 仓库数据:星标看关注度,最近提交看还有没有人在维护。一个仓库只列一行;仓库填成 DSH 本体的不算。'
679
+ const val = r => metric === 'gs' ? r.gh.s
680
+ : metric === 'gf' ? r.gh.f
681
+ : metric === 'gi' ? r.gh.i
682
+ : -(daysSince(r.gh.p) ?? 1e9) // 最近提交:越近越前
683
+ // 按仓库排:一个仓库只占一行(好些作者把一串插件放在一个仓库里,数据都一样),
684
+ // 用这个仓库里周下载最多的那个插件代表,注明共用的个数
685
+ const byRepo = new Map()
686
+ for (const r of Object.values(CAT.packages)) {
687
+ if (!r.gh || !inCat(r)) continue
688
+ const k = r.gh.repo.toLowerCase()
689
+ const cur = byRepo.get(k)
690
+ if (!cur) byRepo.set(k, { r, n: 1 })
691
+ else { cur.n++; if (r.w > cur.r.w) cur.r = r }
692
+ }
693
+ const shared = new Map([...byRepo.values()].map(x => [x.r.n, x.n]))
694
+ const rows = [...byRepo.values()].map(x => x.r).sort((x, y) => val(y) - val(x)).slice(0, 40)
695
+ $('#rankHead').innerHTML = '<tr><th style="width:44px">#</th><th>插件</th><th>分类</th>' +
696
+ '<th class="r">★ 星标</th><th class="r">Fork</th><th class="r" title="未关闭的 issue 与 PR">讨论</th>' +
697
+ '<th class="r" title="仓库最近一次提交">最近提交</th><th></th></tr>'
698
+ $('#rankBody').innerHTML = rows.length ? rows.map((r, i) => {
699
+ const age = daysSince(r.gh.p)
700
+ return `<tr>` +
701
+ `<td style="color:var(--t3)">${i + 1}</td>` +
702
+ `<td class="nm">${esc(r.n)} <span style="color:var(--t3);font-weight:400;font-size:11px">v${esc(r.v)}</span>` +
703
+ (shared.get(r.n) > 1 ? `<div class="sub" title="仓库 ${esc(r.gh.repo)} 里有 ${shared.get(r.n)} 个插件,数据相同,只列一行">等 ${shared.get(r.n)} 个插件共用这个仓库</div>` : '') +
704
+ `</td>` +
705
+ `<td><span class="catpill">${esc(r.cat)}</span></td>` +
706
+ `<td class="r">${b(metric === 'gs', num(r.gh.s))}</td>` +
707
+ `<td class="r">${b(metric === 'gf', num(r.gh.f))}</td>` +
708
+ `<td class="r">${b(metric === 'gi', num(r.gh.i))}</td>` +
709
+ `<td class="r" title="${esc(r.gh.p || '')}">${r.gh.a ? '<span class="arch">已归档</span>' : `<span${age != null && age > 90 ? ' class="stale"' : ''}>${b(metric === 'gp', ageText(age))}</span>`}</td>` +
710
+ `<td class="lks">${watchBtn(r.n)}${linkBtns(r, { icon: true })}</td>` +
711
+ `</tr>`
712
+ }).join('') : '<tr><td colspan="8" class="empty">目录里还没有 GitHub 数据(每日更新取到后就有)。</td></tr>'
713
+ return
714
+ }
578
715
 
579
- let rows = Object.values(CAT.packages).filter(r => (!cat || r.cat === cat) && (!onlyDeep || r.deep))
716
+ $('#rankCap').textContent = '按 npm 下载数据:日常基线已扣掉发版拉取的虚高,最接近真实使用量;周下载含 CI、镜像流量。'
717
+ const onlyDeep = metric !== 'w'
580
718
  const val = r => metric === 'base' ? r.deep.base
581
719
  : metric === 'growth' ? (r.deep.growth === null ? -Infinity : r.deep.growth)
582
720
  : metric === 's' ? r.deep.s
583
721
  : r.w
584
- rows.sort((a, b) => val(b) - val(a))
585
- rows = rows.slice(0, 40)
586
-
722
+ const rows = Object.values(CAT.packages).filter(r => inCat(r) && (!onlyDeep || r.deep)).sort((x, y) => val(y) - val(x)).slice(0, 40)
723
+ $('#rankHead').innerHTML = '<tr><th style="width:44px">#</th><th>插件</th><th>分类</th>' +
724
+ `<th class="r">基线</th><th class="r">周下载</th><th class="r">环比</th>${metric === 's' ? '<th class="r">健康度</th>' : ''}` +
725
+ '<th class="r" title="最近一次发版 · 平均几天发一个版本">更新</th><th></th></tr>'
587
726
  $('#rankBody').innerHTML = rows.map((r, i) => {
588
727
  const d = r.deep
589
728
  const g = d ? d.growth : null
590
729
  return `<tr>` +
591
- `<td style="color:var(--t3)">${i + 1}</td>` +
592
- `<td class="nm">${esc(r.n)} <span style="color:var(--t3);font-weight:400;font-size:11px">v${esc(r.v)}</span></td>` +
730
+ `<td style="color:var(--t3)">${i + 1}</td>` + nameCell(r) +
593
731
  `<td><span class="catpill">${esc(r.cat)}</span></td>` +
594
- `<td class="r"><b>${num(val(r))}</b></td>` +
595
- `<td class="r">${num(r.w)}</td>` +
596
- `<td class="r ${g === null ? '' : (g >= 0 ? 'up' : 'down')}">${pct(g)}</td>` +
732
+ `<td class="r">${b(metric === 'base', d ? num(d.base) : '—')}</td>` +
733
+ `<td class="r">${b(metric === 'w', num(r.w))}</td>` +
734
+ `<td class="r ${g === null ? '' : (g >= 0 ? 'up' : 'down')}">${metric === 'growth' ? `<b>${pct(g)}</b>` : pct(g)}</td>` +
735
+ (metric === 's' ? `<td class="r"><b>${d ? d.s : '—'}</b></td>` : '') +
597
736
  maintCell(d) +
598
- `<td class="lks">${linkBtns(r, { icon: true })}</td>` +
737
+ `<td class="lks">${watchBtn(r.n)}${linkBtns(r, { icon: true })}</td>` +
599
738
  `</tr>`
600
739
  }).join('')
601
740
  }
@@ -606,6 +745,39 @@ function watch() {
606
745
  }
607
746
  function saveWatch(list) { localStorage.setItem(WATCH_KEY, JSON.stringify(list)) }
608
747
 
748
+ /** 监控列表里的名字:npm 包名;只在 GitHub 上的插件记成 gh:owner/repo */
749
+ function watchKey(r) {
750
+ if (r.n) return r.n
751
+ const m = /github\.com\/([^/]+\/[^/#]+)/.exec(r.repo || '')
752
+ return m ? 'gh:' + m[1] : ''
753
+ }
754
+
755
+ /** 彩色 + 号(已监控显示 ✓):点击由 document 上的委托统一处理 */
756
+ function watchBtn(key) {
757
+ if (!key) return ''
758
+ const on = watch().includes(key)
759
+ return `<button class="wadd${on ? ' on' : ''}" data-watch="${esc(key)}" title="${on ? '已在我的监控里,点一下移除' : '加入我的监控'}" aria-label="${on ? '移出我的监控' : '加入我的监控'}">${on ? '✓' : '+'}</button>`
760
+ }
761
+
762
+ function toggleWatch(key) {
763
+ const list = watch()
764
+ const on = list.includes(key)
765
+ if (!on && list.length >= 30) { toast('我的监控最多 30 个,先移除几个再加'); return }
766
+ saveWatch(on ? list.filter(x => x !== key) : [...list, key])
767
+ const now = !on
768
+ const shown = key.startsWith('gh:') ? key.slice(3) : key
769
+ toast(now ? `已加入我的监控:${shown}` : `已移出我的监控:${shown}`)
770
+ renderWatch()
771
+ // 同一个插件可能同时出现在搜索结果和排行榜里,一起更新
772
+ document.querySelectorAll('[data-watch]').forEach(b => {
773
+ if (b.dataset.watch !== key) return
774
+ b.classList.toggle('on', now)
775
+ b.textContent = now ? '✓' : '+'
776
+ b.title = now ? '已在我的监控里,点一下移除' : '加入我的监控'
777
+ b.setAttribute('aria-label', now ? '移出我的监控' : '加入我的监控')
778
+ })
779
+ }
780
+
609
781
  function addPickedToWatch() {
610
782
  const list = watch()
611
783
  for (const n of picked) if (!list.includes(n)) list.push(n)
@@ -625,6 +797,16 @@ let LIVE = (() => {
625
797
  * 否则用目录里的。目录里没有、也没刷新过的返回 null
626
798
  */
627
799
  function watchRec(n) {
800
+ // 只在 GitHub 上的插件(gh:owner/repo):从榜单里找它的信息,有实时数据就用实时的
801
+ if (n.startsWith('gh:')) {
802
+ const repo = n.slice(3)
803
+ const url = 'https://github.com/' + repo
804
+ const inBoard = ['community', 'shop'].flatMap(k => (CAT.boards && CAT.boards[k] && CAT.boards[k].rows) || [])
805
+ .find(r => r.repo && r.repo.toLowerCase() === url.toLowerCase())
806
+ const live = LIVE.rows[n]
807
+ const gh = live && live.found ? live.gh : (inBoard && inBoard.s != null ? { repo, s: inBoard.s, f: null, i: null, p: null, a: false } : null)
808
+ return { n: '', label: repo, cat: '只在 GitHub', w: null, m: null, deep: null, ghUrl: url, gh, live: Boolean(live && live.found) }
809
+ }
628
810
  const base = CAT.packages[n]
629
811
  const live = LIVE.rows[n]
630
812
  if (!live || !live.found) return base || null
@@ -635,7 +817,9 @@ function watchRec(n) {
635
817
  v: live.latest || (base && base.v),
636
818
  w: live.weekly,
637
819
  m: live.monthly,
638
- deep: d ? { base: d.baseline, growth: d.growth, cadence: d.cadence, age: d.ageDays, lastRelease: d.lastRelease, versions: d.versions, s: d.score } : null,
820
+ // npm 下载接口偶尔限流查不到:保留目录里的指标,别把有的数据冲掉
821
+ deep: d ? { base: d.baseline, growth: d.growth, cadence: d.cadence, age: d.ageDays, lastRelease: d.lastRelease, versions: d.versions, s: d.score } : (base && base.deep) || null,
822
+ gh: live.gh || (base && base.gh) || null,
639
823
  live: true,
640
824
  catalogW: base ? base.w : null,
641
825
  }
@@ -654,7 +838,10 @@ async function refreshWatch() {
654
838
  LIVE = { at: j.at, anchor: j.anchor, rows: Object.fromEntries(j.rows.map(x => [x.name, x])) }
655
839
  try { localStorage.setItem(LIVE_KEY, JSON.stringify(LIVE)) } catch { /* 存不下就只这次有效 */ }
656
840
  const miss = j.rows.filter(x => !x.found).map(x => x.name)
657
- toast(miss.length ? `已刷新;npm 上查不到:${miss.join('、')}` : `已刷新 ${j.rows.length} 个插件`)
841
+ toast([
842
+ miss.length ? `已刷新;npm 上查不到:${miss.join('、')}` : `已刷新 ${j.rows.length} 个插件`,
843
+ j.githubError ? `(${j.githubError})` : '',
844
+ ].join(''))
658
845
  } catch (e) {
659
846
  toast('刷新失败:' + e.message + '(检查网络后再试)')
660
847
  }
@@ -688,12 +875,13 @@ function renderWatch() {
688
875
  if (Math.abs(ch) >= 0.05) delta = `<span class="delta ${ch > 0 ? 'up' : 'down'}" title="和目录数据(截止 ${esc(CAT.anchor)})相比">${ch > 0 ? '↑' : '↓'}${Math.round(Math.abs(ch) * 100)}%</span>`
689
876
  }
690
877
  return `<div class="mon">` +
691
- `<span class="nm">${esc(n)}${r.v ? ` <span style="color:var(--t3);font-weight:400;font-size:11px">v${esc(r.v)}</span>` : ''}</span>` +
878
+ `<span class="nm">${esc(r.label || n)}${r.v ? ` <span style="color:var(--t3);font-weight:400;font-size:11px">v${esc(r.v)}</span>` : ''}</span>` +
692
879
  (r.live ? '<span class="live" title="刚从 npm 查的">实时</span>' : '') +
693
880
  `<span class="mrank">${rankText(r)}</span>` +
694
881
  `<span style="font-size:11.5px;color:var(--t3)">${esc(r.cat)}</span>` +
695
- `<span style="font-size:12px"><b>${num(r.w)}</b>/周${delta}</span>` +
696
- `<span style="font-size:12px;color:var(--t2)">基线 ${d ? num(d.base) : '—'}</span>` +
882
+ (r.w != null ? `<span style="font-size:12px"><b>${num(r.w)}</b>/周${delta}</span>` : '') +
883
+ (r.w != null ? `<span style="font-size:12px;color:var(--t2)">基线 ${d ? num(d.base) : '—'}</span>` : '') +
884
+ (r.gh ? `<span style="font-size:12px;color:var(--t2)" title="GitHub · 最近提交 ${esc(r.gh.p || '—')}">★ ${short(r.gh.s)}${r.gh.a ? ' · 已归档' : ''}</span>` : '') +
697
885
  `<span style="font-size:12px;color:var(--t2)">${d ? ageText(d.age) + '发版' : ''}</span>` +
698
886
  `<span class="mlinks">${linkBtns(r, { icon: true })}</span>` +
699
887
  `<button class="x" data-rm="${esc(n)}">×</button></div>`
@@ -703,7 +891,7 @@ function renderWatch() {
703
891
  b.addEventListener('click', () => saveWatch(watch().filter(x => x !== b.dataset.rm)) || renderWatch()))
704
892
 
705
893
  // 对数刻度横条图
706
- const rows = list.map(watchRec).filter(Boolean)
894
+ const rows = list.map(watchRec).filter(r => r && r.w != null)
707
895
  const max = Math.max(...rows.map(r => r.w), 1)
708
896
  $('#watchChart').innerHTML = rows.map((r, i) => {
709
897
  const w = Math.max(Math.log10(r.w + 1) / Math.log10(max + 1) * 100, 1.5)
@@ -746,7 +934,7 @@ ${ROWS.map(row => {
746
934
  }).join('')}
747
935
  </tbody></table>
748
936
  <h2>结论</h2>${verdicts}
749
- <div class="foot">数据来源 api.npmjs.org / registry.npmjs.org,截止 <b>${CAT.anchor}</b>(npm 统计滞后约 5 天)。
937
+ <div class="foot">数据来源 api.npmjs.org / registry.npmjs.org,截止 <b>${CAT.anchor}</b>(npm 最近有数据的一天)。
750
938
  下载量含 CI、镜像、爬虫等非人类流量,不等于用户数;<b>日常基线</b>=扣掉版本发布日与次日后的每日中位数。
751
939
  本页由 dsh-pick 面板导出。</div>
752
940
  </body></html>`