dsh-plugin-tool-management 0.21.6 → 0.21.8

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/CHANGELOG.md CHANGED
@@ -10,6 +10,29 @@
10
10
 
11
11
  ---
12
12
 
13
+ ## [0.21.8] - 2026-10-28
14
+
15
+ ### 新增
16
+
17
+ - **检查更新给出可复制的升级命令**:有兼容更新时点击更新键弹出升级卡,展示固定到该版本的 `dsh plugin ... add ...` 命令;复制到终端执行并重启 DSH。命令不使用 `@latest`,也不在界面内自动安装。
18
+ - **更新检查跟随宿主的下载源**:按宿主登记的源(配置的第一源 + fallback,含镜像)依次请求,并用宿主的双源测速决定先问哪个;不再写死 npm 官方源。
19
+ - **更新检查不再丢弃显式配置的私有源**:冷启动时不再因为等待宿主解析源超时而退回 npm 官方源。
20
+ - **更新检查加固**:跳过 registry 上被标记为 deprecated 的版本;registry 响应加 8 MiB 流式上限;`host-unknown` 按失败缓存 1 小时;缓存读数按当前 profile 重建命令。
21
+ - **档案同步不再复制演示视频**:`docs/videos`(约 97MB)不进入 profile,已有副本会在下一次构建时清掉。
22
+ - **web / desktop 同时运行时不再互相覆盖侧车**:hub 写入加跨进程文件锁(`.write.lock`),停用表 / 作用域覆盖 / 工具表不会被后写的进程整份盖掉;进程崩溃留下的锁最多挡一分钟。
23
+ - **作用域侧车损坏可修复**:作用域条出现写入错误时可点「修复作用域文件」,确认后把损坏文件改名留存、按空表继续,不再只能手删。
24
+ - **技能 / 来源意图随资源删除清理**:对账时清掉已不存在的技能与技能来源的全局意图,同名资源重建不再继承旧的 off / blocked。
25
+
26
+ ## [0.21.7] - 2026-10-27
27
+
28
+ ### 修复
29
+
30
+ - **面板在对话进行中持续闪烁**:宿主会话清单变动改为静默刷新(不立 loading、内容未变不写状态),提示词 / 记忆页不再跟着整份重取。
31
+
32
+ ### 变更
33
+
34
+ - **空清单的 MCP 状态段改用长间隔重算**:MCP 注入域开启但没有服务器时,后台不再每 3 秒全量枚举一次,改为 60 秒确认一次;事件驱动的刷新不受影响。
35
+
13
36
  ## [0.21.6] - 2026-10-24
14
37
 
15
38
  ### 修复
package/docs/UPDATE.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  | 版本 | 发布 | 主题 |
6
6
  | ------------------------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
