dsh-pick 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/boards.js CHANGED
@@ -4,7 +4,8 @@
4
4
  // community awesome-dsh-plugin 社区目录(dshmarket 用的也是它):有星标、30 天下载、收录日期
5
5
  // shop dsh-plugin-shop 的目录(第三方,不是 DeepSeek 官方):有星标、收录日期,没有下载量
6
6
  //
7
- // 每日构建时抓一次,只存每个榜的头部(整份目录有几十 MB,界面用不上)。这些都是别人维护的外部数据,
7
+ // 每日构建时抓一次,只存每个榜的头部(整份目录十几 MB,界面用不上);社区目录里的 npm 包名另外补进
8
+ // npm 目录(见 engine.js 的 addCommunity),让搜索和 npm 榜也能找到。这些都是别人维护的外部数据,
8
9
  // 所以只摘需要的字段、校验类型和链接;官方包只按文本解析,绝不执行从网上下载的代码。
9
10
 
10
11
  const OFFICIAL_JS = 'https://cdn.jsdelivr.net/npm/@deepseek-ai/dsh-official-bundles@latest/lib/index.js'
@@ -17,9 +18,9 @@ const TOP = 100
17
18
  const text = (v, max = 120) => (typeof v === 'string' ? v.trim().slice(0, max) : '')
18
19
  const count = v => (Number.isFinite(v) && v >= 0 ? v : null)
19
20
  const date = v => (/^\d{4}-\d{2}-\d{2}/.test(String(v || '')) ? String(v).slice(0, 10) : null)
20
- const npmName = v => (typeof v === 'string' && /^(@[a-z0-9._-]+\/)?[a-z0-9._-]+$/i.test(v) ? v : null)
21
+ export const npmName = v => (typeof v === 'string' && /^(@[a-z0-9._-]+\/)?[a-z0-9._-]+$/i.test(v) ? v : null)
21
22
  /** 只留 https 的代码托管地址:链接要放进页面,别的协议和站点一律不要 */
