dsh-dpharness 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,7 +14,7 @@
14
14
  | **分类精选** | `GET /api/best`(月度策展,与站点 [/best](https://dpharness.com/best) 同一份数据) | 「我该装哪几个」——按大类 → 小类分组,每小类只留 2~3 个 |
15
15
  | **套装**(v0.5.0) | `GET /api/sets`(组合方案,与站点 [/sets](https://dpharness.com/sets) 同一份数据) | 「我这件整事该配哪一套」——跨插件**纵向**组合:一整套 + 安装顺序 + 冲突提示 + 批量命令 |
16
16
  | **每日推荐**(v0.5.0) | 同上榜单,按自然日取一条 | 「今天装哪个」——当天唯一一条,所有用户一致 |
17
- | **我的插件**(v0.5.0) | 本机 profile + npmmirror | 「我装的这些该升级了吗」——本插件自身 + 已装插件逐包比对;**兼管理入口**:当场卸载(两步确认)、忽略某个版本、**收藏待装**(攒着一起装)、福利专区入口。标签原为「更新」,2026-10-13 改名 —— 它已经不只是"看更新",而是管理这一屏 |
17
+ | **我的插件**(v0.5.0) | 本机 profile + npmmirror | 「我装的这些该升级了吗」——本插件自身 + 已装插件逐包比对;**兼管理入口**:当场卸载(两步确认)、忽略某个版本、**收藏待装**(攒着一起装)、福利专区入口。标签原为「更新」,2026-10-13 改名 —— 它已经不只是"看更新",而是管理这一屏。v0.6.0 起附**使用频次与保留价值**(近 30 天调用数 / 分级 / 按频率排序 / 只看建议清理 / 人工「保留」标注) |
18
18
 
19
19
  分类精选视图刻意保留两项元数据:**小类内名次**与**上榜理由**(如「小类第 1 · 实装验证通过 · 周下载 12.8 万」)。
20
20
 
@@ -51,6 +51,30 @@ dateKey = YYYY-MM-DD(**固定 UTC+8**,不是本地时区)
51
51
  - 想换成编辑每天点选(真正的「每日一荐」),只需把 `pickDaily()` 的数据源换成站点新接口,
52
52
  界面不用动。
53
53
 
54
+ ### 使用频次与保留价值怎么算的(v0.6.0)
55
+
56
+ 用来回答「这些装着的插件,哪个值得留」。**全部在本机计算、零上传**:
57
+
58
+ - **数据源**:本机会话记录 `~/.dsh/sessions/**/session.v4.jsonl.zstd` 里的 `tool/call` 事件
59
+ —— 多帧 zstd(Node 原生只解首帧,本插件按帧魔数逐帧解压并校验行完整性),
60
+ 全量 30 天实测约 1.5s;结果缓存 6 小时,按文件 size+mtime 增量重扫。
61
+ - **工具 → 插件归属**:只认**确定归属**的工具(如 `ego_*`→ego-browser、`mnemon_*`→记忆、
62
+ `advanced/cache/domain_search`→免费搜索、`compress/decompress`→上下文压缩);
63
+ `web_search`/`web_fetch`/`read_page` 是通道类(多提供方动态接管)单列不计;内核工具
64
+ (bash/read/write/…)不归属任何插件。动态归属(运行时注册捕获)是下一步。
65
+ - **等级**:核心在用(≥20 次且跨 ≥3 个会话)/常用(≥5 次)/偶尔用(≥1 次)/
66
+ 可考虑清理(0 次且可度量)/已停用(loader 里被禁用)/**无法度量**(不产生可调用记录
67
+ 的被动型插件,如主题、样式类)。
68
+ - **三态纪律**:查不到 ≠ 没用 ——「无法度量」绝不写成「没在用」;引擎不可用时整列显示
69
+ 「使用数据不可用」。
70
+ - **展示**:徽章在「我的插件」每行版本号旁;列表上方给各档计数与两个开关
71
+ (「按使用频率」排序 /「只看建议清理」筛选)。
72
+ - **「保留」标注**高于一切机器判定:人工标为保留的插件不再进入清理建议(只存本机 localStorage)。
73
+ - **「禁用 / 启用」**(每行,两步确认):对拿不准的插件先停用观察 —— 可逆、即时生效、
74
+ 不动依赖清单(走运行时 `pluginManager.setPluginEnabled`,改的是 profile patch);
75
+ 「只看建议清理」筛选态下另有**批量禁用**(串行、有进度、可中止)。
76
+ 宿主没有启停能力(旧内核)时**不出**这个按钮;只读行 / 定位不到的行会带出明确原因。
77
+
54
78
  ## 五个入口
55
79
 
56
80
  | 入口 | 位置 | 说明 |
package/lib/changelog.js CHANGED
@@ -37,6 +37,17 @@ export function npmLatestUrl(pkg) {
37
37
  * (用户要看的是行为变化,不是我们的 commit 分类)。
38
38
  */
39
39
  export const CHANGELOG = [
40
+ {
41
+ version: "0.6.0",
42
+ date: "2026-10-16",
43
+ title: "插件使用频次与保留价值",
44
+ items: [
45
+ "「我的插件」新增使用概览:按**本机会话记录**统计每个插件近 30 天的调用次数与上次使用时间——只在本机计算,不上传。",
46
+ "插件按使用情况分级:核心在用 / 常用 / 偶尔用 / 可考虑清理 / 已停用;不产生调用记录的被动型插件标注「无法度量」,**不做「没用」的结论**。",
47
+ "新增「保留」标注:人工标为保留的插件不再出现在清理建议里;另支持按使用频率排序与「只看建议清理」筛选。",
48
+ "新增「禁用 / 启用」与「批量禁用」:拿不准的插件先停用观察(可逆、即时生效、不动依赖清单),确定不用了再卸载。",
49
+ ],
50
+ },
40
51
  {
41
52
  version: "0.5.2",
42
53
  date: "2026-10-14",
package/lib/client.js CHANGED
@@ -342,6 +342,48 @@ window.__ModuleLoader__.load({
342
342
  "install.reinstall": "重新安装",
343
343
  "install.reinstallConfirm": "确认重新安装?",
344
344
  "updates.batchNoop": "(其中 {k} 个 dsh 报告成功但版本没变)",
345
+ "usage.summary": "近 {d} 天:核心 {a} · 常用 {b} · 偶尔 {c} · 可考虑清理 {e} · 无法度量 {f}",
346
+ "usage.core": "核心在用",
347
+ "usage.common": "常用",
348
+ "usage.occasional": "偶尔用",
349
+ "usage.silent": "可考虑清理",
350
+ "usage.disabled": "已停用",
351
+ "usage.unmeasurable": "无法度量",
352
+ "usage.unknown": "使用数据不可用",
353
+ "usage.calls30d": "近30天 {n} 次",
354
+ "usage.stats": "近30天 {n} 次 · 上次使用 {d}",
355
+ "usage.today": "今天",
356
+ "usage.yesterday": "昨天",
357
+ "usage.daysAgo": "{d} 天前",
358
+ "usage.silentNote": "近 30 天没有可观测的调用记录",
359
+ "usage.unmeasurableNote": "该插件不产生可观测的调用(被动型),是否保留请人工判断",
360
+ "usage.unknownNote": "暂时读不到使用数据(宿主未提供统计)",
361
+ "usage.keep": "保留",
362
+ "usage.kept": "已保留",
363
+ "usage.keepHint": "标为保留后,不会再出现在清理建议里(只存本机,不上传)",
364
+ "usage.onlySuggest": "只看建议清理",
365
+ "usage.sortUsage": "按使用频率",
366
+ "usage.sortUsageOn": "恢复默认排序",
367
+ "usage.noneSuggest": "没有建议清理的插件(已保留的不会出现在这里)。",
368
+ "usage.disable": "禁用",
369
+ "usage.enable": "启用",
370
+ "usage.disableConfirm": "确认禁用?",
371
+ "usage.enableConfirm": "确认启用?",
372
+ "usage.toggleHint": "禁用/启用即时生效、随时可恢复(改的是本机 profile patch,不动依赖清单)",
373
+ "usage.toggling": "处理中…",
374
+ "usage.disabledDone": "已禁用",
375
+ "usage.enabledDone": "已启用",
376
+ "usage.toggleFailed": "操作失败",
377
+ "usage.toggleOverridden": "未能生效(被更高优先级的层覆盖)",
378
+ "usage.toggleSelf": "不能禁用它自己(管理界面会一起消失)",
379
+ "usage.toggleReadonly": "该行由 dsh 管理,不能在这里启停",
380
+ "usage.toggleUnaddressable": "该行定位不到(刷新后重试)",
381
+ "usage.toggleUnsupported": "当前宿主不支持启停(需要较新的 dsh)",
382
+ "usage.batchDisable": "批量禁用({n})",
383
+ "usage.batchConfirm": "将逐个禁用 {n} 个启用中的候选(可随时恢复)—— 再点一次开始。",
384
+ "usage.batchProgress": "禁用中 {done}/{total} · {name}",
385
+ "usage.batchDone": "已禁用 {done} 个 · 失败 {failed} 个",
386
+ "usage.batchHint": "只处理启用中的候选;已停用的请在行内卸载",
345
387
  "host.stale": "本机 host 还没提供这个接口 —— 通常是 dsh 未重启。重启 dsh 后再试。",
346
388
  "host.skew": "宿主进程是旧版本:本页需要更新的接口字段(重启后正常)。",
347
389
  "count.summary": "共 {n} 条结果",
@@ -545,6 +587,48 @@ window.__ModuleLoader__.load({
545
587
  "install.reinstall": "Reinstall",
546
588
  "install.reinstallConfirm": "Reinstall?",
547
589
  "updates.batchNoop": "({k} reported success but kept the same version)",
590
+ "usage.summary": "Last {d} days: {a} core · {b} regular · {c} occasional · {e} consider-removing · {f} undetectable",
591
+ "usage.core": "Core",
592
+ "usage.common": "Regular",
593
+ "usage.occasional": "Occasional",
594
+ "usage.silent": "Consider removing",
595
+ "usage.disabled": "Disabled",
596
+ "usage.unmeasurable": "Undetectable",
597
+ "usage.unknown": "Usage data unavailable",
598
+ "usage.calls30d": "{n} calls in 30d",
599
+ "usage.stats": "{n} calls in 30d · last used {d}",
600
+ "usage.today": "today",
601
+ "usage.yesterday": "yesterday",
602
+ "usage.daysAgo": "{d} days ago",
603
+ "usage.silentNote": "No observed calls in the last 30 days",
604
+ "usage.unmeasurableNote": "This plugin produces no observable calls (passive) — keep or remove manually",
605
+ "usage.unknownNote": "Usage data is unavailable from this host",
606
+ "usage.keep": "Keep",
607
+ "usage.kept": "Kept",
608
+ "usage.keepHint": "Kept plugins are excluded from removal suggestions (stored locally only)",
609
+ "usage.onlySuggest": "Suggestions only",
610
+ "usage.sortUsage": "By usage",
611
+ "usage.sortUsageOn": "Default order",
612
+ "usage.noneSuggest": "Nothing flagged for removal (kept plugins are excluded).",
613
+ "usage.disable": "Disable",
614
+ "usage.enable": "Enable",
615
+ "usage.disableConfirm": "Confirm disable?",
616
+ "usage.enableConfirm": "Confirm enable?",
617
+ "usage.toggleHint": "Enable/disable applies to the live session immediately and is fully reversible (edits the local profile patch, not dependencies).",
618
+ "usage.toggling": "Working…",
619
+ "usage.disabledDone": "Disabled",
620
+ "usage.enabledDone": "Enabled",
621
+ "usage.toggleFailed": "Failed",
622
+ "usage.toggleOverridden": "Not applied (overridden by a higher-priority layer)",
623
+ "usage.toggleSelf": "Cannot disable the hub itself",
624
+ "usage.toggleReadonly": "This row is managed by dsh and cannot be toggled here",
625
+ "usage.toggleUnaddressable": "This row cannot be addressed (refresh and retry)",
626
+ "usage.toggleUnsupported": "This host does not support enable/disable (needs a newer dsh)",
627
+ "usage.batchDisable": "Disable all ({n})",
628
+ "usage.batchConfirm": "Disable {n} enabled candidates one by one (fully reversible) — click again to start.",
629
+ "usage.batchProgress": "Disabling {done}/{total} · {name}",
630
+ "usage.batchDone": "Disabled {done} · failed {failed}",
631
+ "usage.batchHint": "Only enabled candidates are handled; uninstall disabled ones individually",
548
632
  "host.stale": "This build of the local host does not serve that route yet — usually dsh has not been restarted. Restart dsh and try again.",
549
633
  "host.skew": "The local host process is older than this UI: this page needs newer response fields (a restart fixes it).",
550
634
  "count.summary": "{n} results",
@@ -754,7 +838,7 @@ window.__ModuleLoader__.load({
754
838
  * 两个半边同包但不同运行时(一个在 Node、一个在浏览器),没法 import,
755
839
  * 只能各写一份 —— test-local.mjs 双向断言两者相等,改一处忘另一处会当场变红。
756
840
  */
757
- const HOST_SHAPE_REV = 3;
841
+ const HOST_SHAPE_REV = 4;
758
842
 
759
843
  /**
760
844
  * 宿主进程比客户端旧?
@@ -1284,6 +1368,29 @@ window.__ModuleLoader__.load({
1284
1368
  }
1285
1369
  }
1286
1370
 
1371
+ /* 「保留」标注 —— 本机偏好(localStorage):手动认定"这个插件我要留着"。
1372
+ 语义:**人工标注高于一切机器判定** —— 被标注的插件永不进入清理候选;
1373
+ 反过来,机器测不到(无法度量)的插件也要靠它把用户的真实意图记录下来。 */
1374
+ const KEEP_KEY = "dph-hub-keep";
1375
+ function readKeep() {
1376
+ try {
1377
+ const raw = localStorage.getItem(KEEP_KEY);
1378
+ if (!raw) return [];
1379
+ const parsed = JSON.parse(raw);
1380
+ if (!Array.isArray(parsed)) return [];
1381
+ return parsed.map((name) => String(name)).filter(Boolean).slice(0, 300);
1382
+ } catch (error) {
1383
+ return [];
1384
+ }
1385
+ }
1386
+ function storeKeep(value) {
1387
+ try {
1388
+ localStorage.setItem(KEEP_KEY, JSON.stringify(value));
1389
+ } catch (error) {
1390
+ /* 隐私模式下不持久化:本次会话内仍然有效 */
1391
+ }
1392
+ }
1393
+
1287
1394
  /* 「待重启」提醒 —— 本地通道安装/升级成功后的激活闭环(2026-10-13)。
1288
1395
  为什么必须做:桌面 profile 实测**没有 dshmarket**(只有 dsh-restart 的链接),
1289
1396
  安装全走本地通道、必须重启才生效 —— 「装了没启用」是主路径而不是边缘情况,
@@ -1310,7 +1417,7 @@ window.__ModuleLoader__.load({
1310
1417
  /* 隐私模式下不持久化:本次会话内仍然提醒 */
1311
1418
  }
1312
1419
  }
1313
- const hub = { open: false, hidden: hubHidden, daily: dailyOn, telemetry: telemetryOn, autoCheck: readAutoCheck(), ignore: readIgnore(), fav: readFav(), restartPending: readRestartPending(), install: null, batch: null, compare: [], listeners: new Set() };
1420
+ const hub = { open: false, hidden: hubHidden, daily: dailyOn, telemetry: telemetryOn, autoCheck: readAutoCheck(), ignore: readIgnore(), fav: readFav(), keep: readKeep(), restartPending: readRestartPending(), install: null, batch: null, compare: [], listeners: new Set() };
1314
1421
  function setHub(patch) {
1315
1422
  Object.assign(hub, patch);
1316
1423
  hub.listeners.forEach((listener) => listener());
@@ -1368,6 +1475,19 @@ window.__ModuleLoader__.load({
1368
1475
  const version = hub.ignore[String(item.name || "")];
1369
1476
  return Boolean(version) && version === String(item.latest || "");
1370
1477
  }
1478
+ /** 「保留」查询与切换(按包名,跨视图共享一份 hub.keep)。 */
1479
+ function isKept(name) {
1480
+ const key = String(name || "");
1481
+ return Boolean(key) && (hub.keep || []).indexOf(key) >= 0;
1482
+ }
1483
+ function toggleKeep(name) {
1484
+ const key = String(name || "");
1485
+ if (!key) return;
1486
+ const list = hub.keep || [];
1487
+ const next = isKept(key) ? list.filter((entry) => entry !== key) : list.concat([key]).slice(-300);
1488
+ storeKeep(next);
1489
+ setHub({ keep: next });
1490
+ }
1371
1491
  /**
1372
1492
  * 对比选择集 —— 挂在 hub 上(浮窗与页签共用一份),但**刻意不持久**:
1373
1493
  * 对比是一次性的动作,不是偏好;下次打开还挂着上回选的两个插件只会让人困惑。
@@ -2911,6 +3031,69 @@ window.__ModuleLoader__.load({
2911
3031
  * 只有本机 locale 与站点目录的并集才覆盖全)。缺中文名时显示包名并标注
2912
3032
  * 「未汉化」——与卡片同一口径,绝不假装有中文。
2913
3033
  */
3034
+ /* ---- 使用频次与保留价值(宿主下发 tier + usage;这里只做展示与筛选) ---- */
3035
+
3036
+ /** tier → 本地化标签(未知 tier 返回空串,不显示、不猜)。 */
3037
+ function tierLabel(tier) {
3038
+ const keys = { core: "usage.core", common: "usage.common", occasional: "usage.occasional", silent: "usage.silent", disabled: "usage.disabled", unmeasurable: "usage.unmeasurable", unknown: "usage.unknown" };
3039
+ return keys[tier] ? t(keys[tier]) : "";
3040
+ }
3041
+
3042
+ /** 上次使用时间的人话(今天 / 昨天 / N 天前)。 */
3043
+ function usageDaysText(ms) {
3044
+ const at = Number(ms) || 0;
3045
+ if (!at) return "";
3046
+ const days = Math.floor((Date.now() - at) / 86400000);
3047
+ if (days <= 0) return t("usage.today");
3048
+ if (days === 1) return t("usage.yesterday");
3049
+ return format(t("usage.daysAgo"), { d: days });
3050
+ }
3051
+
3052
+ /** 行内副标题里追加的使用情况(没有可说的就不加,保持安静)。 */
3053
+ function usageSubLines(item) {
3054
+ const tier = item && item.tier;
3055
+ const u = item && item.usage;
3056
+ if (tier === "unknown") return [t("usage.unknownNote")];
3057
+ if (tier === "unmeasurable") return [t("usage.unmeasurableNote")];
3058
+ if (u && u.measurable) {
3059
+ return u.calls > 0
3060
+ ? [format(t("usage.stats"), { n: u.calls, d: usageDaysText(u.lastUsedMs) })]
3061
+ : [t("usage.silentNote")];
3062
+ }
3063
+ return [];
3064
+ }
3065
+
3066
+ /** 汇总行:「近 30 天:核心 4 · 常用 6 …」(宿主给了窗口天数就用它)。 */
3067
+ function usageSummaryText(rows, meta) {
3068
+ const count = { core: 0, common: 0, occasional: 0, silent: 0, unmeasurable: 0 };
3069
+ (Array.isArray(rows) ? rows : []).forEach((item) => {
3070
+ const tier = item && item.tier;
3071
+ if (tier && count[tier] !== undefined) count[tier] += 1;
3072
+ });
3073
+ const days = meta && meta.windowDays ? meta.windowDays : 30;
3074
+ return format(t("usage.summary"), { d: days, a: count.core, b: count.common, c: count.occasional, e: count.silent, f: count.unmeasurable });
3075
+ }
3076
+
3077
+ /** 排序与筛选(纯函数):默认序 = 宿主顺序;usage = 按近 30 天调用数降序,未度量排后。 */
3078
+ function applyUsageView(rows, sortMode, onlySuggest) {
3079
+ let list = Array.isArray(rows) ? rows.slice() : [];
3080
+ if (onlySuggest) {
3081
+ list = list.filter((item) => {
3082
+ const tier = item && item.tier;
3083
+ return (tier === "silent" || tier === "disabled") && !isKept(item && item.name);
3084
+ });
3085
+ }
3086
+ if (sortMode === "usage") {
3087
+ list.sort((a, b) => {
3088
+ const ca = a && a.usage && typeof a.usage.calls === "number" ? a.usage.calls : -1;
3089
+ const cb = b && b.usage && typeof b.usage.calls === "number" ? b.usage.calls : -1;
3090
+ if (cb !== ca) return cb - ca;
3091
+ return String((a && a.name) || "").localeCompare(String((b && b.name) || ""));
3092
+ });
3093
+ }
3094
+ return list;
3095
+ }
3096
+
2914
3097
  function updateRow(item, key, prefix, copied, mark, removable) {
2915
3098
  const nameZh = typeof item.nameZh === "string" ? item.nameZh.trim() : "";
2916
3099
  const note = typeof item.note === "string" ? item.note.trim() : "";
@@ -2919,20 +3102,39 @@ window.__ModuleLoader__.load({
2919
3102
  const blocked = item.outdated === true && updates.blocked.includes(String(item.name) + "@" + String(item.latest || ""));
2920
3103
  /* 清单里写死版本(0.5.27 这种)—— plugin add 挪不动它,直接说清,免得用户反复点 */
2921
3104
  const pinned = item.kind === "pinned";
3105
+ /* 使用频次与保留(tier 由宿主下发;kept 只对本机已装行生效) */
3106
+ const tier = typeof item.tier === "string" ? item.tier : "";
3107
+ const kept = removable ? isKept(item.name) : false;
2922
3108
  const sub = [];
2923
3109
  if (note) sub.push(note);
2924
3110
  /* 有中文名时,包名挪到第二行(用户要靠它去搜/核对);没有中文名时它已在第一行 */
2925
3111
  if (nameZh) sub.push(String(item.name));
2926
3112
  if (pinned) sub.push(format(t("updates.pinnedNote"), { v: String(item.current || "") }));
3113
+ usageSubLines(item).forEach((line) => sub.push(line));
2927
3114
  return h("div", { className: "dph_updItem" + (item.outdated === true ? " dph_updOn" : ""), key: key }, [
2928
3115
  h("div", { className: "dph_upd", key: "row" }, [
2929
3116
  h("span", { className: "dph_updName", key: "n" }, (prefix ? prefix + " · " : "") + (nameZh || String(item.name))),
2930
3117
  untranslated ? h("span", { className: "dph_tag", key: "raw" }, t("label.untranslated")) : null,
2931
3118
  blocked ? h("span", { className: "dph_tag", key: "blocked" }, t("updates.blocked")) : null,
2932
3119
  pinned ? h("span", { className: "dph_tag", key: "pinned" }, t("updates.pinned")) : null,
3120
+ tier ? h("span", { className: "dph_tag", key: "usage" }, tierLabel(tier)) : null,
2933
3121
  h("span", { className: "dph_updVer", key: "v" }, "v" + String(item.current || "?") + (item.outdated === true ? " → v" + String(item.latest || "") : "")),
2934
3122
  h("span", { className: "dph_spacer", key: "gap" }),
2935
3123
  updateVerdict(item, key, copied, mark),
3124
+ /* 「保留」标注:人工高于机器 —— 标了就不再进清理建议;再点一次取消 */
3125
+ removable ? h("button", {
3126
+ className: "dph_btn",
3127
+ key: "keep",
3128
+ type: "button",
3129
+ title: t("usage.keepHint"),
3130
+ onClick: () => {
3131
+ const on = !kept;
3132
+ toggleKeep(item.name);
3133
+ track("plugin_hub", { action: "keep_toggle", on: on, scope: "updates" });
3134
+ },
3135
+ }, kept ? t("usage.kept") : t("usage.keep")) : null,
3136
+ /* 启用/禁用:可逆的「观察」动作(宿主提供启停能力时才有这一项) */
3137
+ removable && typeof item.enabled === "boolean" ? h(ToggleButton, { key: "toggle", item: item }) : null,
2936
3138
  /* 卸载入口:与"该不该升"并排。破坏性操作,自己带两步确认;
2937
3139
  本插件自己那一行不给(卸自己等于把管理界面卸掉)。 */
2938
3140
  removable ? h(RemoveButton, { key: "remove", item: { pkg: String(item.name || ""), name: item.nameZh || String(item.name || "") } }) : null,
@@ -3060,6 +3262,67 @@ window.__ModuleLoader__.load({
3060
3262
  }, t("updates.remove"));
3061
3263
  }
3062
3264
 
3265
+ /**
3266
+ * 启用 / 禁用 —— 「先停用观察」的出口(v0.6.0)。
3267
+ *
3268
+ * 与卸载的分工:卸载是破坏性的(改依赖清单、要重启);禁用是**可逆的**
3269
+ * (改本机 profile patch、即时应用、随时恢复)—— 对"拿不准要不要留"的插件,
3270
+ * 先禁用是唯一不后悔的动作。两步确认照旧;宿主不提供启停能力时不出这个按钮。
3271
+ */
3272
+ function ToggleButton(props) {
3273
+ const item = props.item;
3274
+ const [confirming, setConfirming] = react.useState(false);
3275
+ const [busy, setBusy] = react.useState(false);
3276
+ const [done, setDone] = react.useState("");
3277
+ const [failed, setFailed] = react.useState("");
3278
+ /* enabled=false 的行 → 目标是「启用」;其余(含 true)→ 「禁用」 */
3279
+ const want = item.enabled !== true;
3280
+ if (busy) return h("span", { className: "dph_instMsg", key: "tg" }, t("usage.toggling"));
3281
+ if (done) return h("span", { className: "dph_instMsg dph_instOk", key: "tg" }, done);
3282
+ if (failed) return h("span", { className: "dph_instMsg dph_instBad", key: "tg" }, failed);
3283
+ if (confirming) {
3284
+ return h("span", { className: "dph_logCmd", key: "tg" }, [
3285
+ h("button", {
3286
+ className: "dph_btn",
3287
+ key: "go",
3288
+ type: "button",
3289
+ onClick: async () => {
3290
+ setConfirming(false);
3291
+ setBusy(true);
3292
+ track("plugin_hub", { action: "toggle", on: want, pkg: String(item.name || "") });
3293
+ const result = await postJson("/api/dpharness/toggle", { name: String(item.name || ""), enabled: want });
3294
+ setBusy(false);
3295
+ const body = (result && result.data) || {};
3296
+ if (result && result.status === 200 && body.ok === true && body.enabled === want) {
3297
+ setDone(want ? t("usage.enabledDone") : t("usage.disabledDone"));
3298
+ loadUpdates(true);
3299
+ return;
3300
+ }
3301
+ if (body.code === "unsupported") { setFailed(t("usage.toggleUnsupported")); return; }
3302
+ if (body.code === "self") { setFailed(t("usage.toggleSelf")); return; }
3303
+ if (body.code === "management-required") { setFailed(t("usage.toggleReadonly")); return; }
3304
+ if (body.code === "unaddressable" || body.code === "not-found" || body.code === "ambiguous") { setFailed(t("usage.toggleUnaddressable")); return; }
3305
+ if (body.overridden === true) { setFailed(t("usage.toggleOverridden")); loadUpdates(true); return; }
3306
+ setFailed(t("usage.toggleFailed") + (body.error ? ":" + String(body.error) : ""));
3307
+ },
3308
+ }, want ? t("usage.enableConfirm") : t("usage.disableConfirm")),
3309
+ h("button", {
3310
+ className: "dph_btn",
3311
+ key: "cancel",
3312
+ type: "button",
3313
+ onClick: () => { setConfirming(false); track("plugin_hub", { action: "toggle_cancel" }); },
3314
+ }, t("install.cancel")),
3315
+ ]);
3316
+ }
3317
+ return h("button", {
3318
+ className: "dph_btn",
3319
+ key: "tg",
3320
+ type: "button",
3321
+ title: t("usage.toggleHint"),
3322
+ onClick: () => { setConfirming(true); track("plugin_hub", { action: "toggle_ask", on: want }); },
3323
+ }, want ? t("usage.enable") : t("usage.disable"));
3324
+ }
3325
+
3063
3326
  /**
3064
3327
  * 一行的结论。三态必须三句话:可升级(一键升级 + 复制命令)/已是最新/查不到 ——
3065
3328
  * 把「查不到」显示成「已是最新」是本插件明确禁止的那类错误。
@@ -3136,6 +3399,14 @@ window.__ModuleLoader__.load({
3136
3399
  const [restartAsk, setRestartAsk] = react.useState(false);
3137
3400
  const [restarting, setRestarting] = react.useState(false);
3138
3401
  const [restartFailed, setRestartFailed] = react.useState(false);
3402
+ /* 使用视图:排序切换与「只看建议清理」筛选(本会话内有效,不持久) */
3403
+ const [sortMode, setSortMode] = react.useState("default");
3404
+ const [onlySuggest, setOnlySuggest] = react.useState(false);
3405
+ /* 批量禁用:本地状态驱动(不挤占安装批处理那台机器);stop 用 ref 传递中止信号。
3406
+ ⚠️ 变量名带 disable —— 上面的 `batchAsk` 是「批量升级」的,同名会直接语法错 */
3407
+ const [batchDisableAsk, setBatchDisableAsk] = react.useState(false);
3408
+ const [batchRun, setBatchRun] = react.useState(null);
3409
+ const batchStop = react.useRef(null);
3139
3410
  const data = store.data;
3140
3411
  /* 收藏区要知道哪些已经装了(用更新检查这份清单,不再多打一次请求) */
3141
3412
  const installedNames = new Set(
@@ -3212,6 +3483,27 @@ window.__ModuleLoader__.load({
3212
3483
  }
3213
3484
  const self = data.self || {};
3214
3485
  const rows = Array.isArray(data.plugins) ? data.plugins : [];
3486
+ const visibleRows = applyUsageView(rows, sortMode, onlySuggest);
3487
+ /* 批量禁用只处理「启用中」的候选;已停用的走行内卸载 */
3488
+ const batchCandidates = visibleRows.filter((row) => row && row.enabled === true);
3489
+ async function runBatchDisable() {
3490
+ const queue = batchCandidates.slice();
3491
+ const state = { done: 0, failed: 0, stop: false };
3492
+ batchStop.current = state;
3493
+ setBatchRun({ done: 0, failed: 0, total: queue.length, current: "", finished: false });
3494
+ for (const row of queue) {
3495
+ if (state.stop) break;
3496
+ const result = await postJson("/api/dpharness/toggle", { name: String(row.name || ""), enabled: false });
3497
+ const body = (result && result.data) || {};
3498
+ if (result && result.status === 200 && body.ok === true && body.enabled === false) state.done += 1;
3499
+ else state.failed += 1;
3500
+ setBatchRun({ done: state.done, failed: state.failed, total: queue.length, current: String(row.name || ""), finished: false });
3501
+ }
3502
+ batchStop.current = null;
3503
+ setBatchRun({ done: state.done, failed: state.failed, total: queue.length, current: "", finished: true });
3504
+ loadUpdates(true);
3505
+ track("plugin_hub", { action: "batch_disable_done", done: state.done, failed: state.failed });
3506
+ }
3215
3507
  const batch = state.batch;
3216
3508
  /* 自插件也算进去:它同样是"升一下就到最新",用户在意的是一共几个。
3217
3509
  目标写成**具体版本号**(@latest 在 dsh 上是空转的)。 */
@@ -3279,9 +3571,67 @@ window.__ModuleLoader__.load({
3279
3571
  /* 本插件自己的更新日志就在它这一行下面 —— 不必再为它跑一趟设置页 */
3280
3572
  changelogBlock(cl.state.data ? cl.state.data.entries : null, "upd:"),
3281
3573
  h("div", { className: "dph_setTitle", key: "installed" }, t("updates.installed")),
3282
- rows.length === 0
3283
- ? h(Notice, { key: "none", text: t("updates.none") })
3284
- : h("div", { className: "dph_updList", key: "list" }, rows.map((item) => updateRow(item, item.name, "", copied, mark, true))),
3574
+ h("div", { className: "dph_logCmd", key: "usagebar" }, [
3575
+ h("span", { className: "dph_setHint", key: "sum" }, usageSummaryText(rows, data.usageMeta)),
3576
+ h("span", { className: "dph_spacer", key: "gap" }),
3577
+ h("button", {
3578
+ className: "dph_btn",
3579
+ key: "sort",
3580
+ type: "button",
3581
+ onClick: () => {
3582
+ const next = sortMode === "usage" ? "default" : "usage";
3583
+ setSortMode(next);
3584
+ track("plugin_hub", { action: "usage_sort", mode: next, scope: scope });
3585
+ },
3586
+ }, sortMode === "usage" ? t("usage.sortUsageOn") : t("usage.sortUsage")),
3587
+ h("button", {
3588
+ className: "dph_btn" + (onlySuggest ? " dph_btnPrimary" : ""),
3589
+ key: "filter",
3590
+ type: "button",
3591
+ onClick: () => {
3592
+ const next = !onlySuggest;
3593
+ setOnlySuggest(next);
3594
+ track("plugin_hub", { action: "usage_filter", on: next, scope: scope });
3595
+ },
3596
+ }, t("usage.onlySuggest")),
3597
+ ]),
3598
+ batchRun
3599
+ ? h("div", { className: "dph_logCmd", key: "batchrun" }, [
3600
+ h("span", { className: "dph_instMsg", key: "msg" }, batchRun.finished
3601
+ ? format(t("usage.batchDone"), { done: batchRun.done, failed: batchRun.failed })
3602
+ : format(t("usage.batchProgress"), { done: batchRun.done, total: batchRun.total, name: batchRun.current })),
3603
+ !batchRun.finished
3604
+ ? h("button", {
3605
+ className: "dph_btn",
3606
+ key: "stop",
3607
+ type: "button",
3608
+ onClick: () => { if (batchStop.current) batchStop.current.stop = true; track("plugin_hub", { action: "batch_disable_stop" }); },
3609
+ }, t("updates.stop"))
3610
+ : null,
3611
+ ])
3612
+ : (onlySuggest && batchCandidates.length > 0
3613
+ ? h("div", { className: "dph_logCmd", key: "batchask" }, [
3614
+ batchDisableAsk ? h("span", { className: "dph_setHint", key: "warn" }, format(t("usage.batchConfirm"), { n: batchCandidates.length })) : null,
3615
+ h("button", {
3616
+ className: "dph_btn" + (batchDisableAsk ? " dph_btnPrimary" : ""),
3617
+ key: "go",
3618
+ type: "button",
3619
+ onClick: () => {
3620
+ if (!batchDisableAsk) {
3621
+ setBatchDisableAsk(true);
3622
+ track("plugin_hub", { action: "batch_disable_ask", n: batchCandidates.length });
3623
+ return;
3624
+ }
3625
+ setBatchDisableAsk(false);
3626
+ runBatchDisable();
3627
+ },
3628
+ }, format(t("usage.batchDisable"), { n: batchCandidates.length })),
3629
+ h("span", { className: "dph_setHint", key: "hint" }, t("usage.batchHint")),
3630
+ ])
3631
+ : null),
3632
+ visibleRows.length === 0
3633
+ ? h(Notice, { key: "none", text: rows.length === 0 ? t("updates.none") : t("usage.noneSuggest") })
3634
+ : h("div", { className: "dph_updList", key: "list" }, visibleRows.map((item) => updateRow(item, item.name, "", copied, mark, true))),
3285
3635
  data.counts && data.counts.unknown > 0
3286
3636
  ? h("div", { className: "dph_setHint", key: "unknown" }, format(t("updates.unknownNote"), { k: data.counts.unknown }))
3287
3637
  : null,
@@ -3293,9 +3643,15 @@ window.__ModuleLoader__.load({
3293
3643
  ]),
3294
3644
  h("div", { className: "dph_logNest", key: "body" }, [
3295
3645
  h("div", { className: "dph_setHint", key: "note" }, t("updates.localsNote")),
3296
- ...((Array.isArray(data.locals) ? data.locals : []).map((row) => h("div", { className: "dph_updSub", key: String(row.name) },
3297
- String(row.name) + " → " + String(row.spec || "").replace(/^(link|file):/, ""),
3298
- ))),
3646
+ ...((Array.isArray(data.locals) ? data.locals : []).map((row) => {
3647
+ const bits = [];
3648
+ if (row && row.tier) bits.push(tierLabel(row.tier));
3649
+ if (row && row.usage && row.usage.measurable && row.usage.calls > 0) bits.push(format(t("usage.calls30d"), { n: row.usage.calls }));
3650
+ const suffix = bits.length ? " · " + bits.join(" · ") : "";
3651
+ return h("div", { className: "dph_updSub", key: String(row.name) },
3652
+ String(row.name) + " → " + String(row.spec || "").replace(/^(link|file):/, "") + suffix,
3653
+ );
3654
+ })),
3299
3655
  ]),
3300
3656
  ])
3301
3657
  : null,
package/lib/index.js CHANGED
@@ -39,13 +39,14 @@ import fs from "node:fs";
39
39
  import os from "node:os";
40
40
  import path from "node:path";
41
41
  import { CHANGELOG, RELEASES_URL, REPO, compareVersions, mergeChangelog, npmLatestUrl } from "./changelog.js";
42
+ import { classifyUsage, getUsageReport } from "./usage.js";
42
43
 
43
44
  export const name = "dpharness";
44
45
 
45
46
  /** The dsh web server service used to register HTTP routes. */
46
47
  export const inject = ["webServer"];
47
48
 
48
- export const VERSION = "0.5.2";
49
+ export const VERSION = "0.6.0";
49
50
 
50
51
  /**
51
52
  * 本插件在 npm 上的包名 —— 与 dsh 的插件 id(上面的 `name = "dpharness"`)**不是一回事**,
@@ -63,7 +64,7 @@ export const PKG_NAME = "dsh-dpharness";
63
64
  * ⚠️ 客户端侧有一份同名常量(两个半边同包但不同运行时,没法 import),
64
65
  * test-local.mjs **双向断言两者相等** —— 改一处忘了另一处会当场变红。
65
66
  */
66
- export const SHAPE_REV = 3;
67
+ export const SHAPE_REV = 4;
67
68
 
68
69
  /**
69
70
  * Wall-clock time this dsh process started.
@@ -1398,15 +1399,77 @@ export function sortUpdates(entries) {
1398
1399
  * 本插件**从已装列表里摘出来单独给**(self)—— 它同时出现在 profile 的 dependencies 里,
1399
1400
  * 两处都列会让人以为有两个不同的东西要升级。
1400
1401
  */
1401
- async function buildUpdates() {
1402
+ /** pluginManager 的已知拒绝原因(界面据此出中文;不在表里的原样展示)。 */
1403
+ const TOGGLE_FAILURE_CODES = ["unknown-plugin", "management-required", "unaddressable", "incompatible-version"];
1404
+
1405
+ /** 使用频次引擎失败时不产出结论(三态),绝不让「没测到」冒充「没在用」。 */
1406
+ function safeUsageReport() {
1407
+ try {
1408
+ return getUsageReport();
1409
+ } catch {
1410
+ return null;
1411
+ }
1412
+ }
1413
+
1414
+ /**
1415
+ * 启用状态(三态):从运行时 `pluginManager` 服务读取。
1416
+ * 服务不存在(或读取失败)→ null,全部按「未知」处理,不猜。
1417
+ */
1418
+ async function enabledMapOf(ctx) {
1419
+ try {
1420
+ const manager = ctx && typeof ctx.get === "function" ? ctx.get("pluginManager") : undefined;
1421
+ if (!manager || typeof manager.listPlugins !== "function") return null;
1422
+ const rows = await manager.listPlugins();
1423
+ const map = new Map();
1424
+ for (const row of Array.isArray(rows) ? rows : []) {
1425
+ if (row && typeof row.moduleName === "string") map.set(row.moduleName, row.enabled !== false);
1426
+ }
1427
+ return map;
1428
+ } catch {
1429
+ return null;
1430
+ }
1431
+ }
1432
+
1433
+ /** 安装/最近变化时间(粗略):node_modules/<pkg> 的 mtime。link: 包指向源码目录,不适用,给 null。 */
1434
+ function installedAtOf(name, dir, kind) {
1435
+ if (kind === "local") return null;
1436
+ try {
1437
+ return fs.statSync(path.join(dir, "node_modules", name)).mtimeMs || null;
1438
+ } catch {
1439
+ return null;
1440
+ }
1441
+ }
1442
+
1443
+ /** 单个包的使用记录;引擎不可用给 null,无归属工具的包给 { measurable:false }。 */
1444
+ function usageFor(usageReport, pkg) {
1445
+ if (!usageReport) return null;
1446
+ const found = usageReport.plugins && usageReport.plugins[pkg];
1447
+ if (found) return found;
1448
+ return { measurable: false, calls: 0, sessions: 0, lastUsedMs: null, tools: [] };
1449
+ }
1450
+
1451
+ async function buildUpdates(ctx) {
1402
1452
  const dir = profileDir();
1403
1453
  const candidates = pluginCandidates(profileManifest());
1454
+ const usageReport = safeUsageReport();
1455
+ const enabledByPkg = await enabledMapOf(ctx);
1404
1456
  const installed = await mapLimit(candidates, UPDATE_CONCURRENCY, (candidate) => readInstalled(candidate.name, dir));
1405
1457
  const rows = candidates.map((candidate, index) => ({ ...candidate, info: installed[index], kind: classifySpec(candidate.spec) }));
1406
1458
  /* 本地链接的包**不参与更新检查**:它们的"版本"来自本机源码,跟 npm 上的最新版没有关系。
1407
1459
  实测本机 desktop profile 的 20 个依赖里有 11 个是这种(含本插件自己)——
1408
1460
  把它们当"可升级"列出来,只会让用户点一次、失败一次(而且方向本来就是错的)。 */
1409
- const locals = rows.filter((row) => row.kind === "local").map((row) => ({ name: row.name, spec: row.spec }));
1461
+ const locals = rows.filter((row) => row.kind === "local").map((row) => {
1462
+ const usageRow = usageFor(usageReport, row.name);
1463
+ const enabled = enabledByPkg ? (enabledByPkg.has(row.name) ? enabledByPkg.get(row.name) : null) : null;
1464
+ return {
1465
+ name: row.name,
1466
+ spec: row.spec,
1467
+ enabled,
1468
+ installedAtMs: installedAtOf(row.name, dir, row.kind),
1469
+ usage: usageRow,
1470
+ tier: classifyUsage(enabled, usageRow),
1471
+ };
1472
+ });
1410
1473
  const plugins = rows.filter((row) => row.kind !== "local" && row.info && row.info.plugin && row.name !== PKG_NAME);
1411
1474
  const versions = await mapLimit(plugins, UPDATE_CONCURRENCY, (row) => fetchNpmVersion(row.name));
1412
1475
 
@@ -1446,6 +1509,8 @@ async function buildUpdates() {
1446
1509
  const current = row.info.version;
1447
1510
  const latest = versions[index];
1448
1511
  const found = identity.get(row.name) || { nameZh: "", note: "" };
1512
+ const usageRow = usageFor(usageReport, row.name);
1513
+ const enabled = enabledByPkg ? (enabledByPkg.has(row.name) ? enabledByPkg.get(row.name) : null) : null;
1449
1514
  return {
1450
1515
  name: row.name,
1451
1516
  /* 中文名可能为空 —— 界面回落显示包名,并明确标注「未汉化」,绝不假装有中文 */
@@ -1458,6 +1523,12 @@ async function buildUpdates() {
1458
1523
  kind: row.kind,
1459
1524
  current,
1460
1525
  latest,
1526
+ /* 使用频次与保留价值(本机计算、零上传;详见 lib/usage.js 的口径说明) */
1527
+ enabled,
1528
+ installedAtMs: installedAtOf(row.name, dir, row.kind),
1529
+ usage: usageRow,
1530
+ /* 等级:core/common/occasional/silent/disabled/unmeasurable/unknown —— 客户端直接消费 */
1531
+ tier: classifyUsage(enabled, usageRow),
1461
1532
  /* 三态:任一端拿不到就不下结论(null),绝不用 false 兜底 */
1462
1533
  outdated: latest && current ? compareVersions(current, latest) < 0 : null,
1463
1534
  /* ⚠️ 用**具体版本号**(dsh-context@0.69.1),不要 `@latest`。
@@ -1489,6 +1560,15 @@ async function buildUpdates() {
1489
1560
  : `dsh plugin --profile ${PROFILE} add ${PKG_NAME}@latest`,
1490
1561
  },
1491
1562
  plugins: entries,
1563
+ /* 使用频次统计口径(本机计算,零上传)。null = 引擎不可用,客户端按「无法度量」展示 */
1564
+ usageMeta: usageReport
1565
+ ? {
1566
+ windowDays: usageReport.windowDays,
1567
+ generatedAtMs: usageReport.generatedAtMs,
1568
+ cacheAgeMs: usageReport.cacheAgeMs,
1569
+ scanned: usageReport.scanned,
1570
+ }
1571
+ : null,
1492
1572
  /* 本地链接的包(link:/file:)单列:它们不参与更新检查,但用户需要知道"它们为什么不在列表里" */
1493
1573
  locals: locals,
1494
1574
  counts: {
@@ -1685,6 +1765,85 @@ export function apply(ctx) {
1685
1765
  sendJson(res, 202, { ok: true, target, verb, profile: PROFILE, job: jobView() });
1686
1766
  });
1687
1767
 
1768
+ /**
1769
+ * 启用/禁用(「禁用观察」通道)。
1770
+ *
1771
+ * 走运行时 `pluginManager.setPluginEnabled(entryId, enabled)`——它把改动写进 profile 的
1772
+ * patch 并即时应用(`reload`),比"卸载"温和得多:可随时恢复、不改依赖清单。
1773
+ * 与卸载一样要求两步确认在**客户端**做(这里只承接已确认的调用)。
1774
+ *
1775
+ * 三态纪律:
1776
+ * · 宿主没有该服务(旧内核)→ 501 `unsupported`(明说"不支持",不冒充失败);
1777
+ * · 同名多入口 / 无 entryId / 只读行 → 409 带 code,界面据此出中文;
1778
+ * · 改完**复读真值**——`setPluginEnabled` 可能被更高优先级的层覆盖(overridden),
1779
+ * 响应里的 `enabled` 永远是"实际状态"而不是"请求状态"。
1780
+ */
1781
+ registerRoute(ctx, "/api/dpharness/toggle", async (req, res) => {
1782
+ if (req.method !== "POST") {
1783
+ res.writeHead(405, { allow: "POST" });
1784
+ res.end();
1785
+ return;
1786
+ }
1787
+ let input;
1788
+ try {
1789
+ input = JSON.parse((await readBody(req, 2048)) || "{}");
1790
+ } catch (error) {
1791
+ sendJson(res, 400, { ok: false, error: String((error && error.message) || error) });
1792
+ return;
1793
+ }
1794
+ const name = typeof (input && input.name) === "string" ? input.name.trim().slice(0, 214) : "";
1795
+ const want = input && input.enabled === true;
1796
+ if (!name) {
1797
+ sendJson(res, 400, { ok: false, error: "missing plugin name", code: "missing-name" });
1798
+ return;
1799
+ }
1800
+ /* 禁自己等于把管理界面一起关掉:明确拒绝(卸载通道也有同样的保护) */
1801
+ if (name === PKG_NAME) {
1802
+ sendJson(res, 400, { ok: false, error: "refusing to toggle dsh-dpharness itself", code: "self" });
1803
+ return;
1804
+ }
1805
+ const manager = ctx && typeof ctx.get === "function" ? ctx.get("pluginManager") : undefined;
1806
+ if (!manager || typeof manager.listPlugins !== "function" || typeof manager.setPluginEnabled !== "function") {
1807
+ sendJson(res, 501, { ok: false, error: "toggle is not supported by this host", code: "unsupported" });
1808
+ return;
1809
+ }
1810
+ try {
1811
+ const rows = await manager.listPlugins();
1812
+ const matches = (Array.isArray(rows) ? rows : []).filter((row) => row && row.moduleName === name);
1813
+ if (matches.length === 0) {
1814
+ sendJson(res, 404, { ok: false, error: "plugin entry not found", code: "not-found" });
1815
+ return;
1816
+ }
1817
+ if (matches.length > 1) {
1818
+ sendJson(res, 409, { ok: false, error: "multiple entries share this name", code: "ambiguous" });
1819
+ return;
1820
+ }
1821
+ const row = matches[0];
1822
+ if (typeof row.entryId !== "string" || !row.entryId) {
1823
+ sendJson(res, 409, { ok: false, error: "entry cannot be addressed", code: "unaddressable" });
1824
+ return;
1825
+ }
1826
+ if (row.enabled === want) {
1827
+ sendJson(res, 200, { ok: true, name, enabled: want, changed: false });
1828
+ return;
1829
+ }
1830
+ await manager.setPluginEnabled(row.entryId, want);
1831
+ const after = (await manager.listPlugins()).find((item) => item && item.entryId === row.entryId);
1832
+ const actual = after ? after.enabled !== false : null;
1833
+ sendJson(res, 200, {
1834
+ ok: true,
1835
+ name,
1836
+ enabled: actual,
1837
+ changed: actual === want,
1838
+ ...(actual === want ? {} : { overridden: true }),
1839
+ });
1840
+ } catch (error) {
1841
+ const raw = String((error && error.message) || error);
1842
+ const code = (error && typeof error.code === "string" && error.code) || (TOGGLE_FAILURE_CODES.includes(raw) ? raw : undefined);
1843
+ sendJson(res, 409, { ok: false, error: raw, ...(code ? { code } : {}) });
1844
+ }
1845
+ });
1846
+
1688
1847
  /**
1689
1848
  * Post-install evidence for telemetry.
1690
1849
  *
@@ -1793,7 +1952,7 @@ export function apply(ctx) {
1793
1952
  return;
1794
1953
  }
1795
1954
  try {
1796
- const value = await buildUpdates();
1955
+ const value = await buildUpdates(ctx);
1797
1956
  updatesCache = { at: Date.now(), value };
1798
1957
  sendJson(res, 200, { ...value, cached: false });
1799
1958
  } catch (error) {
@@ -1824,6 +1983,7 @@ export function apply(ctx) {
1824
1983
  "/api/dpharness/event",
1825
1984
  "/api/dpharness/install",
1826
1985
  "/api/dpharness/postinstall",
1986
+ "/api/dpharness/toggle",
1827
1987
  "/api/dpharness/changelog",
1828
1988
  "/api/dpharness/updates",
1829
1989
  "/api/dpharness/meta",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-dpharness",
3
3
  "icon": "./icon.svg",
4
- "version": "0.5.2",
4
+ "version": "0.6.0",
5
5
  "description": "Curated dpharness.com plugin catalog inside the DeepSeek Harness Web GUI: a conversation-view tab, a sidebar entry and a dismissible site-wide floating panel, offering a searchable full catalog, a monthly by-category shortlist, a daily pick and an update check (this plugin plus every installed plugin) with a red-dot reminder, with one-click install via dshmarket or the dsh CLI. Includes a settings page (General row + Plugins tab) for the widget visibility, the daily pick, the update check and the opt-out telemetry relay covering the full install funnel.",
6
6
  "author": "zhanghao3693 <zhanghao3693@qq.com>",
7
7
  "repository": {