7
+ | [0.21.8](../CHANGELOG.md#0218---2026-10-28) | 2026-10-28 | 「检查更新」在发现兼容版本时给出可复制的固定版本升级命令(不使用 `@latest`,不在界面内安装);检查跟随宿主登记的下载源(含镜像回退),不再写死 npm 官方源;更新检查跳过 deprecated、限制响应体大小,档案同步不再复制演示视频;作用域侧车损坏可在作用域条一键隔离修复,技能 / 来源意图随资源删除清理;web / desktop 同时运行时 hub 写入加跨进程锁,不再互相覆盖 |
8
+ | [0.21.7](../CHANGELOG.md#0217---2026-10-27) | 2026-10-27 | 修好面板在对话进行中持续闪烁:会话清单变动不再触发顶栏 loading 与提示词 / 记忆页整份重取;MCP 注入域开启且无服务器时,状态段改为 60 秒确认一次,降低后台开销 |
7
9
  | [0.21.6](../CHANGELOG.md#0216---2026-10-24) | 2026-10-24 | 修好「应用提示词预设」恒定失败(并发指纹校验误拿正文当指纹,#22);记忆附件补根内断言、保留期清理先送系统回收站、场景冻结口径统一(回收站永久删除与被锁场景编辑纳入)且即时生效、人设名单逐条转义、预设 / 快捷词 / 人设改名可重试;适配宿主 0.2.1-rc.3 |
8
10
  | [0.21.5](../CHANGELOG.md#0215---2026-10-23) | 2026-10-23 | 十处写操作补上确认卡(MCP 停机、提示词正向应用、五域删除、开关落到机器级),恢复路径不拦;错误消息附现成候选(记忆 id、技能名、场景名、预设 id、MCP 服务器名) |
9
11
  | [0.21.4](../CHANGELOG.md#0214---2026-10-23) | 2026-10-23 | 「彻底停止」改为一次性的「统一关闭」;场景 / MCP / 技能 / 子智能体 / 提示词 / 记忆六页页头新增「全部关闭」(有临时运行时才出现,位于回收站右侧,执行后立即消失);技能行可编辑(官方内置只读),场景 / 子智能体 / 记忆 / 快捷提示词补齐逐条「统一关闭」;统一关闭后徽章即时消失、不再触发列表重排;兼容页移除更新检查行,「保存到场景」「创建技能」文案收短 |
package/lib/client.js CHANGED
@@ -2520,6 +2520,8 @@ button.dsm-rowselect-box:disabled{cursor:default;opacity:.45}
2520
2520
  currentSessionId: function () { return '' },
2521
2521
  /** 订阅宿主会话列表 / 工作区记账(归档 / 恢复 / 起标题后下拉要跟着变);返回取消函数。 */
2522
2522
  subscribeSessionList: function (fn) { return null },
2523
+ /** 提示条(修复结果用);缺省不弹。参数须与 `showPluginToast` 同形,供 checkJs 推断。 */
2524
+ toast: function (text, kind) {},
2523
2525
  }
2524
2526
  function configureScopeDeps(next) {
2525
2527
  scopeDeps = Object.assign({}, scopeDeps, next || {})
@@ -2553,18 +2555,57 @@ button.dsm-rowselect-box:disabled{cursor:default;opacity:.45}
2553
2555
  * 还会和菜单自己的那一拍抢读。
2554
2556
  */
2555
2557
  var scopeMounted = 0
2558
+ /**
2559
+ * 后台刷新(静默)的最小间隔。
2560
+ *
2561
+ * 会话列表在对话流式输出期间按帧通知(任何一条会话的投影更新都会让宿主重建清单),
2562
+ * 只靠下面的 400ms 去抖仍然会变成每 400ms 一次重拉 —— 而每次重拉是两条重查询
2563
+ * (`scope-sessions-list` 扫会话清单、`scope-get` 扫五个域),页面还会跟着修订号
2564
+ * 整份重取,用户看到的就是面板一直闪。清单变化只影响下拉里的标题 / 「当前」标记,
2565
+ * 2 秒的滞后看不出来。
2566
+ */
2567
+ var SCOPE_SILENT_MIN_INTERVAL_MS = 2000
2568
+ var scopeLastSilentAt = 0
2556
2569
  /** 会话列表变化后的合并刷新:标题 / 归档 / 恢复可能连着来,400ms 内只重拉一次。 */
2557
2570
  var scopeRefreshTimer = null
2558
2571
  function scheduleScopeRefresh() {
2559
2572
  if (scopeRefreshTimer !== null) return
2560
- scopeRefreshTimer = setTimeout(function () { scopeRefreshTimer = null; refreshScope() }, 400)
2573
+ var wait = 400
2574
+ if (scopeLastSilentAt > 0) {
2575
+ var since = Date.now() - scopeLastSilentAt
2576
+ if (since < SCOPE_SILENT_MIN_INTERVAL_MS) wait = Math.max(wait, SCOPE_SILENT_MIN_INTERVAL_MS - since)
2577
+ }
2578
+ scopeRefreshTimer = setTimeout(function () { scopeRefreshTimer = null; refreshScope({ silent: true }) }, wait)
2579
+ }
2580
+ /** 界面上会被 `refreshScope` 改到的字段指纹(options 已含标题 / 条数 / 「当前」标记)。 */
2581
+ function scopeVisibleSig(s) {
2582
+ return JSON.stringify([
2583
+ s.mode, s.currentSessionId, s.currentScopeKey, s.workspaces, s.options, s.groups,
2584
+ s.overrides, s.effective, s.scene, s.detached, s.prompt, s.global, s.locked,
2585
+ ])
2586
+ }
2587
+ /**
2588
+ * 页面是否需要重取的指纹。
2589
+ *
2590
+ * 页面把 `revision` 当依赖(提示词 / 记忆页),而后台上拉只要写一次状态就会让修订号 +1:
2591
+ * 内容没变也重取,空列表会整块闪成「加载中」。所以修订号只在**内容真的变了**时推进。
2592
+ */
2593
+ function scopeContentSig(s) {
2594
+ return JSON.stringify([s.mode, s.overrides, s.effective, s.scene, s.detached, s.prompt, s.global, s.locked])
2561
2595
  }
2562
- function refreshScope() {
2596
+ /**
2597
+ * @param {object} [opts] 刷新选项。
2598
+ * @param opts.silent 后台刷新:不立 loading、失败不标错误、字段全等时不写状态。
2599
+ * 只有宿主会话清单变动这类非用户动作走它;用户切层 / 写回执仍走默认(可见)路径。
2600
+ */
2601
+ function refreshScope(opts) {
2563
2602
  if (scopeMounted === 0) return Promise.resolve()
2603
+ var silent = !!(opts && opts.silent)
2604
+ if (silent) scopeLastSilentAt = Date.now()
2564
2605
  var current = ''
2565
2606
  try { current = (typeof scopeDeps.currentSessionId === 'function' ? scopeDeps.currentSessionId() : '') || '' } catch (e) { current = '' }
2566
2607
  var seq = ++scopeRefreshSeq
2567
- setScopeState({ loading: true, error: null, currentSessionId: current })
2608
+ if (!silent) setScopeState({ loading: true, error: null, currentSessionId: current })
2568
2609
  // **只按 `sessionId` 取,不拿 `current` 兜底**:全局那一层给空 sessionId,拿的是
2569
2610
  // 全局快照(含意图三态与租约计数),与某个会话那一层同形。用当前会话兜底会把它的
2570
2611
  // `overrides` 与 `locked` 灌进全局层 —— 面板顶上就会挂着「本会话已锁定」。
@@ -2649,23 +2690,23 @@ button.dsm-rowselect-box:disabled{cursor:default;opacity:.45}
2649
2690
  sessionId: selected, mode: mode, currentSessionId: current, currentScopeKey: currentKey,
2650
2691
  followCurrent: false, workspaces: workspaces, options: options, groups: groups,
2651
2692
  })
2652
- return refreshScope()
2693
+ return refreshScope(opts)
2653
2694
  }
2654
2695
  return apiCall('scope-get', { sessionId: selected }).then(function (getRes) {
2655
2696
  // 已经有人发起了更新的一次(切了层 / 刚写完)→ 这一份是旧层的,整份丢掉。
2656
2697
  if (seq !== scopeRefreshSeq) return
2657
2698
  if (!getRes || getRes.ok === false) throw new Error(scopeErrorText(getRes))
2658
- setScopeState({
2699
+ var next = {
2659
2700
  loading: false,
2660
2701
  error: null,
2661
2702
  mode: mode,
2703
+ currentSessionId: current,
2662
2704
  currentScopeKey: currentKey,
2663
2705
  workspaces: workspaces,
2664
2706
  options: options,
2665
2707
  groups: groups,
2666
2708
  overrides: getRes.overrides || {},
2667
2709
  effective: getRes.effective || {},
2668
- revision: (Number(scopeState.revision) || 0) + 1,
2669
2710
  scene: typeof getRes.scene === 'string' ? getRes.scene : null,
2670
2711
  detached: getRes.detached === true,
2671
2712
  prompt: getRes.prompt && typeof getRes.prompt === 'object'
@@ -2673,11 +2714,20 @@ button.dsm-rowselect-box:disabled{cursor:default;opacity:.45}
2673
2714
  : { override: null, effective: '' },
2674
2715
  global: getRes.global || { scene: null, flags: {} },
2675
2716
  locked: getRes.locked === true,
2676
- })
2717
+ }
2718
+ var contentChanged = scopeContentSig(next) !== scopeContentSig(scopeState)
2719
+ // 后台上拉且一个字段都没变 → 不写状态。每次写都会让所有订阅页重渲染一遍,
2720
+ // 对话流式输出期间就是每帧一次(面板看着像在闪)。
2721
+ if (silent && !contentChanged && scopeVisibleSig(next) === scopeVisibleSig(scopeState) &&
2722
+ scopeState.loading !== true && scopeState.error === null) return
2723
+ next.revision = contentChanged ? (Number(scopeState.revision) || 0) + 1 : scopeState.revision
2724
+ setScopeState(next)
2677
2725
  })
2678
2726
  }).catch(function (e) {
2679
2727
  // 旧层的失败也不该把新层标成错误。
2680
2728
  if (seq !== scopeRefreshSeq) return
2729
+ // 后台上拉失败不把面板标成读不到:下一次成功会自己清掉,页面那份提示仍在。
2730
+ if (silent && scopeState.loading !== true) return
2681
2731
  setScopeState({ loading: false, error: errMsg(e) })
2682
2732
  })
2683
2733
  }
@@ -2701,13 +2751,13 @@ button.dsm-rowselect-box:disabled{cursor:default;opacity:.45}
2701
2751
  if (!following) {
2702
2752
  setScopeState({ currentSessionId: next })
2703
2753
  // 下拉里「当前对话」那一项 / 它的标题可能变了:重拉一次会话清单(全局层不取覆盖)。
2704
- refreshScope()
2754
+ refreshScope({ silent: true })
2705
2755
  return
2706
2756
  }
2707
2757
  // 新工作区键要等服务端按 cwd 算出来 —— 置 followCurrent,refreshScope 取完列表后会
2708
2758
  // 把选中层换到 currentKey 并用新键重取一次,不拿旧层数据冒充新层。
2709
2759
  setScopeState({ currentSessionId: next, followCurrent: true, overrides: {}, effective: {}, scene: null, detached: false, locked: false, prompt: { override: null, effective: '' } })
2710
- refreshScope()
2760
+ refreshScope({ silent: true })
2711
2761
  }