22
- const repoUrl = v => {
23
+ export const repoUrl = v => {
23
24
  const m = /^https:\/\/(github\.com|gitlab\.com)\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+/.exec(String(v || ''))
24
25
  return m ? m[0].replace(/\.git$/, '') : null
25
26
  }
@@ -79,6 +80,23 @@ export function communityBoard(doc) {
79
80
  return { total: rows.length, updated: date(doc && doc.updated), rows: topRows(rows, ['s', 'dl', 'added']) }
80
81
  }
81
82
 
83
+ /**
84
+ * 社区目录 → 补进 npm 目录的包:校验包名、去重,只摘补记录要用的字段
85
+ * @returns {{n: string, m: number|null, repo: string|null}[]} n 包名 · m 30 天下载(和搜索接口的月下载基本一致)· repo 仓库
86
+ */
87
+ export function communityPackages(doc) {
88
+ const list = doc && Array.isArray(doc.plugins) ? doc.plugins : []
89
+ const out = new Map()
90
+ for (const p of list) {
91
+ const n = npmName(p && p.npm)
92
+ if (n && !out.has(n)) out.set(n, { n, m: count(p.downloads), repo: repoUrl(p.url) })
93
+ }
94
+ return [...out.values()]
95
+ }
96
+
97
+ /** 下载社区目录(约 12 MB)。构建时只下一次,补目录和社区榜共用 */
98
+ export const loadCommunity = (fetchImpl = globalThis.fetch) => getJson(fetchImpl, COMMUNITY_URL, 180000)
99
+
82
100
  /** 插件商店的目录 + 星标表 → 榜单。星标表按 owner/repo 或包名记 */
83
101
  export function shopBoard(plugins, stars) {
84
102
  const list = Array.isArray(plugins) ? plugins : (plugins && plugins.plugins) || []
@@ -135,11 +153,12 @@ async function loadShop(fetchImpl) {
135
153
  * 抓全部榜单。某个来源这次抓不到,就沿用上次的那份,不让一个榜拖垮整个构建
136
154
  * @param {object} [opt]
137
155
  * @param {object} [opt.previous] 上一次的 boards
156
+ * @param {object} [opt.communityDoc] 已经下载好的社区目录,有就不再下一次
138
157
  */
139
- export async function buildBoards({ fetchImpl = globalThis.fetch, previous = {}, onProgress = () => {} } = {}) {
158
+ export async function buildBoards({ fetchImpl = globalThis.fetch, previous = {}, communityDoc = null, onProgress = () => {} } = {}) {
140
159
  const sources = {
141
160
  official: () => loadOfficial(fetchImpl),
142
- community: async () => communityBoard(await getJson(fetchImpl, COMMUNITY_URL, 180000)),
161
+ community: async () => communityBoard(communityDoc || await loadCommunity(fetchImpl)),
143
162
  shop: () => loadShop(fetchImpl),
144
163
  }
145
164
  const boards = {}
package/lib/engine.js CHANGED
@@ -13,7 +13,7 @@ import { classify } from './classify.js'
13
13
  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
- import { buildBoards } from './boards.js'
16
+ import { buildBoards, communityPackages, loadCommunity, repoUrl } from './boards.js'
17
17
 
18
18
  const PKG_ROOT = fileURLToPath(new URL('..', import.meta.url))
19
19
  /** 随包自带的目录(发版时的快照;dsh-pick build 也写这里) */
@@ -112,7 +112,7 @@ export const maskGaps = (daily, gaps) => daily.map((v, i) => (gaps.has(i) ? null
112
112
  * 抓取 DSH 插件目录
113
113
  * @param {object} opt
114
114
  * @param {number} opt.deep 对周下载 Top N 抓日序列 + 发布历史,算出噪指标
115
- * @param {number} opt.max 最多抓多少个包(search 深分页上限约 2250)
115
+ * @param {number} opt.max 搜索接口最多抓多少个包(深分页上限约 2250;社区目录补进来的不算)
116
116
  * @param {boolean} opt.deepOnly 只补算去噪指标,不重新抓目录(省 5 分钟)
117
117
  * @param {(msg:string)=>void} opt.onProgress 进度回调
118
118
  */
@@ -125,6 +125,8 @@ export async function buildCatalog({ deep = 200, max = 2250, pages = 9, deepOnly
125
125
  onProgress(`统计截止日 ${anchor}${gapDates.length ? `;npm 缺 ${gapDates.join('、')} 的数据,这几天不参与计算` : ''},${deepOnly ? '只补算去噪指标' : '开始抓取目录'}…`)
126
126
 
127
127
  const records = new Map()
128
+ const previous = await readJson(CATALOG_PATH)
129
+ let communityDoc = null
128
130
 
129
131
  if (deepOnly) {
130
132
  const prev = await loadCatalog()
@@ -157,6 +159,17 @@ export async function buildCatalog({ deep = 200, max = 2250, pages = 9, deepOnly
157
159
  if (objs.length < 250) break
158
160
  await sleep(220)
159
161
  }
162
+
163
+ // 搜索接口翻不到的,用社区目录补。社区目录抓不到就沿用上次目录里的包,不让总数一天掉一半
164
+ try {
165
+ communityDoc = await loadCommunity()
166
+ } catch (e) {
167
+ onProgress(`社区目录抓不到(${e.message}),沿用上次目录里的包`)
168
+ }
169
+ const rows = communityDoc
170
+ ? communityPackages(communityDoc)
171
+ : Object.values((previous && previous.packages) || {}).map(r => ({ n: r.n, m: r.m, repo: repoUrl(r.repo) }))
172
+ await addCommunity(records, rows, { previous: previous && previous.packages, onProgress })
160
173
  }
161
174
 
162
175
  // 分类:**全部**目录都要有(v1 只给深挖目标分了类,导致其余全是 undefined)
@@ -167,6 +180,7 @@ export async function buildCatalog({ deep = 200, max = 2250, pages = 9, deepOnly
167
180
  onProgress(`目录 ${records.size} 个包已分类,开始算去噪指标 Top ${deep}…`)
168
181
 
169
182
  // 深挖:日序列 + 发布历史 → 日常基线 / 增速 / 版本节奏 / 新鲜度
183
+ // 范围不随目录变大:多出来的包大多下载量很小,而且下载量接口经不起更多请求
170
184
  // 注意:api.npmjs.org 并发稍高就开始 429,所以下载量请求必须低并发;
171
185
  // registry.npmjs.org 宽松得多,可以并发。两段分开抓。
172
186
  // deepOnly 时只补缺失的;全量时按周下载取 Top N
@@ -232,7 +246,8 @@ export async function buildCatalog({ deep = 200, max = 2250, pages = 9, deepOnly
232
246
  // dsh.bundle 有没有声明(没有的话 dsh plugin add 直接拒绝安装)、
233
247
  // 客户端平台(web / tui)、声明的 DSH 版本要求(engines.dsh 与 @deepseek-ai/dsh* 的 peer)
234
248
  // registry 的单版本 manifest 很宽松,可以并发
235
- const needFacts = [...records.values()].filter(r => !(deepOnly && r.inst))
249
+ // 已经有的不再抓:deepOnly 沿用的,和社区目录补进来时读过 manifest 的
250
+ const needFacts = [...records.values()].filter(r => !r.inst)
236
251
  onProgress(`安装信息 ${needFacts.length} 个…`)
237
252
  const manifests = await pool(needFacts, 8, rec => jget(`${REG_API}/${enc(rec.n)}/latest`, 2))
238
253
  needFacts.forEach((rec, i) => { if (manifests[i]) rec.inst = installFacts(manifests[i]) })
@@ -260,8 +275,9 @@ export async function buildCatalog({ deep = 200, max = 2250, pages = 9, deepOnly
260
275
 
261
276
  // npm、GitHub 之外的榜单:官方、社区、插件商店(抓不到的沿用上次)
262
277
  onProgress('其他榜单…')
263
- const previous = await readJson(CATALOG_PATH)
264
- const boards = await buildBoards({ previous: previous && previous.boards, onProgress })
278
+ const boards = await buildBoards({ previous: previous && previous.boards, communityDoc, onProgress })
279
+
280
+ for (const rec of records.values()) slimRecord(rec)
265
281
 
266
282
  const catalog = {
267
283
  tool: 'dsh-pick',
@@ -283,7 +299,140 @@ export async function buildCatalog({ deep = 200, max = 2250, pages = 9, deepOnly
283
299
  }
284
300
 
285
301
  /**
286
- * 从 npm manifest 里摘出安装相关的三件事(字段名短:2,250 个包都要存)
302
+ * 把社区目录里有、搜索接口翻不到的包补进 records。
303
+ * 每个包都读一次 npm 上的 manifest:社区目录可能过时或写错,npm 上查不到(或名字对不上)的不收。
304
+ * @param {Map<string, object>} records 会就地补充
305
+ * @param {{n: string, m?: number|null, repo?: string|null}[]} rows 包名已校验(communityPackages)
306
+ * @param {object} [opt]
307
+ * @param {Record<string, object>} [opt.previous] 上次目录的 packages:没轮到或查不到周下载时沿用
308
+ * @param {string} [opt.today] YYYY-MM-DD,决定今天轮到哪些带 scope 的包(见 weeklyDue)
309
+ * @returns {Promise<number>} 补进去几个
310
+ */
311
+ export async function addCommunity(records, rows, { previous = {}, today = new Date().toISOString().slice(0, 10), onProgress = () => {} } = {}) {
312
+ const missing = rows.filter(r => !records.has(r.n))
313
+ onProgress(`社区目录 ${rows.length} 个 npm 包,其中 ${missing.length} 个搜索接口没翻到,逐个读 manifest…`)
314
+ const manifests = await pool(missing, 8, r => jget(`${REG_API}/${enc(r.n)}/latest`))
315
+ const added = missing
316
+ .map((row, i) => communityRecord(row, manifests[i]))
317
+ .filter(Boolean)
318
+ if (added.length < missing.length) onProgress(` ${missing.length - added.length} 个在 npm 上查不到,不收`)
319
+
320
+ // 不带 scope 的批量查,每天全查;带 scope 的只能逐个查,下载量接口经不起(几百个包在 Actions 上要排队二十多分钟),
321
+ // 所以每天只查轮到的那组和上次没有数的,其余沿用上次的
322
+ const prevW = n => previous?.[n]?.w
323
+ const due = added.filter(r => !r.n.startsWith('@') || prevW(r.n) == null || weeklyDue(r.n, today))
324
+ onProgress(` 周下载 ${due.length} 个(带 scope 的 ${added.length - due.length} 个今天没轮到,沿用上次的)…`)
325
+ const weekly = await fetchWeekly(due.map(r => r.n), onProgress)
326
+ let stale = 0
327
+ for (const rec of added) {
328
+ const known = weekly.get(rec.n)
329
+ if (known == null && due.includes(rec)) stale++
330
+ rec.w = known ?? prevW(rec.n) ?? 0
331
+ // 两个数据来源的统计窗口差几天,别出现月下载比周下载还少
332
+ rec.m = Math.max(rec.m, rec.w)
333
+ records.set(rec.n, rec)
334
+ }
335
+ if (stale) onProgress(` ${stale} 个查不到周下载,沿用上次的数(没有就记 0)`)
336
+ return added.length
337
+ }
338
+
339
+ /** 社区目录的一行 + npm manifest → 目录记录(周下载另外填)。manifest 不对劲返回 null */
340
+ export function communityRecord(row, manifest) {
341
+ if (!manifest || manifest.name !== row.n) return null
342
+ const repository = manifest.repository
343
+ const repoText = typeof repository === 'string' ? repository : (repository && repository.url) || ''
344
+ return {
345
+ n: row.n,
346
+ v: str(manifest.version),
347
+ d: str(manifest.description).slice(0, 160),
348
+ kw: Array.isArray(manifest.keywords) ? manifest.keywords.filter(k => typeof k === 'string') : [],
349
+ w: 0,
350
+ m: row.m || 0,
351
+ home: /^https?:\/\//.test(str(manifest.homepage)) ? manifest.homepage : '',
352
+ // 社区目录的地址校验过(https、代码托管站),优先用它;monorepo 子目录也已截到仓库根
353
+ repo: row.repo || str(repoText),
354
+ inst: installFacts(manifest),
355
+ }
356
+ }
357
+
358
+ const str = v => (typeof v === 'string' ? v : '')
359
+
360
+ /**
361
+ * 查一批包的周下载。不带 scope 的走批量接口(一次最多 128 个,几十次请求就完);带 scope 的 npm 不支持批量,
362
+ * 只能一个个查,所以低并发(同去噪指标,稍高就 429),最后一轮降到并发 1。
363
+ * 这个接口的数和搜索接口的周下载基本一致(实测中位数差 4%)。
364
+ * (试过用搜索接口按包名查带 scope 的:连查一百来个也开始限流,并不更宽松)
365
+ * @returns {Promise<Map<string, number>>} 查不到的不在里面
366
+ */
367
+ async function fetchWeekly(names, onProgress = () => {}) {
368
+ const out = new Map()
369
+ const url = name => `${DL_API}/point/last-week/${name}`
370
+ const bare = names.filter(n => !n.startsWith('@'))
371
+ for (let i = 0; i < bare.length; i += 128) {
372
+ const batch = bare.slice(i, i + 128)
373
+ if (batch.length < 2) break // 只查一个时返回的形状不一样,交给下面逐个查
374
+ const d = await jget(url(batch.join(',')))
375
+ for (const n of batch) {
376
+ const v = d && d[n] && d[n].downloads
377
+ if (Number.isFinite(v)) out.set(n, v)
378
+ }
379
+ await sleep(180)
380
+ }
381
+ let pending = names.filter(n => !out.has(n))
382
+ for (let round = 1; round <= 2 && pending.length; round++) {
383
+ onProgress(` 逐个查周下载 第 ${round} 轮,${pending.length} 个…`)
384
+ await pool(pending, round === 1 ? 2 : 1, async n => {
385
+ const d = await jget(url(enc(n)))
386
+ if (d && Number.isFinite(d.downloads)) out.set(n, d.downloads)
387
+ await sleep(round === 1 ? 180 : 420)
388
+ })
389
+ pending = pending.filter(n => !out.has(n))
390
+ }
391
+ return out
392
+ }
393
+
394
+ /** 带 scope 的包分几天轮着查周下载 */
395
+ export const WEEKLY_ROTATION = 3
396
+
397
+ /**
398
+ * 这个带 scope 的包今天轮不轮到查周下载:按包名分进 WEEKLY_ROTATION 组,一天查一组。
399
+ * 不记状态,每个包固定每隔 WEEKLY_ROTATION 天刷新一次
400
+ */
401
+ export function weeklyDue(name, today) {
402
+ let h = 0
403
+ for (const ch of name) h = (h * 31 + ch.codePointAt(0)) >>> 0
404
+ const day = Math.floor(Date.parse(today + 'T00:00:00Z') / 86400000)
405
+ return h % WEEKLY_ROTATION === day % WEEKLY_ROTATION
406
+ }
407
+
408
+ /** 几乎每个包都有的关键字:搜索时没有区分度,存着还白占地方 */
409
+ const GENERIC_KW = new Set(['dsh-plugin', 'dsh-plugins', 'dsh', 'deepseek-harness'])
410
+
411
+ /**
412
+ * 落盘前瘦身(五千多个包,每个省几十字节就是几百 KB)。只去掉读的一方用不上的:
413
+ * pub / rel 发布日期(算完去噪指标就没用了)· home 已有 GitHub 仓库地址时的主页(只用来找仓库)
414
+ * repo 的 git+ 和 .git · 没有区分度的关键字,关键字最多留 12 个 · inst、gh 里的空值(读的时候都只判真假)
415
+ */
416
+ export function slimRecord(rec) {
417
+ delete rec.pub
418
+ delete rec.rel
419
+ if (rec.repo) rec.repo = rec.repo.replace(/^git\+/, '').replace(/\.git$/, '')
420
+ if (!rec.home || (/^https?:\/\//.test(rec.repo || '') && parseRepo(rec.repo))) delete rec.home
421
+ if (!rec.repo) delete rec.repo
422
+ rec.kw = (rec.kw || []).filter(k => !GENERIC_KW.has(String(k).toLowerCase())).slice(0, 12)
423
+ if (rec.inst) {
424
+ if (rec.inst.p == null) delete rec.inst.p
425
+ if (rec.inst.r == null) delete rec.inst.r
426
+ }
427
+ if (rec.gh) {
428
+ if (!rec.gh.a) delete rec.gh.a
429
+ if (rec.gh.l == null) delete rec.gh.l
430
+ }
431
+ return rec
432
+ }
433
+
434
+ /**
435
+ * 从 npm manifest 里摘出安装相关的三件事(字段名短:几千个包都要存)
287
436
  * b 有没有 dsh.bundle 声明 · p 客户端平台 · r 声明的 DSH 版本要求(可能为 null)
288
437
  * 版本要求的读法照 dshmarket:engines.dsh 与 dsh.engines.dsh 都认,peer 只看 @deepseek-ai/dsh*
289
438
  * (cordis、schemastery 不跟 DSH 版本走)
@@ -340,7 +489,7 @@ export function reloadCatalog(cat) {
340
489
 
341
490
  /**
342
491
  * 归一化:补上 npm 地址、GitHub 地址、总排行、分类排行
343
- * 排名字段不落盘,加载时算一次(2,250 个包一次排序,毫秒级),
492
+ * 排名字段不落盘,加载时算一次(几千个包一次排序,毫秒级),
344
493
  * 这样 catalog.json 重建与否都不影响排名显示。
345
494
  */
346
495
  export function normalize(cat) {
package/lib/github.js CHANGED
@@ -4,11 +4,11 @@
4
4
  // 最近一次提交、是不是已经归档。两边合起来判断才靠谱。
5
5
  //
6
6
  // 两种取法:
7
- // - 每日构建(GitHub Actions):GraphQL 一次查 50 个仓库,2,000 个仓库几十次请求就完。要令牌:
7
+ // - 每日构建(GitHub Actions):GraphQL 一次查 50 个仓库,五千个仓库一百来次请求就完。要令牌:
8
8
  // Actions 里自带的 GITHUB_TOKEN 就够;本地 build 没设 GITHUB_TOKEN 就跳过这一步
9
9
  // - 「我的监控」刷新:REST 逐个查,不用令牌(每小时 60 次,监控列表最多 30 个,够用)
10
10
  //
11
- // 存进目录的字段名短(2,000 多个包都要存):
11
+ // 存进目录的字段名短(五千多个包都要存):
12
12
  // s 星标 · f Fork · i 未关闭的 issue + PR · p 最近一次提交(YYYY-MM-DD)· a 已归档 · l 许可证 · repo owner/name
13
13
 
14
14
  const GRAPHQL = 'https://api.github.com/graphql'
package/lib/remote.js CHANGED
@@ -2,7 +2,7 @@
2
2
  //
3
3
  // GitHub Actions 每天跑一次 dsh-pick build,把 catalog.json 和一个很小的 meta.json 推到本仓库的
4
4
  // catalog 分支(.github/workflows/catalog.yml)。插件在 DSH 里启动时、之后每 6 小时问一次:
5
- // 先取 meta.json 比新旧,真有更新才下载完整目录(约 1.5 MB),校验后原子写进 ~/.dsh/dsh-pick/,
5
+ // 先取 meta.json 比新旧,真有更新才下载完整目录(约 3 MB,gzip 后约 0.9 MB),校验后原子写进 ~/.dsh/dsh-pick/,
6
6
  // 再换上新目录。取不到(没网、被墙)就继续用手上的,什么都不报——随包自带的那份永远兜底。
7
7
  //
8
8
  // 镜像按顺序试:jsDelivr 国内一般能直连;raw.githubusercontent.com 兜底。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-pick",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "帮你在 DSH 生态里选对插件:说需求 → 找候选 → 多维比较 → 出结论。下载量是证据,AI 是推理。",
5
5
  "repository": {
6
6
  "type": "git",
package/plugin/client.js CHANGED
@@ -89,12 +89,20 @@ window.__ModuleLoader__.load({
89
89
  h(Btn, { onClick: copy }, copied ? L('已复制', 'Copied') : L('复制', 'Copy')))
90
90
  }
91
91
 
92
+ /** 更新成功后按钮上的字:只有 updateBundle 明说不用重启(restart: false)才算已生效;老版 DSH 走 installBundle,答复里没有这个字段,照旧提示重启 */
93
+ function updatedLabel(j) {
94
+ return j && j.restart === false
95
+ ? L(`已更新到 v${j.version}`, `Updated to v${j.version}`)
96
+ : L('已更新,重启 DSH 生效', 'Updated; restart DSH')
97
+ }
98
+
92
99
  /** 标题行:dsh-pick · 版本号 · 更新 ……(最右)卸载 */
93
100
  function HeaderBar() {
94
101
  const [info, setInfo] = useState(null)
95
102
  const [phase, setPhase] = useState('checking') // checking | idle | updating | updated | removing | removed
96
103
  const [confirm, setConfirm] = useState(false)
97
104
  const [msg, setMsg] = useState(null) // { text, command? }
105
+ const [updated, setUpdated] = useState(null) // 更新成功的答复 { version, restart? }
98
106
 
99
107
  const check = (force) => {
100
108
  setPhase('checking')
@@ -108,7 +116,7 @@ window.__ModuleLoader__.load({
108
116
  setPhase('updating'); setMsg(null)
109
117
  try {
110
118
  const j = await api('update', 'POST')
111
- if (j.ok) { setPhase('updated'); return }
119
+ if (j.ok) { setUpdated(j); setPhase('updated'); return }
112
120
  setMsg({ text: j.message, command: j.command })
113
121
  } catch (e) {
114
122
  setMsg({ text: L('更新请求失败:', 'Update failed: ') + e.message })
@@ -131,7 +139,7 @@ window.__ModuleLoader__.load({
131
139
 
132
140
  let upd
133
141
  if (phase === 'updating') upd = { label: L('正在更新…', 'Updating…'), disabled: true }
134
- else if (phase === 'updated') upd = { label: L('已更新,重启 DSH 生效', 'Updated; restart DSH'), disabled: true }
142
+ else if (phase === 'updated') upd = { label: updatedLabel(updated), disabled: true }
135
143
  else if (info && info.restartPending) upd = { label: L(`v${info.restartPending} 已装好,重启 DSH 生效`, `v${info.restartPending} installed; restart DSH`), disabled: true }
136
144
  else if (info && info.available) upd = { label: L(`更新到 v${info.latest}`, `Update to v${info.latest}`), primary: true, onClick: update }
137
145
  else if (phase === 'checking') upd = { label: L('检查更新…', 'Checking…'), disabled: true }
@@ -387,7 +395,7 @@ window.__ModuleLoader__.load({
387
395
  }
388
396
 
389
397
  // 给测试用的内部句柄(浏览器里没人碰它)
390
- module.exports = { name: 'dsh-pick', inject: injectSlots, apply, __test: { sendToChat } }
398
+ module.exports = { name: 'dsh-pick', inject: injectSlots, apply, __test: { sendToChat, updatedLabel } }
391
399
  return module.exports
392
400
  },
393
401
  })
package/plugin/index.js CHANGED
@@ -11,7 +11,7 @@
11
11
  // GET /api-dsh-pick/catalog.json 目录(含排名、链接、去噪指标)
12
12
  // GET /api-dsh-pick/meta 目录概要(更新时间、包数、来源)
13
13
  // GET /api-dsh-pick/update 本插件版本 + npm 上的最新版本
14
- // POST /api-dsh-pick/update 更新到 npm 最新版(交给 DSH 的插件管理器)
14
+ // POST /api-dsh-pick/update 更新到 npm 最新版(交给 DSH 的插件管理器,优先用 updateBundle)
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 个)
@@ -126,6 +126,38 @@ function managerError(result) {
126
126
  return detail ? `${code}:${detail}` : code
127
127
  }
128
128
 
129
+ /** 这个 DSH 能不能在运行中更新插件:新版有 updateBundle,老版只有 installBundle(还不一定成,见上) */
130
+ function canUpdateHere(pluginManager) {
131
+ return Boolean(pluginManager && (typeof pluginManager.updateBundle === 'function' || typeof pluginManager.installBundle === 'function'))
132
+ }
133
+
134
+ /**
135
+ * 新版 DSH 的 updateBundle 答复 → 给面板的答复。答复的结构见官方仓库 packages/boot/plugin-manager:
136
+ * { from, to, step: 'check' | 'remove' | 'install', result: ChangeResult, restore?: ChangeResult }
137
+ * result 是最后跑的那一步;restore 只在「旧版已卸、新版没装成」时才有,是把旧版装回去的结果。
138
+ */
139
+ function updateReply(update, latest, command) {
140
+ const change = update && update.result
141
+ if (!change) return { ok: false, message: '更新失败(DSH 没有给出结果)', command }
142
+ const err = managerError(change)
143
+ if (!err) {
144
+ // pnpm 的 minimumReleaseAge 可能让实际装上的比 npm 最新版旧,以 DSH 报的版本为准
145
+ return { ok: true, version: change.version || latest, restart: change.application === 'restart-required' }
146
+ }
147
+ const retry = '也可以完全退出 DSH,在终端执行下面的命令'
148
+ if (update.step === 'check') {
149
+ // 这个新版要求更高版本的 DSH,命令行也装不上,就不给命令了
150
+ if (managerCode(change) === 'incompatible-version') return { ok: false, message: `v${latest} 和这个版本的 DSH 不兼容,先升级 DSH 再更新` }
151
+ return { ok: false, message: `更新被拒绝,什么都没改(${err})。${retry}`, command }
152
+ }
153
+ if (update.step === 'remove') return { ok: false, message: `卸载旧版 v${update.from} 失败,没有更新(${err})。${retry}`, command }
154
+ if (!update.restore) return { ok: false, message: `更新失败,还是 v${update.from}(${err})。${retry}`, command }
155
+ if (managerError(update.restore)) {
156
+ return { ok: false, message: `更新失败(${err}),旧版 v${update.from} 也没能装回去,dsh-pick 现在已经不在了。请完全退出 DSH,在终端执行下面的命令重新安装`, command }
157
+ }
158
+ return { ok: false, message: `更新失败,已经装回旧版 v${update.from}(${err})。${retry}`, command }
159
+ }
160
+
129
161
  /** 读请求体里的 JSON(最多 16 KB,这里只收很小的参数) */
130
162
  function readJsonBody(req) {
131
163
  return new Promise((resolve) => {
@@ -305,7 +337,7 @@ export function apply(ctx) {
305
337
  restartPending: installed && running && compareVersions(installed, running) > 0 ? installed : '',
306
338
  latest,
307
339
  available: Boolean(latest) && compareVersions(latest, current) > 0,
308
- canInstall: Boolean(pluginManager && typeof pluginManager.installBundle === 'function'),
340
+ canInstall: canUpdateHere(pluginManager),
309
341
  command: pluginCommand(`add ${PACKAGE}@${latest || 'latest'}`, profile),
310
342
  })
311
343
  }
@@ -314,6 +346,14 @@ export function apply(ctx) {
314
346
  const command = pluginCommand(`add ${PACKAGE}@${latest || 'latest'}`, profile)
315
347
  if (!latest) return sendJson(res, 200, { ok: false, message: '查不到 npm 上的最新版本,检查网络后再试', command })
316
348
  if (compareVersions(latest, running) <= 0) return sendJson(res, 200, { ok: false, message: `已经是最新版 v${running}` })
349
+ // 新版 DSH 有专门的 updateBundle,能在运行中直接更新
350
+ if (pluginManager && typeof pluginManager.updateBundle === 'function') {
351
+ try {
352
+ return sendJson(res, 200, updateReply(await pluginManager.updateBundle(PACKAGE, latest), latest, command))
353
+ } catch (e) {
354
+ return sendJson(res, 200, { ok: false, message: `更新失败:${e.message}`, command })
355
+ }
356
+ }
317
357
  if (!pluginManager || typeof pluginManager.installBundle !== 'function') {
318
358
  return sendJson(res, 200, { ok: false, message: '这个版本的 DSH 不能在这里装插件,请在终端执行命令', command })
319
359
  }
package/web/panel.html CHANGED
@@ -118,9 +118,8 @@ table.rank td .arch{font-size:10.5px;color:var(--t3);background:var(--soft);bord
118
118
  .section h2 .h2-acts{margin-left:auto;display:inline-flex;gap:8px;align-items:center}
119
119
  .section h2 .h2-acts .ai{margin-left:0}
120
120
  .btn.sm{font-size:11.5px;padding:0 10px;height:24px;border-radius:7px}
121
- .mon .live{font-size:10px;color:var(--ok-text);background:var(--ok-bg);border-radius:5px;padding:1px 5px;white-space:nowrap}
122
- .mon .delta{font-size:10.5px;margin-left:3px}
123
- .mon .delta.up{color:var(--ok)}.mon .delta.down{color:var(--bad)}
121
+ .mrow .delta{font-size:10.5px;margin-left:3px}
122
+ .mrow .delta.up{color:var(--ok)}.mrow .delta.down{color:var(--bad)}
124
123
  #watchAsOf b{color:var(--t2);font-weight:600}
125
124
  .inst{appearance:none;font-family:inherit;font-size:10.5px;font-weight:600;border-radius:6px;padding:2px 9px;cursor:pointer;
126
125
  border:1px solid var(--accent);background:var(--panel);color:var(--accent);white-space:nowrap}
@@ -228,14 +227,24 @@ td.down{color:var(--bad);font-weight:600}
228
227
  .catpill{font-size:10.5px;background:var(--soft);color:var(--t2);border-radius:20px;padding:2px 8px;white-space:nowrap}
229
228
 
230
229
  /* ---------- 监控 ---------- */
231
- .mon{display:flex;align-items:center;gap:12px;padding:11px 0;border-bottom:1px solid var(--soft);flex-wrap:wrap}
232
- .mon:last-child{border-bottom:none}
233
- .mon .nm{font-size:13px;font-weight:650;flex:1;min-width:150px}
234
- .mon .mrank{font-size:10.5px;color:var(--t3);font-variant-numeric:tabular-nums}
235
- .mon .mrank b{color:var(--t2);font-weight:700}
236
- .mon .mlinks{display:flex;gap:5px}
237
- .mon .x{appearance:none;border:none;background:none;color:var(--t3);cursor:pointer;font-size:16px;padding:0 4px}
238
- .mon .x:hover{color:var(--bad)}
230
+ /* 我的监控:和排行榜一样一行一个插件,上面是列名。名字和最后的图标宽度固定,
231
+ 中间各列用 minmax(0, 1fr) 平分剩下的宽度,栏变窄时一起压缩,放不下的用省略号 */
232
+ /* 数字列留够短写数字(312k、#3088)的最小宽度,不会被截断;压缩主要由「分类」承担 */
233
+ #watchList{--mcols:minmax(84px,3.4fr) minmax(36px,.7fr) minmax(0,1.2fr) minmax(40px,.9fr) minmax(32px,.8fr) minmax(30px,.7fr) minmax(36px,.8fr) auto}
234
+ .mrow{display:grid;grid-template-columns:var(--mcols);align-items:center;column-gap:6px;padding:8px 0;border-bottom:1px solid var(--soft);font-size:12px;color:var(--t2)}
235
+ .mrow:last-child{border-bottom:none}
236
+ .mrow.mhead{font-size:11px;color:var(--t3);font-weight:600;padding:0 0 7px;border-bottom:1px solid var(--line)}
237
+ .mrow .mc{min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-variant-numeric:tabular-nums}
238
+ .mrow .mc.r{text-align:right}
239
+ .mrow .mc.span{grid-column:2 / -2;color:var(--t3)}
240
+ .mrow .mc b{color:var(--text);font-weight:650}
241
+ .mrow .nm{font-size:13px;font-weight:650;color:var(--text)}
242
+ .mrow.mhead .nm{font-size:11px;font-weight:600;color:var(--t3)}
243
+ .mrow .ver{color:var(--t3);font-weight:400;font-size:11px}
244
+ .mrow .acts{display:flex;align-items:center;justify-content:flex-end;overflow:visible}
245
+ .mrow .livedot{display:inline-block;width:6px;height:6px;border-radius:50%;background:var(--ok);margin-right:5px;vertical-align:middle}
246
+ .mrow .x{appearance:none;border:none;background:none;color:var(--t3);cursor:pointer;font-size:16px;line-height:1;padding:0 2px 0 4px;flex:none}
247
+ .mrow .x:hover{color:var(--bad)}
239
248
 
240
249
  .foot{font-size:11.5px;color:var(--t3);line-height:1.9;margin-top:6px}
241
250
  .foot b{color:var(--t2);font-weight:650}
package/web/panel.js CHANGED
@@ -864,27 +864,38 @@ function renderWatch() {
864
864
  return
865
865
  }
866
866
 
867
- host.innerHTML = list.map(n => {
867
+ // 像排行榜一样:上面一行是列名,每个插件一行。名字在最前、图标和移除在最后,
868
+ // 中间各列始终都在,右侧栏变窄时一起按比例压缩(放不下的用省略号,悬停看全文)
869
+ const cell = (text, title, cls = '') => `<span class="mc${cls ? ' ' + cls : ''}" title="${esc(title)}">${text}</span>`
870
+ const head = '<div class="mrow mhead">' +
871
+ '<span class="mc nm">插件</span>' +
872
+ [['总榜', 'r', '总榜排名'], ['分类', '', '分类'], ['周下载', 'r', '周下载'], ['基线', 'r', '日常基线'], ['★', 'r', 'GitHub 星标'], ['发版', 'r', '最近一次发版']]
873
+ .map(([t, cls, title]) => `<span class="mc${cls ? ' ' + cls : ''}" title="${title}">${t}</span>`).join('') +
874
+ '<span class="mc acts"></span></div>'
875
+ host.innerHTML = head + list.map(n => {
868
876
  const r = watchRec(n)
869
- if (!r) return `<div class="mon"><span class="nm">${esc(n)}</span><span style="color:var(--t3);font-size:11.5px">不在目录中,点「刷新」去 npm 查</span><button class="x" data-rm="${esc(n)}">×</button></div>`
877
+ const name = r ? esc(r.label || n) : esc(n)
878
+ const ver = r && r.v ? ` <span class="ver">v${esc(r.v)}</span>` : ''
879
+ const live = r && r.live ? '<i class="livedot" title="实时数据:刚从 npm / GitHub 查的"></i>' : ''
880
+ const nameCell = `<span class="mc nm" title="${name}${r && r.v ? ' v' + esc(r.v) : ''}">${live}${name}${ver}</span>`
881
+ const acts = `<span class="mc acts">${r ? linkBtns(r, { icon: true }) : ''}<button class="x" data-rm="${esc(n)}" title="从我的监控移除" aria-label="移除 ${name}">×</button></span>`
882
+ if (!r) return `<div class="mrow">${nameCell}<span class="mc span">不在目录中,点「刷新」去 npm 查</span>${acts}</div>`
870
883
  const d = r.deep
871
884
  // 和目录数据比,周下载涨了还是跌了(只在刷新过、差得明显时标)
872
885
  let delta = ''
873
886
  if (r.live && r.catalogW) {
874
887
  const ch = (r.w - r.catalogW) / Math.max(r.catalogW, 1)
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>`
888
+ if (Math.abs(ch) >= 0.05) delta = `<span class="delta ${ch > 0 ? 'up' : 'down'}">${ch > 0 ? '↑' : '↓'}${Math.round(Math.abs(ch) * 100)}%</span>`
876
889
  }
877
- return `<div class="mon">` +
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>` +
879
- (r.live ? '<span class="live" title="刚从 npm 查的">实时</span>' : '') +
880
- `<span class="mrank">${rankText(r)}</span>` +
881
- `<span style="font-size:11.5px;color:var(--t3)">${esc(r.cat)}</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>` : '') +
885
- `<span style="font-size:12px;color:var(--t2)">${d ? ageText(d.age) + '发版' : ''}</span>` +
886
- `<span class="mlinks">${linkBtns(r, { icon: true })}</span>` +
887
- `<button class="x" data-rm="${esc(n)}">×</button></div>`
890
+ const rankFull = r.rank ? `总榜 #${num(r.rank)}${r.crank ? ` · ${r.cat} #${num(r.crank)}` : ''}` : ''
891
+ return '<div class="mrow">' + nameCell +
892
+ cell(r.rank ? `#${r.rank < 1000 ? r.rank : short(r.rank)}` : '—', rankFull || '不在总榜里', 'r') +
893
+ cell(esc(r.cat || '—'), r.cat || '') +
894
+ cell(r.w != null ? `<b>${short(r.w)}</b>${delta}` : '—', r.w != null ? `周下载 ${num(r.w)}${delta ? `(和目录数据相比 ${delta.replace(/<[^>]+>/g, '')})` : ''}` : '只在 GitHub,没有 npm 数据', 'r') +
895
+ cell(d ? short(d.base) : '—', d ? `日常基线 ${num(d.base)} 次/天` : '没有去噪指标', 'r') +
896
+ cell(r.gh ? `${short(r.gh.s)}${r.gh.a ? ' · 已归档' : ''}` : '—', r.gh ? `GitHub ★ ${num(r.gh.s)}${r.gh.p ? ` · 最近提交 ${r.gh.p}` : ''}${r.gh.a ? ' · 已归档' : ''}` : '没有 GitHub 数据', 'r') +
897
+ cell(d ? ageText(d.age) : '—', d && d.lastRelease ? `最近发版 ${d.lastRelease}` : '', 'r') +
898
+ acts + '</div>'
888
899
  }).join('')
889
900
 
890
901
  host.querySelectorAll('[data-rm]').forEach(b =>