dsh-recall-plugin 1.0.1 → 1.0.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/README.md CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
  - **文件 + 对话,整段回退**:撤回的不只是聊天记录,agent 改过的文件也一并回到原样。
28
28
  - **不碰你项目自己的 git**:快照存在独立的影子 git 仓库里,你的分支、暂存区、未提交改动统统不受影响;`.git`、`node_modules` 自动排除。
29
- - **项目目录保持干净**:快照始终存在 `$DSH_HOME` 下,不会往项目里塞任何东西;与会话的沙箱权限无关(workspace-write / read-only 会话照常快照与回退),仅当 home 本身不可写(如指到只读盘)才降级到项目内 `.dsh-recall-snapshots`,home 恢复后自动迁走、清理干净。
29
+ - **项目目录保持干净**:快照始终存在 `$DSH_HOME` 下,不会往项目里塞任何东西;与会话的沙箱权限无关(workspace-write / read-only 会话照常快照与回退),仅当 home 本身不可写(如指到只读盘)才降级到项目内 `.dsh-recall-snapshots`(降级时页面会提示),home 恢复后自动迁走、清理干净。
30
30
  - **可以反复后悔**:快照全量保留、永不修剪。撤回一次后还能再撤到更早;撤回时被覆盖的文件也一直找得回来。
31
31
  - **先看清单再动手**:点撤回先弹出将变更的文件清单(修改 / 恢复 / 删除),确认后才执行,不会稀里糊涂覆盖。
32
32
  - **磁盘友好**:快照走 git delta 压缩,是增量不是整目录拷贝;超过 100MB 的大文件自动跳过。
@@ -40,7 +40,7 @@
40
40
 
41
41
  ## 安装
42
42
 
43
- 前置:Windows + git CLI(未装 git 时插件静默降级,不显示撤回按钮,不影响 DSH 运行);PowerShell 5.1 / 7 均可;DSH 0.1.0-rc.x(依赖版本见 `peerDependencies`)。
43
+ 前置:Windows + git CLI(未装 git 时撤回按钮不出现,页面顶部会提示安装 git,不影响 DSH 运行);PowerShell 5.1 / 7 均可;DSH 0.1.0-rc.x(依赖版本见 `peerDependencies`)。
44
44
 
45
45
 
46
46
  - DSH 官方插件命令:安装并自动挂载进 web profile