2712
2762
  /** 一行会话选项:标题进正文,覆盖条数与「当前」放行尾。 */
2713
2763
  function scopeSessionOption(row, current) {
@@ -2894,6 +2944,32 @@ button.dsm-rowselect-box:disabled{cursor:default;opacity:.45}
2894
2944
  function scopeClearWriteError() {
2895
2945
  if (scopeState.writeError !== null) setScopeState({ writeError: null })
2896
2946
  }
2947
+ /**
2948
+ * 隔离损坏的作用域侧车(`scope-repair`)。
2949
+ *
2950
+ * 只改名、不覆盖:损坏文件留在 hub 里供事后查看,覆盖表/意图表按空表继续。
2951
+ * 调用方(ScopeBar)负责二次确认 —— 这是把用户设置退回默认的动作。
2952
+ */
2953
+ function scopeRepair() {
2954
+ return apiCall('scope-repair', {}).then(function (res) {
2955
+ if (!res || res.ok !== true) {
2956
+ scopeDeps.toast(scopeT('scope.repair.failed', { error: scopeErrorText(res) || '?' }), 'err')
2957
+ return res
2958
+ }
2959
+ var files = []
2960
+ if (res.scopeQuarantined) files.push('scope-overrides.json')
2961
+ if (res.intentQuarantined) files.push('scope-intent.json')
2962
+ scopeDeps.toast(files.length
2963
+ ? scopeT('scope.repair.done', { files: files.join(' / ') })
2964
+ : scopeT('scope.repair.none'), files.length ? 'ok' : 'warn')
2965
+ scopeClearWriteError()
2966
+ refreshScope({ silent: true })
2967
+ return res
2968
+ }).catch(function (e) {
2969
+ scopeDeps.toast(scopeT('scope.repair.failed', { error: errMsg(e) }), 'err')
2970
+ return { ok: false, error: errMsg(e) }
2971
+ })
2972
+ }
2897
2973
  /**
2898
2974
  * 锁 / 解锁**本会话**(0.21.2,决策 12)。只在会话层成立:
2899
2975
  * 锁冻结的是这个会话自己的覆盖写入,与场景锁(全局写)互不干扰。
@@ -2925,6 +3001,13 @@ button.dsm-rowselect-box:disabled{cursor:default;opacity:.45}
2925
3001
  function ScopeBar(props) {
2926
3002
  var t = props.t
2927
3003
  var snap = React.useSyncExternalStore(subscribeScope, scopeSnapshot, scopeSnapshot)
3004
+ // 修复是破坏性动作:第一次点只切到「确认」,第二次才执行。
3005
+ var ra = React.useState(false)
3006
+ var repairArmed = ra[0], setRepairArmed = ra[1]
3007
+ // 错误消失(修复成功 / 用户点掉)后别让下一次错误直接落在「确认」态。
3008
+ React.useEffect(function () {
3009
+ if (!snap.writeError) setRepairArmed(false)
3010
+ }, [snap.writeError])
2928
3011
  // 首次挂载拉一次:面板一打开就要知道"我在哪一层"。失败不阻塞页面(下拉仍在,只是选项少)。
2929
3012
  // **每次挂载都拉**:设置页与侧栏入口是两个挂载点,切页签又会让页面重新挂载;
2930
3013
  // 只在模块作用域缓存一份的话,别处写进去的覆盖要等下一次下拉操作才看得见。
@@ -2980,6 +3063,18 @@ button.dsm-rowselect-box:disabled{cursor:default;opacity:.45}
2980
3063
  snap.writeError
2981
3064
  ? h('div', { key: 'writeerr', className: 'dsm-scope-bar-error', role: 'alert' }, [
2982
3065
  h('span', { key: 'text' }, String(snap.writeError)),
3066
+ // 损坏的侧车没有别的恢复入口:写入会一直失败。修复只隔离现场,不覆盖健康文件。
3067
+ h('button', {
3068
+ key: 'repair',
3069
+ type: 'button',
3070
+ className: 'dsm-btn dsm-btn-quiet',
3071
+ title: scopeT('scope.repair.hint'),
3072
+ onClick: function () {
3073
+ if (!repairArmed) { setRepairArmed(true); return }
3074
+ setRepairArmed(false)
3075
+ scopeRepair()
3076
+ },
3077
+ }, repairArmed ? scopeT('scope.repair.confirm') : scopeT('scope.repair.action')),
2983
3078
  h('button', { key: 'x', type: 'button', className: 'dsm-btn dsm-btn-quiet', onClick: function () { scopeClearWriteError() } }, scopeT('scope.warn.dismiss')),
2984
3079
  ])
2985
3080
  : null,
@@ -5939,6 +6034,14 @@ button.dsm-rowselect-box:disabled{cursor:default;opacity:.45}
5939
6034
  // 有兼容更新时那颗键**外观不变**(只多一个红点),但无障碍名换成「更新」——
5940
6035
  // 读屏该读到"有更新",而不是泛泛的"检查"。
5941
6036
  "update.action": "更新",
6037
+ // 升级入口只给命令,不在界面内安装:插件不能自我安装,宿主也没有更新已装插件的接口。
6038
+ // 命令里的版本由服务端固定,不出现 @latest。
6039
+ "update.install.open": "查看升级命令", "update.install.title": "升级到 {version}",
6040
+ "update.install.body": "插件不能自我安装,宿主也没有“更新已装插件”的接口。复制下面的命令到终端执行(当前 {current},命令固定到 {version},不会使用 @latest),完成后重启 DSH。",
6041
+ "update.install.after": "命令执行完再重启 DSH:运行中的仍是旧版本。",
6042
+ "update.install.copy": "复制命令", "update.install.copied": "已复制升级命令",
6043
+ "update.install.copyFailed": "复制失败,请手动选中命令复制",
6044
+ "update.install.noCommand": "这次检查没有给出可执行的命令,请重新点一次检查更新。",
5942
6045
  "compat.diag.copy": "复制诊断信息", "compat.diag.copied": "已复制诊断信息",
5943
6046
  "compat.host": "宿主版本", "compat.verified": "插件适配版本",
5944
6047
  "compat.caps": "可用能力", "compat.caps.degraded": "{count} 项不可用",
@@ -6535,6 +6638,11 @@ button.dsm-rowselect-box:disabled{cursor:default;opacity:.45}
6535
6638
  "scope.view.lease": "{count} 个对话单独设置",
6536
6639
  "scope.view.leaseHint": "全局是关的,但还有 {count} 个对话单独把它拨开了 —— 这只影响它们各自看到的内容,全局设置没变。",
6537
6640
  "scope.warn.dismiss": "知道了",
6641
+ "scope.repair.action": "修复作用域文件", "scope.repair.confirm": "确认隔离损坏文件(设置回到默认)",
6642
+ "scope.repair.hint": "仅在作用域侧车损坏时使用:损坏的文件会改名留存,覆盖表与全局意图回到默认,下一次对账会从运行态反推。",
6643
+ "scope.repair.done": "已隔离 {files},相关设置回到默认;损坏文件保留在 hub 里。",
6644
+ "scope.repair.none": "作用域侧车文件正常,无需修复。",
6645
+ "scope.repair.failed": "修复失败:{error}",
6538
6646
  "scope.intent.globalOnly": "全局意图只能在全局层修改",
6539
6647
  "scope.intent.blocked": "已统一关闭", "scope.intent.blockedHint": "全局已「统一关闭」:任何会话都不能再用它(包括在会话层打开)。要恢复,先在全局改回启用。",
6540
6648
  "scope.intent.lease": "临时运行 · {count} 个对话", "scope.intent.leaseHint": "全局是关的,但还有 {count} 个对话在用它 —— 它保持启用,只有这些对话看得到。",
@@ -6838,6 +6946,12 @@ button.dsm-rowselect-box:disabled{cursor:default;opacity:.45}
6838
6946
  "update.check": "Check for updates", "update.checking": "Checking for updates…", "update.recheck": "Click to check again",
6839
6947
  "update.failed": "Update check failed: {error}",
6840
6948
  "update.action": "Update",
6949
+ "update.install.open": "View upgrade command", "update.install.title": "Upgrade to {version}",
6950
+ "update.install.body": "The plugin cannot install itself, and the host exposes no 'update installed plugin' API. Copy the command below into a terminal (you are on {current}; it is pinned to {version}, never @latest), then restart DSH.",
6951
+ "update.install.after": "Restart DSH after running the command; the running copy is still the old version.",
6952
+ "update.install.copy": "Copy command", "update.install.copied": "Upgrade command copied",
6953
+ "update.install.copyFailed": "Copy failed; select the command and copy it manually",
6954
+ "update.install.noCommand": "This check produced no runnable command; check for updates again.",
6841
6955
  "compat.diag.copy": "Copy diagnostics", "compat.diag.copied": "Diagnostics copied",
6842
6956
  "compat.host": "Host version", "compat.verified": "Verified against",
6843
6957
  "compat.caps": "Usable capabilities", "compat.caps.degraded": "{count} unavailable",
@@ -7418,6 +7532,11 @@ button.dsm-rowselect-box:disabled{cursor:default;opacity:.45}
7418
7532
  "scope.view.lease": "set in {count} chats",
7419
7533
  "scope.view.leaseHint": "Off globally, but {count} conversation(s) switched it on for themselves — that only changes what they see; the global setting is unchanged.",
7420
7534
  "scope.warn.dismiss": "Dismiss",
7535
+ "scope.repair.action": "Repair scope files", "scope.repair.confirm": "Quarantine the corrupt file (settings reset to defaults)",
7536
+ "scope.repair.hint": "Only for corrupt scope sidecars: the corrupt file is renamed and kept, per-conversation overrides and global intent reset to defaults, and the next reconcile adopts the running state.",
7537
+ "scope.repair.done": "Quarantined {files}; related settings are back to defaults. The corrupt file is kept in the hub.",
7538
+ "scope.repair.none": "The scope sidecars are healthy; nothing to repair.",
7539
+ "scope.repair.failed": "Repair failed: {error}",
7421
7540
  "scope.intent.globalOnly": "Global intent can only be changed from the global layer",
7422
7541
  "scope.intent.blocked": "closed everywhere", "scope.intent.blockedHint": "Closed globally: no conversation can use it, even by switching it on locally. Set it back to on/off globally to allow it again.",
7423
7542
  "scope.intent.lease": "temporary · {count} conversation(s)", "scope.intent.leaseHint": "Off globally, but {count} conversation(s) still use it — it stays enabled and only they see it.",
@@ -7623,6 +7742,7 @@ button.dsm-rowselect-box:disabled{cursor:default;opacity:.45}
7623
7742
  t: t,
7624
7743
  currentSessionId: currentSessionId,
7625
7744
  subscribeSessionList: subscribeSessionList,
7745
+ toast: showPluginToast,
7626
7746
  })
7627
7747
  /**
7628
7748
  * 一次性「服务点名」:锁挂不上时把几个关键服务在**本插件上下文里**的可见性一起写出来。
@@ -8084,20 +8204,33 @@ button.dsm-rowselect-box:disabled{cursor:default;opacity:.45}
8084
8204
  // · GitHub 图标——原样保留,仓库入口一个都不能少。
8085
8205
  //
8086
8206
  // 交互约定:
8087
- // · 点击 = 查一次(只读 op `update-status` + `refresh:true`)—— 不安装、不改配置、
8088
- // 不碰 `@latest`,`update-check.ts` 那几条硬约束照旧。插件跑在宿主的
8089
- // node_modules 里,装不了自己 —— 这颗键**不许**承诺自动更新;
8090
- // · 答案用 toast 说,不弹窗:它是一句话结论,弹窗要压暗整页、还得再点一次才关。
8207
+ // · 没有更新时点击 = 查一次(只读 op `update-status` + `refresh:true`);
8208
+ // · 有更新时点击 = 打开升级卡,展示**固定版本**的 CLI 命令供复制。
8209
+ // 插件跑在宿主的 node_modules 里,不能自我安装;宿主也没有"更新已装插件"的接口
8210
+ // (`installBundle` 对已在 profile 依赖里的包在 HMR 下必拒),所以这里只给命令,
8211
+ // 不承诺在界面内完成安装,也不出现 `@latest`。
8212
+ // · 检查结论用 toast 说(一句话结论,不必弹窗);只有要给人抄命令时才弹卡。
8091
8213
  //
8092
- // 结果存**会话级**(`updateProbe`):设置面板每次打开都会重挂本组件,重挂不该把「更新」
8093
- // 抹掉,也不该每次都去读一遍盘。
8214
+ // 结果存**会话级**(`updateProbe`):设置面板每次打开都会重挂本组件,重挂不该把
8215
+ // 「更新」抹掉,也不该每次都去读一遍盘。
8094
8216
  var updateProbe = { info: null, asked: false }
8095
8217
 
8096
8218
  function FeedbackLinks() {
8097
8219
  var st = React.useState({ busy: false, info: updateProbe.info })
8098
8220
  var state = st[0], setState = st[1]
8221
+ var co = React.useState(false)
8222
+ var cardOpen = co[0], setCardOpen = co[1]
8223
+ var cp = React.useState(false)
8224
+ var copied = cp[0], setCopied = cp[1]
8099
8225
  var busy = state.busy === true
8100
8226
  var info = state.info
8227
+ var hasUpdate = !!info && String(info.status || '') === 'update-available'
8228
+ var targetVersion = String((info && info.bestCompatible) || '')
8229
+ // 服务端按当前 profile 拼好的命令;缓存读数读到 old cache 时也会重建(见 update-check.ts)。
8230
+ var command = String((info && info.command) || '')
8231
+
8232
+ // 只改给到的字段:补读数 / 检查两路异步回填不能互相覆盖。
8233
+ var patch = function (next) { setState(function (prev) { return Object.assign({}, prev, next) }) }
8101
8234
 
8102
8235
  // 挂载时补一次缓存读数(不带 refresh):服务端启动时预热过,这一次通常零网络,
8103
8236
  // 只是把盘上 `update-check.json` 的结论先摆上来。读不到 = 少一个「更新」标记,不报错。
@@ -8109,61 +8242,111 @@ button.dsm-rowselect-box:disabled{cursor:default;opacity:.45}
8109
8242
  if (!r || !r.ok) return
8110
8243
  updateProbe.info = r
8111
8244
  // 用户已经自己点过一次(拿到的是更新的结果)就不覆盖。
8112
- if (alive) setState(function (prev) { return prev.info ? prev : { busy: prev.busy, info: r } })
8245
+ if (alive) setState(function (prev) { return prev.info ? prev : Object.assign({}, prev, { info: r }) })
8113
8246
  }).catch(function () { /* 静默:这个标记只是便利,不是结论 */ })
