@240xu/dsh-message-ops 0.3.2 → 0.4.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
@@ -188,3 +188,13 @@ MIT
188
188
  回退路径的 SVG 也改为官方 IconClockOutline/IconTrashOutline 的精确 path 数据
189
189
  (1px stroke,与 Regular 变体一致),不再手绘。
190
190
  - 字典文案去 emoji(label 仅用于 tooltip/aria,不参与渲染)。
191
+
192
+ ### 0.4.0 · opencode 式回撤深化(composer 回填 + 回撤 dock)
193
+
194
+ - **Composer 回填**:回滚**用户消息**后,原文经官方 `InputActions.setDraft`
195
+ 自动回填输入框——「编辑重发」零按钮(opencode 招牌交互)。
196
+ - **结构化回撤 dock**:注入官方 `conversation.input.dock` 槽(composer 卡片上方
197
+ 全宽条目)——「已回撤 N 条(可恢复)」折叠面板,展开列出每个回撤/删除标记,
198
+ 逐条「恢复」(restoring 中间态禁用,S11);无标记时 dock 不渲染。
199
+ - 数据链:messages 端点为 user 消息新增 `fullText` 字段(回填原文)。
200
+ - 0.1.x 宿主两个槽均不存在,inject 自动 no-op。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@240xu/dsh-message-ops",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "Roll back, branch, and export any DSH conversation — from the UI or straight from the agent via a message_ops tool. Non-destructive: logs stay append-only and recoverable. 消息回滚/删除/分支/导出四合一,内置 message_ops agent 工具;非破坏语义,日志只追加可恢复。",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/client.js CHANGED
@@ -70,6 +70,9 @@ window.__ModuleLoader__.load({
70
70
  'busy.restore': '恢复中…',
71
71
  'confirm.restore': '恢复',
72
72
  'ack.restore': '我已了解:恢复将以新 seq 重放被遮蔽的消息(原日志不变)',
73
+ 'dock.title': '已回撤 {n} 条(可恢复)',
74
+ 'dock.restore': '恢复',
75
+ 'dock.restoring': '恢复中…',
73
76
  'menu.ops': '消息操作',
74
77
  }
75
78
 
@@ -117,11 +120,15 @@ window.__ModuleLoader__.load({
117
120
  'done.delete': 'Deleted; reload to apply',
118
121
  'action.reload': 'Reload page',
119
122
  'errorPrefix': 'Operation failed: ',
123
+ 'dock.title': '{n} rolled back (restorable)',
124
+ 'dock.restore': 'Restore',
125
+ 'dock.restoring': 'Restoring…',
120
126
  'menu.ops': 'Message ops',
121
127
  }
122
128
 
123
129
  var __locale = null
124
130
  var __sessionsSvc = null
131
+ var __inputActions = null // 0.4.0: 从 session 槽捕获(InputActions.setDraft → composer 回填)
125
132
  var __uiWorkspace = null
126
133
  // messageId→seq 索引缓存(每会话一次拉取;0.3.0 assistant-actions 槽用)
127
134
  var __seqIndexCache = new Map()
@@ -379,6 +386,11 @@ window.__ModuleLoader__.load({
379
386
  const okMsg = mode === 'restore'
380
387
  ? t('done.restore', { n: String(data.restoredCount != null ? data.restoredCount : '?'), s: String(data.skipped != null ? data.skipped : 0) })
381
388
  : t(mode === 'revert' ? 'done.revert' : 'done.delete')
389
+ // 0.4.0 composer 回填(opencode 式):回滚用户消息 → 原文回填输入框,「编辑重发」零按钮
390
+ if (mode === 'revert' && pickedMsg && pickedMsg.role === 'user' && pickedMsg.fullText
391
+ && __inputActions && typeof __inputActions.setDraft === 'function') {
392
+ try { __inputActions.setDraft(pickedMsg.fullText) } catch { /* 回填失败不阻断成功反馈 */ }
393
+ }
382
394
  setDoneMsg(okMsg)
383
395
  setBusyMsg('')
384
396
  setState('done')
@@ -582,7 +594,8 @@ window.__ModuleLoader__.load({
582
594
  const CHAT_ACTIONS_ID = 'message-ops-row'
583
595
 
584
596
  function MsgSlotActions(props) {
585
- const { messageId, sessionId, useSessions } = props
597
+ const { messageId, sessionId, useSessions, inputActions } = props
598
+ if (inputActions && typeof inputActions.setDraft === 'function') __inputActions = inputActions
586
599
  const t = (props && props.t) || __t
587
600
  useLocaleRevision()
588
601
  const sessions = useSessions ? useSessions((s) => s) : undefined
@@ -656,6 +669,101 @@ window.__ModuleLoader__.load({
656
669
  )
657
670
  }
658
671
 
672
+ // --- 0.4.0 回撤 dock:composer 上方「N 条已回撤」结构化面板(opencode 式) ----
673
+ // 官方槽 conversation.input.dock(scope session,composer 卡片上方全宽条目)。
674
+ // ownerProps/standardProps 含 sessionId + useSessions + inputActions。
675
+ const INPUT_DOCK_SLOT = 'conversation.input.dock'
676
+ const INPUT_DOCK_ID = 'message-ops-revert-dock'
677
+
678
+ function RevertDock(props) {
679
+ const { sessionId, useSessions, inputActions } = props
680
+ const t = (props && props.t) || __t
681
+ useLocaleRevision()
682
+ if (inputActions && typeof inputActions.setDraft === 'function') __inputActions = inputActions
683
+ const sessions = useSessions ? useSessions((s) => s) : undefined
684
+ const summary = sessions && sessions.byId ? sessions.byId[sessionId] : undefined
685
+ const running = summary ? summary.running === true : false
686
+ const [open, setOpen] = useState(false)
687
+ const [rows, setRows] = useState(null) // [{seq, snippet, role}] replace 标记行
688
+ const [shadowedCount, setShadowedCount] = useState(0)
689
+ const [restoring, setRestoring] = useState(null)
690
+
691
+ useEffect(() => {
692
+ let alive = true
693
+ fetch('/api/message-ops/messages?sessionId=' + encodeURIComponent(sessionId))
694
+ .then((r) => (r.ok ? r.json() : null))
695
+ .then((data) => {
696
+ if (!alive || !data || !data.ok) return
697
+ const msgs = data.messages || []
698
+ setShadowedCount(msgs.filter((m) => m.visible === false && m.role !== 'system').length)
699
+ setRows(msgs.filter((m) => m.marker))
700
+ })
701
+ .catch(() => {})
702
+ return () => { alive = false }
703
+ }, [sessionId])
704
+
705
+ if (!rows || !rows.length) return null // 无回撤标记 → dock 不渲染
706
+
707
+ const restoreRow = (row) => {
708
+ if (restoring != null || running) return
709
+ setRestoring(row.seq)
710
+ fetch('/api/message-ops/restore', {
711
+ method: 'POST', headers: { 'content-type': 'application/json' },
712
+ body: JSON.stringify({ sessionId, seq: row.seq }),
713
+ })
714
+ .then(async (res) => {
715
+ let data = {}
716
+ try { data = await res.json() } catch { /* keep {} */ }
717
+ if (!res.ok || !data.ok) throw new Error(data.error || ('HTTP ' + res.status))
718
+ notifyDone(t('done.restore', { n: String(data.restoredCount != null ? data.restoredCount : '?'), s: String(data.skipped != null ? data.skipped : 0) }))
719
+ // 刷新 dock 数据(重放后标记行状态变化)
720
+ const fresh = await fetch('/api/message-ops/messages?sessionId=' + encodeURIComponent(sessionId)).then((r) => (r.ok ? r.json() : null)).catch(() => null)
721
+ if (fresh && fresh.ok) {
722
+ const msgs = fresh.messages || []
723
+ setShadowedCount(msgs.filter((m) => m.visible === false && m.role !== 'system').length)
724
+ setRows(msgs.filter((m) => m.marker))
725
+ }
726
+ })
727
+ .catch((reason) => {
728
+ notifyDone(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error')
729
+ })
730
+ .finally(() => setRestoring(null))
731
+ }
732
+
733
+ const rowEl = (row) => React.createElement('div', {
734
+ key: row.seq,
735
+ style: { display: 'flex', alignItems: 'center', gap: 8, padding: '4px 10px',
736
+ borderTop: '1px solid var(--dsw-alias-border-l1,rgba(128,128,128,.15))' },
737
+ },
738
+ React.createElement('span', { style: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', fontSize: 12, opacity: 0.85 } },
739
+ '#' + row.seq + ' ' + (row.role || '') + ' · ' + (row.snippet || '')),
740
+ React.createElement('button', {
741
+ type: 'button', 'aria-label': t('dock.restore'), disabled: restoring != null || running,
742
+ style: { border: 'none', background: 'transparent', color: 'var(--dsw-alias-link,#8ab4f8)',
743
+ font: 'inherit', fontSize: 12, cursor: restoring != null || running ? 'default' : 'pointer',
744
+ opacity: restoring != null || running ? 0.5 : 1, padding: '4px 8px', minHeight: 28 },
745
+ onClick: () => restoreRow(row),
746
+ }, restoring === row.seq ? t('dock.restoring') : t('dock.restore')),
747
+ )
748
+
749
+ return React.createElement('div', {
750
+ role: 'region', 'aria-label': t('dock.title', { n: String(shadowedCount) }),
751
+ style: { border: '1px solid var(--dsw-alias-border-l1,rgba(128,128,128,.25))', borderRadius: 8, margin: '0 0 8px', overflow: 'hidden',
752
+ background: 'var(--dsw-alias-bg-elevated,rgba(128,128,128,.06))' },
753
+ },
754
+ React.createElement('button', {
755
+ type: 'button', 'aria-expanded': open,
756
+ style: { display: 'flex', width: '100%', alignItems: 'center', justifyContent: 'space-between',
757
+ border: 'none', background: 'transparent', color: 'inherit',
758
+ font: 'inherit', fontSize: 12, padding: '6px 10px', cursor: 'pointer', minHeight: 32 },
759
+ onClick: () => setOpen((v) => !v),
760
+ },
761
+ React.createElement('span', null, t('dock.title', { n: String(shadowedCount) })),
762
+ React.createElement('span', { style: { opacity: 0.6 } }, open ? '▾' : '▸')),
763
+ open ? React.createElement('div', { style: { maxHeight: 180, overflowY: 'auto' } }, rows.map(rowEl)) : null,
764
+ )
765
+ }
766
+
659
767
  // --- 侧栏行菜单注入(DOM 级,同 session-delete 模式) ------------------------
660
768
 
661
769
  function findOpenSessionRow() {
@@ -783,6 +891,11 @@ window.__ModuleLoader__.load({
783
891
  name: CHAT_ACTIONS_SLOT, id: CHAT_ACTIONS_ID, order: 20,
784
892
  ...(__locale ? { locale: NS } : {}),
785
893
  }, MsgSlotActions))
894
+ // 0.4.0:composer 上方回撤 dock(0.1.x 无此槽自动 no-op)
895
+ ctx.slots.inject(INPUT_DOCK_SLOT, () => ctx.slots.register({
896
+ name: INPUT_DOCK_SLOT, id: INPUT_DOCK_ID, order: 10,
897
+ ...(__locale ? { locale: NS } : {}),
898
+ }, RevertDock))
786
899
  ctx.slots.inject(OVERLAY_SLOT, () => ctx.slots.register({
787
900
  name: OVERLAY_SLOT, id: DIALOG_ID, order: 101,
788
901
  ...(__locale ? { locale: NS } : {}),
@@ -182,6 +182,8 @@ export function listMessages(events) {
182
182
  id: (msg && msg.id) || e.data.id || null,
183
183
  marker: isReplaceMarker,
184
184
  snippet: text.replace(/\s+/g, " ").trim().slice(0, 160),
185
+ // 0.4.0 composer 回填:user 消息携带全文(revert 后 setDraft 原文)
186
+ fullText: e.type === "user/message" ? text : null,
185
187
  time: e.time ?? null,
186
188
  turn: (e.data && e.data.turn) ?? null,
187
189
  });