package/lib/client.js CHANGED
@@ -59,7 +59,10 @@ window.__ModuleLoader__.load({
59
59
  '.dsh-recall-btn{border:none;border-radius:8px;padding:5px 14px;font-size:13px;line-height:20px;cursor:pointer;color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-interactive-bg-hover)}',
60
60
  '.dsh-recall-btn:hover{color:var(--dsw-alias-label-primary)}',
61
61
  '.dsh-recall-btn-danger{background:var(--dsw-alias-state-error-primary);color:#fff}',
62
- '.dsh-recall-btn-danger:hover{color:#fff;filter:brightness(1.08)}'
62
+ '.dsh-recall-btn-danger:hover{color:#fff;filter:brightness(1.08)}',
63
+ '.dsh-recall-toast{position:fixed;top:18px;left:50%;transform:translateX(-50%);z-index:10000;max-width:min(560px,86vw);box-sizing:border-box;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary);border:1px solid var(--dsw-alias-border-l2);border-radius:12px;padding:10px 16px;font-size:13px;line-height:20px;box-shadow:0 8px 28px rgba(0,0,0,.22);display:flex;align-items:baseline;gap:8px;opacity:0;transition:opacity .25s ease;pointer-events:auto}',
64
+ '.dsh-recall-toast.dsh-recall-toast-in{opacity:1}',
65
+ '.dsh-recall-toast-tag{flex:none;font-weight:600;color:var(--dsw-alias-state-error-primary)}'
63
66
  ].join('')
64
67
  // 静态 bundle 的 ctx 可能不提供 styles 服务,降级为直接注入 <style>
65
68
  const stylesSvc = ctx.get('styles')
@@ -75,6 +78,37 @@ window.__ModuleLoader__.load({
75
78
  let initedSessionId = null
76
79
  let initDone = Promise.resolve()
77
80
 
81
+ // 降级提示:每个种类每次页面加载只弹一次(Set 去重),避免切会话时
82
+ // 反复打扰。纯 DOM 直插(与剪贴板同样的零依赖思路),7 秒后自动淡出。
83
+ const noticeShown = new Set()
84
+ function showNotice(kind, text) {
85
+ if (noticeShown.has(kind) || typeof document === 'undefined') return
86
+ noticeShown.add(kind)
87
+ try {
88
+ const el = document.createElement('div')
89
+ el.className = 'dsh-recall-toast'
90
+ const tag = document.createElement('span')
91
+ tag.className = 'dsh-recall-toast-tag'
92
+ tag.textContent = '撤回插件'
93
+ const body = document.createElement('span')
94
+ body.textContent = text
95
+ el.appendChild(tag)
96
+ el.appendChild(body)
97
+ el.addEventListener('click', () => dismiss(), { once: true })
98
+ document.body.appendChild(el)
99
+ requestAnimationFrame(() => el.classList.add('dsh-recall-toast-in'))
100
+ const timer = setTimeout(dismiss, 7000)
101
+ let dismissed = false
102
+ function dismiss() {
103
+ if (dismissed) return
104
+ dismissed = true
105
+ clearTimeout(timer)
106
+ el.classList.remove('dsh-recall-toast-in')
107
+ setTimeout(() => el.remove(), 300)
108
+ }
109
+ } catch (e) { /* 提示失败不影响主流程 */ }
110
+ }
111
+
78
112
  // 每个会话只向 Host 注册一次(预热其根目录解析缓存)。
79
113
  // 返回 init 的 promise:Host 端 init 要跑数条 PowerShell(建仓/loadIndex),
80
114
  // snapshot-info 必须等它完成后再查,否则冷启动时索引尚未载入会误判
@@ -82,7 +116,15 @@ window.__ModuleLoader__.load({
82
116
  function ensureInit(sessionId) {
83
117
  if (!sessionId || initedSessionId === sessionId) return initDone
84
118
  initedSessionId = sessionId
85
- initDone = api('init', { sessionId }).catch(() => {})
119
+ initDone = api('init', { sessionId }).then((res) => {
120
+ const notice = res && res.notice
121
+ if (notice && notice.gitMissing) {
122
+ showNotice('git', '未检测到 git CLI,撤回功能不可用(快照引擎依赖 git)。安装 git 并重启 DSH 后即可使用。')
123
+ }
124
+ if (notice && notice.homeFallback) {
125
+ showNotice('home', 'home 目录不可写,快照已降级存储到项目内 .dsh-recall-snapshots 目录。')
126
+ }
127
+ }).catch(() => {})
86
128
  return initDone
87
129
  }
88
130
 
package/lib/index.js CHANGED
@@ -570,6 +570,7 @@ export function apply(ctx) {
570
570
  if (name === 'init') {
571
571
  const sessionId = args && args.sessionId ? String(args.sessionId) : null
572
572
  const root = await resolveRoot(sessionId)
573
+ let notice = null
573
574
  if (root) {
574
575
  let store = await resolveStore(root, sessionId)
575
576
  store = await tryUpgradeToHome(root, sessionId)
@@ -577,8 +578,15 @@ export function apply(ctx) {
577
578
  await loadIndex(root, sessionId)
578
579
  await rebuildOrphans(root, sessionId)
579
580
  cleanupLegacy(root, sessionId)
581
+ // 降级状态随 init 下发,Client 弹一次性提示(每次页面加载各弹一次):
582
+ // gitMissing=未检测到 git CLI(撤回按钮不出现);homeFallback=home
583
+ // 不可写,快照降级存进项目内 .dsh-recall-snapshots。
584
+ notice = {
585
+ gitMissing: state.gitExe === '',
586
+ homeFallback: store ? !store.home : false
587
+ }
580
588
  }
581
- sendJson(res, 200, { ok: Boolean(root), root: root || null })
589
+ sendJson(res, 200, { ok: Boolean(root), root: root || null, notice })
582
590
  return
583
591
  }
584
592
  if (name === 'snapshot-info') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-recall-plugin",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "DSH 消息撤回插件:在用户消息气泡旁加「撤回」按钮,把项目文件(独立影子 git 仓库快照)与对话历史(官方 fork)一并回退到该消息发送之前。",
5
5
  "type": "module",
6
6
  "repository": {