8114
8247
  return function () { alive = false }
8115
8248
  }, [])
8116
8249
 
8117
- var hasUpdate = !!info && String(info.status || '') === 'update-available'
8118
-
8119
8250
  var check = function () {
8120
8251
  if (busy) return
8121
- setState({ busy: true, info: info })
8252
+ patch({ busy: true })
8122
8253
  // `refresh:true`:点这一下就是要一个**现在**的答案。读 12 小时前的缓存等于骗人
8123
8254
  // ——「已是最新」可能是在某个版本发布之前算出来的。
8124
8255
  apiCall('update-status', { refresh: true }).then(function (r) {
8125
8256
  if (!r || !r.ok) throw new Error(String((r && r.error) || t('compat.update.unknown')))
8126
8257
  updateProbe.info = r
8127
- setState({ busy: false, info: r })
8258
+ patch({ busy: false, info: r })
8128
8259
  var s = String(r.status || 'unknown')
8129
8260
  showPluginToast(updateStatusText(r, t), s === 'up-to-date' ? 'ok' : 'warn')
8130
8261
  }).catch(function (e) {
8131
- setState({ busy: false, info: info })
8262
+ patch({ busy: false })
8132
8263
  showPluginToast(t('update.failed', { error: errMsg(e) }), 'err')
8133
8264
  })
8134
8265
  }
8135
8266
 
8136
- // 标题就是"这一下会做什么":没有答案时是"查一次",有答案时是"再查一遍"。
8267
+ /**
8268
+ * 复制升级命令。命令由服务端按当前 profile 拼好(固定版本),这里只负责放进剪贴板。
8269
+ * 剪贴板不可用时命令仍显示在卡里,用户可以直接选中复制。
8270
+ */
8271
+ var copyCommand = function () {
8272
+ if (command === '') return
8273
+ var done = function () {
8274
+ setCopied(true)
8275
+ showPluginToast(t('update.install.copied'), 'ok')
8276
+ }
8277
+ var fail = function () { showPluginToast(t('update.install.copyFailed'), 'err') }
8278
+ try {
8279
+ if (navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
8280
+ navigator.clipboard.writeText(command).then(done, fail)
8281
+ return
8282
+ }
8283
+ } catch (e) { /* 落到下面的失败提示 */ }
8284
+ fail()
8285
+ }
8286
+
8287
+ var onUpdateClick = function () {
8288
+ if (busy) return
8289
+ if (hasUpdate) { setCopied(false); setCardOpen(true); return }
8290
+ check()
8291
+ }
8292
+
8293
+ // 标题就是"这一下会做什么":没答案时"查一次",有答案时"再查一遍",
8294
+ // 有更新时"查看升级命令"。
8137
8295
  var tip = busy ? t('update.checking')
8138
- : info ? updateStatusText(info, t) + ' · ' + t('update.recheck')
8139
- : t('update.check')
8140
- return React.createElement('div', { className: 'dsm-feedback-links' },
8141
- // 版本号在最左:它回答的是"我现在装的是哪个版本",与右边两颗键各自回答的问题不同,
8142
- // 所以不并进按钮文字里(并进去就成了"要变成哪个版本",两件事会混)。
8143
- React.createElement(VersionBadgeComponent, null),
8144
- React.createElement('button', {
8145
- type: 'button',
8146
- // 永远是同一颗图标键(用户 2026-10-22:不必在有更新时多出「更新」二字)——
8147
- // 有更新只多一个红点,宽度不变,这一行也就不会因为状态变化而抖一下。
8148
- className: 'dsm-feedback-link dsm-feedback-check' + (busy ? ' dsm-feedback-link-busy' : ''),
8149
- 'aria-label': hasUpdate ? t('update.action') : t('update.check'),
8150
- 'aria-busy': busy ? 'true' : 'false',
8151
- title: tip,
8152
- onClick: check,
8153
- },
8154
- React.createElement(UpdateMark16, null),
8155
- // 有新版本时右上角挂一个小红点:这是这一簇里唯一"扫一眼就看见"的信号,
8156
- // 图标本身不随状态变(文字在窄面板下还会被挤掉)。
8157
- hasUpdate ? React.createElement('span', { className: 'dsm-feedback-dot', 'aria-hidden': 'true' }) : null),
8158
- React.createElement('a', {
8159
- className: 'dsm-feedback-link',
8160
- href: 'https://github.com/ouli-1242/dsh-plugin-tool-management',
8161
- target: '_blank',
8162
- rel: 'noreferrer',
8163
- 'aria-label': t('link.project'),
8164
- title: t('link.project'),
8296
+ : hasUpdate ? updateStatusText(info, t) + ' · ' + t('update.install.open')
8297
+ : info ? updateStatusText(info, t) + ' · ' + t('update.recheck')
8298
+ : t('update.check')
8299
+ var label = hasUpdate ? t('update.action') : t('update.check')
8300
+ return React.createElement(React.Fragment, null,
8301
+ React.createElement('div', { className: 'dsm-feedback-links' },
8302
+ // 版本号在最左:它回答的是"我现在装的是哪个版本",与右边两颗键各自回答的问题不同,
8303
+ // 所以不并进按钮文字里(并进去就成了"要变成哪个版本",两件事会混)。
8304
+ React.createElement(VersionBadgeComponent, null),
8305
+ React.createElement('button', {
8306
+ type: 'button',
8307
+ // 永远是同一颗图标键(用户 2026-10-22:不必在有更新时多出「更新」二字)——
8308
+ // 有更新只多一个红点,宽度不变,这一行也就不会因为状态变化而抖一下。
8309
+ className: 'dsm-feedback-link dsm-feedback-check' + (busy ? ' dsm-feedback-link-busy' : ''),
8310
+ 'aria-label': label,
8311
+ 'aria-busy': busy ? 'true' : 'false',
8312
+ title: tip,
8313
+ onClick: onUpdateClick,
8314
+ },
8315
+ React.createElement(UpdateMark16, null),
8316
+ hasUpdate ? React.createElement('span', { className: 'dsm-feedback-dot', 'aria-hidden': 'true' }) : null),
8317
+ React.createElement('a', {
8318
+ className: 'dsm-feedback-link',
8319
+ href: 'https://github.com/ouli-1242/dsh-plugin-tool-management',
8320
+ target: '_blank',
8321
+ rel: 'noreferrer',
8322
+ 'aria-label': t('link.project'),
8323
+ title: t('link.project'),
8324
+ },
8325
+ React.createElement(GithubMark16, null))),
8326
+ cardOpen ? React.createElement(Modal, {
8327
+ title: t('update.install.title', { version: targetVersion }),
8328
+ closeLabel: t('btn.close'),
8329
+ onClose: function () { setCardOpen(false) },
8330
+ className: 'dsm-modal-sm',
8165
8331
  },
8166
- React.createElement(GithubMark16, null)))
8332
+ React.createElement('p', { className: 'dsm-help' }, t('update.install.body', {
8333
+ current: String((info && info.current) || '?'),
8334
+ version: targetVersion,
8335
+ })),
8336
+ command !== ''
8337
+ ? React.createElement('pre', { className: 'dsm-code' }, command)
8338
+ : React.createElement('p', { className: 'dsm-help' }, t('update.install.noCommand')),
8339
+ React.createElement('div', { className: 'dsm-feedback dsm-warning' }, t('update.install.after')),
8340
+ React.createElement('div', { className: 'dsm-modal-actions' },
8341
+ React.createElement('button', {
8342
+ type: 'button', className: 'dsm-btn dsm-btn-secondary',
8343
+ onClick: function () { setCardOpen(false) },
8344
+ }, t('btn.close')),
8345
+ React.createElement('button', {
8346
+ type: 'button', className: 'dsm-btn', disabled: command === '',
8347
+ onClick: copyCommand,
8348
+ }, copied ? t('update.install.copied') : t('update.install.copy'))))
8349
+ : null)
8167
8350
  }
8168
8351
 
8169
8352
  // MCP 服务页:与 Skills 页共用 dsm-* 设计语言(统计卡 / 筛选 / 分组卡片 / 模态框)。
@@ -0,0 +1,121 @@
1
+ // hub 级跨进程写锁。
2
+ //
3
+ // 为什么需要:DSH 的 web 与 desktop 是两个宿主进程,却共用同一个 `$DSH_HOME`。apply 里那条
4
+ // `writeChain` 只能串行**同一进程**的写入;两个进程同时读-改-写同一份侧车时,后写的会覆盖
5
+ // 先写的(停用表、作用域覆盖、工具表都是整份写)。这里用 hub 根下的 `.write.lock` 做第二层。
6
+ //
7
+ // 锁文件不常开:写入 pid / 时间 / 随机 token 后立即关闭;临界区结束时按 token 删除。持锁期间
8
+ // 每 5 秒 touch 一次 mtime,心跳停了超过 `staleMs` 才允许别的进程抢占。这样进程崩溃留下的锁
9
+ // 最多挡一分钟,不会永久锁死 hub。
10
+ import { mkdir, open, readFile, stat, unlink, utimes } from 'node:fs/promises';
11
+ import { join } from 'node:path';
12
+ import { randomUUID } from 'node:crypto';
13
+ /** 锁文件名(hub 根;点开头,迁移与备份都不认识它)。 */
14
+ export const HUB_LOCK_FILE = '.write.lock';
15
+ /** 等锁的上限:超过就报错,不无限挂住一次面板写入。 */
16
+ const DEFAULT_TIMEOUT_MS = 30_000;
17
+ /** 没有心跳多久算死锁。必须明显大于心跳间隔,给一次长写入留余量。 */
18
+ const DEFAULT_STALE_MS = 60_000;
19
+ /** 心跳间隔:touch 锁文件 mtime。 */
20
+ const HEARTBEAT_MS = 5_000;
21
+ /** 等锁的重试间隔(带少量随机抖动,避免两个进程同步醒来反复撞)。 */
22
+ const RETRY_MS = 25;
23
+ /** 读锁文件的内容与 mtime;不存在 / 读不动返回 null。 */
24
+ async function readLock(path) {
25
+ try {
26
+ const [raw, info] = await Promise.all([readFile(path, 'utf8'), stat(path)]);
27
+ let parsed = null;
28
+ try {
29
+ const obj = JSON.parse(raw);
30
+ if (typeof obj.pid === 'number' && typeof obj.at === 'number' && typeof obj.token === 'string') {
31
+ parsed = { pid: obj.pid, at: obj.at, token: obj.token };
32
+ }
33
+ }
34
+ catch { /* 刚创建还没写完 / 坏内容:按"有锁但读不懂"处理 */ }
35
+ return { info: parsed, mtime: info.mtimeMs };
36
+ }
37
+ catch {
38
+ return null;
39
+ }
40
+ }
41
+ /** 进程还在吗:`EPERM` 表示存在但没权限发信号,按活着算。 */
42
+ function processAlive(pid) {
43
+ if (!Number.isInteger(pid) || pid <= 0)
44
+ return false;
45
+ try {
46
+ process.kill(pid, 0);
47
+ return true;
48
+ }
49
+ catch (e) {
50
+ return e?.code === 'EPERM';
51
+ }
52
+ }
53
+ /**
54
+ * 建一把 hub 文件锁。
55
+ *
56
+ * @param dir hub 根目录(`$DSH_HOME/tool-management`);不存在时首次等锁会创建
57
+ * @param options 超时与死锁阈值(测试可缩短)
58
+ */
59
+ export function createHubFileLock(dir, options = {}) {
60
+ const path = join(dir, HUB_LOCK_FILE);
61
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
62
+ const staleMs = options.staleMs ?? DEFAULT_STALE_MS;
63
+ /** 尝试拿锁;拿不到返回 false,拿到后由调用方持有。 */
64
+ async function tryAcquire(token) {
65
+ try {
66
+ const handle = await open(path, 'wx');
67
+ try {
68
+ await handle.writeFile(JSON.stringify({ pid: process.pid, at: Date.now(), token }), 'utf8');
69
+ }
70
+ finally {
71
+ await handle.close();
72
+ }
73
+ return true;
74
+ }
75
+ catch (e) {
76
+ if (e?.code !== 'EEXIST')
77
+ throw e;
78
+ const seen = await readLock(path);
79
+ if (seen === null)
80
+ return false; // 刚被删;下一轮重试即可
81
+ const age = Date.now() - seen.mtime;
82
+ if (seen.info !== null && processAlive(seen.info.pid) && age < staleMs)
83
+ return false;
84
+ // 进程已死 / 心跳过期 / 内容读不懂:只删我们看到的那一份,避免误删别人刚建的新锁。
85
+ const again = await readLock(path);
86
+ if (again !== null && (seen.info === null || again.info?.token === seen.info.token)) {
87
+ await unlink(path).catch(() => undefined);
88
+ }
89
+ return false;
90
+ }
91
+ }
92
+ return {
93
+ async run(fn) {
94
+ await mkdir(dir, { recursive: true });
95
+ const token = randomUUID();
96
+ const started = Date.now();
97
+ for (;;) {
98
+ if (await tryAcquire(token))
99
+ break;
100
+ if (Date.now() - started > timeoutMs) {
101
+ throw new Error('另一个 DSH 进程正在写同一个数据目录,等待超时;请稍后重试,或只保留一个宿主进程。');
102
+ }
103
+ await new Promise((resolve) => setTimeout(resolve, RETRY_MS + Math.floor(Math.random() * RETRY_MS)));
104
+ }
105
+ const beat = setInterval(() => {
106
+ // 心跳失败(文件被删 / 被抢占)不打断临界区:释放时还会按 token 再确认一次。
107
+ void utimes(path, new Date(), new Date()).catch(() => undefined);
108
+ }, HEARTBEAT_MS);
109
+ beat.unref();
110
+ try {
111
+ return await fn();
112
+ }
113
+ finally {
114
+ clearInterval(beat);
115
+ const seen = await readLock(path);
116
+ if (seen?.info?.token === token)
117
+ await unlink(path).catch(() => undefined);
118
+ }
119
+ },
120
+ };
121
+ }