dsh-session-superagent 0.9.283 → 0.9.285

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
@@ -2,6 +2,46 @@
2
2
 
3
3
  格式参照 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
4
4
 
5
+ ## [0.9.285] - 2026-11-06 —— /state 会话上下文修复
6
+
7
+ ### 主面板带 sessionId
8
+
9
+ - 主面板 `load()` 在 sessionId 存在时请求 `/state?sessionId=<encodeURIComponent>`。
10
+ - 服务端现在能返回正确的 `sessionGoal / sessionTitle / sessionUsage`,不再因为缺参置空。
11
+ - 空 sessionId 保持原请求,不串用其它会话 goal;Orbit 的独立 `/state` 调用不变。
12
+ - 服务端行为不改,只补客户端与 routes 契约。
13
+
14
+ ### 验证
15
+
16
+ - 离线联合 client + update-ui + routes:**214/214**。
17
+ - 全量:**645/645**。
18
+ - 真实 Chromium:**47/47**。
19
+ - fixture 精确校验 sessionId query,没有放宽断言。
20
+
21
+ 未验真实 DSH Web GUI 与真实 watcher 写操作。按 Git 工作流保留本地候选。
22
+
23
+ ## [0.9.284] - 2026-11-06 —— Orbit 并发与删除错误修复
24
+
25
+ ### 写操作 busy 锁
26
+
27
+ - 立刻/暂停/恢复/删除按 watcherId+action 加同步锁。
28
+ - pending 禁止重复点击,显示处理中文字、aria-busy 与 busy 样式。
29
+ - 成功和失败都在 finally 解锁,fallback 的位置化 hook 契约不变。
30
+
31
+ ### 轮询与删除
32
+
33
+ - 定时轮询和写后 /state 共用请求序号,旧成功/失败都不能覆盖新结果,最新成功清读取错误。
34
+ - 删除失败在当前确认 Modal 以 role=alert 显示,pending 禁止 dismiss,失败保留重试。
35
+ - 成功才自动关闭并回焦;失败后的主动 Escape/取消仍可用。
36
+
37
+ ### 验证
38
+
39
+ - 新增用例先红复现双击 2 POST;最终定向 176/176、integration 15/15。
40
+ - 全量 643/643,UI 体检 11/11=100。
41
+ - 主线 Chromium 47/47,双击/删除重试/pending Escape/解锁专项合计 52/52。
42
+
43
+ 未验真实 DSH Web GUI 与真实 watcher 写操作。按 Git 工作流保留本地候选。
44
+
5
45
  ## [0.9.283] - 2026-11-06 —— 保存 pending 状态机修复
6
46
 
7
47
  ### 新草稿不再被旧响应覆盖
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <img src="assets/icon-180.png" width="88" height="88" alt="">
4
4
 
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
- [![Version](https://img.shields.io/badge/version-0.9.283-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.285-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
7
7
  [![npm](https://img.shields.io/npm/v/dsh-session-superagent.svg)](https://www.npmjs.com/package/dsh-session-superagent)
8
8
  [![dsh](https://img.shields.io/badge/DeepSeek%20Harness-plugin-orange.svg)](https://github.com/topics/dsh-plugin)
9
9
  [![awesome](https://img.shields.io/badge/awesome-dsh--plugin-%E2%9C%93-success.svg)](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin)
@@ -148,7 +148,7 @@ Gitee 私有仓库要在「设置 → 凭证」填私人令牌;公开仓库不
148
148
  ## 开发
149
149
 
150
150
  ```sh
151
- npm test # 637 项单测(带离线开关;裸 node --test 会真去 spawn gh,两分半)
151
+ npm test # 645 项单测(带离线开关;裸 node --test 会真去 spawn gh,两分半)
152
152
  ```
153
153
 
154
154
  ### 工具输出:文本给人和 agent,JSON 给程序
@@ -208,7 +208,7 @@ dsh plugin --profile <profile> add dsh-session-superagent@latest
208
208
 
209
209
 
210
210
  ```bash
211
- npm test # 637 项单测(带离线开关,约 1.6 秒)
211
+ npm test # 645 项单测(带离线开关,约 1.6 秒)
212
212
  node scripts/ui-audit.mjs # 11 项 UI 指标(写死颜色 / 自造 token / 官方结构采用 …)
213
213
  node scripts/preflight.mjs # 41 项门禁(含上面两条,外加 profile 一致性、路由面、包内容)
214
214
  node scripts/render-preview.mjs preview.html # 双主题静态预览,直接浏览器打开
package/client.js CHANGED
@@ -418,7 +418,7 @@ window.__ModuleLoader__.load({
418
418
  }
419
419
 
420
420
  // 客户端版本探针:每次模块加载写一次,用来确认浏览器里跑的是哪一版
421
- const CLIENT_VERSION = '0.9.283'
421
+ const CLIENT_VERSION = '0.9.285'
422
422
  // SEMVER_COMPARATOR_SOURCE_START
423
423
  // This block is duplicated verbatim in client.js because the browser UMD cannot import ESM.
424
424
  // test/update-semver.test.mjs audits both copies and exercises their behavior.
@@ -1306,7 +1306,7 @@ window.__ModuleLoader__.load({
1306
1306
  const PanelModal = hostUi ? hostUi.Modal : Modal
1307
1307
 
1308
1308
  /** 确认层与触发器分离:DSH orbit 关闭后,同一个本地 Modal 仍能由 StatusOrbit 持有。 */
1309
- function ConfirmDialog({ open, label, confirmLabel = '确定执行', title = confirmLabel, message, onConfirm, onClose, modalContext = 'panel', ButtonComponent = Btn, danger = true, preventDismissOnBusy = false }) {
1309
+ function ConfirmDialog({ open, label, confirmLabel = '确定执行', title = confirmLabel, message, onConfirm, onClose, modalContext = 'panel', ButtonComponent = Btn, danger = true, preventDismissOnBusy = false, error = null, busyLabel = confirmLabel, busyHint = '安装进行中,完成后才能关闭' }) {
1310
1310
  const [busy, setBusy] = useState(false)
1311
1311
  const busyRef = useRef(false)
1312
1312
  const dismiss = () => {
@@ -1331,6 +1331,11 @@ window.__ModuleLoader__.load({
1331
1331
  }
1332
1332
  // orbit 删除明确保留 superagent 同源 Modal;普通主面板删除仍走 PanelModal,不换 RiskConfirmation。
1333
1333
  const ModalView = modalContext === 'orbit' ? Modal : PanelModal
1334
+ const feedback = error || (preventDismissOnBusy && busy)
1335
+ ? h(React.Fragment, null,
1336
+ error ? h('div', { className: 'dt-error', role: 'alert' }, error) : null,
1337
+ preventDismissOnBusy && busy ? h(Hint, null, busyHint) : null)
1338
+ : null
1334
1339
  return h(ModalView, {
1335
1340
  open,
1336
1341
  title,
@@ -1345,12 +1350,12 @@ window.__ModuleLoader__.load({
1345
1350
  'aria-label': confirmLabel,
1346
1351
  'aria-busy': busy ? 'true' : undefined,
1347
1352
  onClick: confirm,
1348
- }, confirmLabel)),
1349
- }, preventDismissOnBusy && busy ? h(Hint, null, '安装进行中,完成后才能关闭') : null)
1353
+ }, busy ? busyLabel : confirmLabel)),
1354
+ }, feedback)
1350
1355
  }
1351
1356
 
1352
1357
  /** 官方 ConfirmButton 动线:触发按钮只开 Modal,取消不执行,确认期间 busy 防重复。 */
1353
- function ConfirmButton({ label, confirmLabel = '确定执行', title = confirmLabel, message, onConfirm, variant = 'ghost', icon, size, modalContext = 'panel', ButtonComponent = Btn, danger = true, preventDismissOnBusy = false }) {
1358
+ function ConfirmButton({ label, confirmLabel = '确定执行', title = confirmLabel, message, onConfirm, variant = 'ghost', icon, size, modalContext = 'panel', ButtonComponent = Btn, danger = true, preventDismissOnBusy = false, error = null, busyLabel = confirmLabel, busyHint }) {
1354
1359
  const [open, setOpen] = useState(false)
1355
1360
  const close = useCallback(() => setOpen(false), [])
1356
1361
  return h(React.Fragment, null,
@@ -1362,10 +1367,11 @@ window.__ModuleLoader__.load({
1362
1367
  'aria-haspopup': 'dialog',
1363
1368
  onClick: () => setOpen(true),
1364
1369
  }, label),
1365
- h(ConfirmDialog, { open, label, confirmLabel, title, message, onConfirm, onClose: close, modalContext, ButtonComponent, danger, preventDismissOnBusy }))
1370
+ h(ConfirmDialog, { open, label, confirmLabel, title, message, onConfirm, onClose: close, modalContext, ButtonComponent, danger, preventDismissOnBusy, error, busyLabel, busyHint }))
1366
1371
  }
1367
1372
 
1368
1373
  const watcherId = (w) => (w && w.id) || String((w && w.repo) || '') + '#' + String((w && w.sessionId) || '')
1374
+ const orbitActionKey = (w, action) => JSON.stringify([watcherId(w), action])
1369
1375
  const short = (value, width = 19) => (typeof value === 'string' && value.length > width ? value.slice(0, width - 1) + '…' : (value ?? '—'))
1370
1376
  const when = (iso) => (typeof iso === 'string' ? iso.replace('T', ' ').replace('Z', '').slice(5, 19) : '—')
1371
1377
 
@@ -1571,6 +1577,9 @@ window.__ModuleLoader__.load({
1571
1577
  const [anchor, setAnchor] = useState(null)
1572
1578
  const btnRef = useRef(null)
1573
1579
  const panelRef = useRef(null)
1580
+ const actionLocks = useRef(new Set())
1581
+ const stateSequence = useRef(0)
1582
+ const orbitAlive = useRef(true)
1574
1583
  const orbitConfirm = useOrbitConfirm({
1575
1584
  orbitRef: btnRef,
1576
1585
  onCloseOrbit: () => setOpen(false),
@@ -1578,28 +1587,36 @@ window.__ModuleLoader__.load({
1578
1587
  onRequestConfirm: ({ watcher }) => setAnchor(watcher),
1579
1588
  })
1580
1589
 
1590
+ const isReadError = (value) => typeof value === 'string'
1591
+ && (value.startsWith('读取失败:') || value.startsWith('写成功了,但刷新列表失败:'))
1592
+ // 定时轮询与写后回读共用同一个代际:只允许最后一次请求改 watchers/读取错误。
1593
+ const loadState = async (failurePrefix = '读取失败:') => {
1594
+ const sequence = ++stateSequence.current
1595
+ try {
1596
+ const body = await call('/state')
1597
+ if (!orbitAlive.current || sequence !== stateSequence.current) return { applied: false, ok: true }
1598
+ setWatchers(Array.isArray(body && body.watchers) ? body.watchers : [])
1599
+ setOrbitError((current) => isReadError(current) ? null : current)
1600
+ return { applied: true, ok: true }
1601
+ } catch (error) {
1602
+ if (orbitAlive.current && sequence === stateSequence.current) {
1603
+ setOrbitError(failurePrefix + String((error && error.message) || error).slice(0, 160))
1604
+ }
1605
+ return { applied: orbitAlive.current && sequence === stateSequence.current, ok: false }
1606
+ }
1607
+ }
1608
+
1581
1609
  // 弹层的样式(DOCK_CSS)挂在 PORTED_CSS 同一张 <style> 里,而那张表以前只有「主理鱼」面板挂载时才注入。
1582
1610
  // 用户从没打开过面板就直接点状态栏圆环时,弹层就是一堆无样式的裸文字(真机复现过)。
1583
1611
  useEffect(() => { ensurePortedCss() }, [])
1584
1612
 
1585
1613
  useEffect(() => {
1586
- let alive = true
1614
+ orbitAlive.current = true
1587
1615
  noteOnce('orbit-mount', 'ok')
1588
- const load = async () => {
1589
- try {
1590
- const body = await call('/state')
1591
- if (alive) {
1592
- setWatchers(Array.isArray(body && body.watchers) ? body.watchers : [])
1593
- setOrbitError((current) => typeof current === 'string' && current.startsWith('读取失败:') ? null : current)
1594
- }
1595
- } catch (error) {
1596
- // null=尚未读到,[]=成功读到空列表;首次失败不能伪造成“还没有主理鱼”。
1597
- if (alive) setOrbitError('读取失败:' + String((error && error.message) || error).slice(0, 160))
1598
- }
1599
- }
1616
+ const load = () => loadState()
1600
1617
  load()
1601
1618
  const timer = setInterval(load, POLL_MS)
1602
- return () => { alive = false; clearInterval(timer) }
1619
+ return () => { orbitAlive.current = false; clearInterval(timer) }
1603
1620
  }, [])
1604
1621
 
1605
1622
  // 弹层每次打开都把样式表钉一遍:宿主热重载可能把 <style> 清掉,
@@ -1634,7 +1651,7 @@ window.__ModuleLoader__.load({
1634
1651
  }, [open])
1635
1652
 
1636
1653
  const list = watchers || []
1637
- const readError = typeof orbitError === 'string' && orbitError.startsWith('读取失败:') ? orbitError : null
1654
+ const readError = isReadError(orbitError) ? orbitError : null
1638
1655
  // Never hide the entry: with nothing being watched it stays as a grey
1639
1656
  // ring, so the affordance is always findable in the dock row.
1640
1657
  const running = list.filter((w) => orbitStateOf(w) === 'active').length
@@ -1683,24 +1700,33 @@ window.__ModuleLoader__.load({
1683
1700
  const bottom = !hostOrbit && anchor ? Math.max(8, (window.innerHeight || 800) - anchor.y + 8) : 64
1684
1701
 
1685
1702
  const act = async (w, action) => {
1686
- // 删除只走 ConfirmButton + Modal;不要再叠一层原生确认框(同一动作问两次)。
1687
- // 审核 M4:两层空 catch 让写操作遇 409/404/503/断网时**完全静默** ——
1688
- // 界面不变、无提示,客户以为按钮坏了。失败必须说出来。
1689
- try {
1690
- await call('/watch', { method: 'POST', body: JSON.stringify({ action, id: watcherId(w) }) })
1691
- } catch (error) {
1692
- setOrbitError(String((error && error.message) || error).slice(0, 160))
1693
- return false
1703
+ const key = orbitActionKey(w, action)
1704
+ if (actionLocks.current.has(key)) return false
1705
+ actionLocks.current.add(key)
1706
+ // 不新增根 useState:旧 fallback 的位置化 hook 契约必须保持不变。
1707
+ // 新数组只触发一次渲染,watcher 内容不变;可见 pending 直接读取同步锁集合。
1708
+ setWatchers((current) => Array.isArray(current) ? [...current] : current)
1709
+ if (action === 'delete') {
1710
+ setOrbitError((current) => typeof current === 'string' && current.startsWith('删除失败:') ? null : current)
1694
1711
  }
1695
1712
  try {
1696
- const body = await call('/state')
1697
- setWatchers(Array.isArray(body && body.watchers) ? body.watchers : [])
1713
+ // 删除只走 ConfirmButton + Modal;不要再叠一层原生确认框(同一动作问两次)。
1714
+ try {
1715
+ await call('/watch', { method: 'POST', body: JSON.stringify({ action, id: watcherId(w) }) })
1716
+ } catch (error) {
1717
+ const message = String((error && error.message) || error).slice(0, 160)
1718
+ setOrbitError(action === 'delete' ? '删除失败:' + message : message)
1719
+ return false
1720
+ }
1721
+ // 写已成功:清掉上一代操作/读取错误;回读失败会由 loadState 写入新的可见错误。
1698
1722
  setOrbitError(null)
1699
- } catch (error) {
1700
- setOrbitError('写成功了,但刷新列表失败:' + String((error && error.message) || error).slice(0, 120))
1723
+ await loadState('写成功了,但刷新列表失败:')
1724
+ // 刷新失败不等于删除失败:动作已成功,确认框仍应关闭。
1725
+ return true
1726
+ } finally {
1727
+ actionLocks.current.delete(key)
1728
+ setWatchers((current) => Array.isArray(current) ? [...current] : current)
1701
1729
  }
1702
- // 刷新失败不等于删除失败:动作已成功,确认框仍应关闭。
1703
- return true
1704
1730
  }
1705
1731
 
1706
1732
  // fallback 完全保留原提前返回;DSH 即使 orbit 已关,也要继续渲染由本组件持有的确认 Modal。
@@ -1709,6 +1735,8 @@ window.__ModuleLoader__.load({
1709
1735
  setAnchor(null)
1710
1736
  orbitConfirm.onConfirmClose()
1711
1737
  }
1738
+ const deleteError = typeof orbitError === 'string' && orbitError.startsWith('删除失败:') ? orbitError : null
1739
+ const actionPending = (w, action) => actionLocks.current.has(orbitActionKey(w, action))
1712
1740
 
1713
1741
  // 悬浮面板也走移植来的 dt-* 设计系统(以前这里是一套自成体系的 inline style,
1714
1742
  // 和原生界面放在一起能看出断层;ui-audit ⑥ 就是在盯这件事)。
@@ -1745,6 +1773,9 @@ window.__ModuleLoader__.load({
1745
1773
  const key = String(w.repo || '') + '#' + String(w.sessionId || '')
1746
1774
  const statusDot = h('span', { className: 'dt-state-dot', 'data-state': dotState })
1747
1775
  const statusTag = h('span', { className: 'dt-tag', 'data-tone': tone }, STATE_TEXT[state])
1776
+ const pollPending = actionPending(w, 'poll')
1777
+ const toggleAction = w.enabled ? 'pause' : 'resume'
1778
+ const togglePending = actionPending(w, toggleAction)
1748
1779
  const detailContent = h(React.Fragment, null,
1749
1780
  h('div', { className: 'sa-dock-sub' }, shortSub(w)),
1750
1781
  w.lastError
@@ -1752,9 +1783,16 @@ window.__ModuleLoader__.load({
1752
1783
  : null)
1753
1784
  const details = h('div', { className: 'sa-dock-body' }, detailContent)
1754
1785
  const actions = h('div', { className: 'sa-dock-actions' },
1755
- h(Btn, { size: 'sm', variant: 'ghost', onClick: () => act(w, 'poll') }, '立刻'),
1756
- h(Btn, { size: 'sm', variant: 'ghost', onClick: () => act(w, w.enabled ? 'pause' : 'resume') },
1757
- w.enabled ? '暂停' : '恢复'),
1786
+ h(Btn, {
1787
+ size: 'sm', variant: 'ghost', disabled: pollPending,
1788
+ className: cx(pollPending && 'dt-btn-busy'), 'aria-busy': pollPending ? 'true' : undefined,
1789
+ onClick: () => act(w, 'poll'),
1790
+ }, pollPending ? '轮询中…' : '立刻'),
1791
+ h(Btn, {
1792
+ size: 'sm', variant: 'ghost', disabled: togglePending,
1793
+ className: cx(togglePending && 'dt-btn-busy'), 'aria-busy': togglePending ? 'true' : undefined,
1794
+ onClick: () => act(w, toggleAction),
1795
+ }, togglePending ? (toggleAction === 'pause' ? '暂停中…' : '恢复中…') : (w.enabled ? '暂停' : '恢复')),
1758
1796
  hostOrbit
1759
1797
  ? h(Btn, {
1760
1798
  variant: 'ghost', size: 'sm', icon: h(Icon, { name: 'trash' }),
@@ -1765,7 +1803,8 @@ window.__ModuleLoader__.load({
1765
1803
  : h(ConfirmButton, {
1766
1804
  label: '删除', confirmLabel: '确认删除', variant: 'ghost', size: 'sm', modalContext: 'orbit',
1767
1805
  icon: h(Icon, { name: 'trash' }),
1768
- onConfirm: () => act(w, 'delete'),
1806
+ onConfirm: () => act(w, 'delete'), error: deleteError,
1807
+ preventDismissOnBusy: true, busyLabel: '删除中…', busyHint: '删除进行中,完成后才能关闭',
1769
1808
  }))
1770
1809
 
1771
1810
  if (hostOrbitRow) {
@@ -1855,6 +1894,10 @@ window.__ModuleLoader__.load({
1855
1894
  modalContext: 'orbit',
1856
1895
  onConfirm: () => act(anchor, 'delete'),
1857
1896
  onClose: closeConfirm,
1897
+ error: deleteError,
1898
+ preventDismissOnBusy: true,
1899
+ busyLabel: '删除中…',
1900
+ busyHint: '删除进行中,完成后才能关闭',
1858
1901
  })
1859
1902
  : null
1860
1903
 
@@ -2053,8 +2096,9 @@ window.__ModuleLoader__.load({
2053
2096
  const loadSeqRef = useRef(0)
2054
2097
  const load = useCallback(async () => {
2055
2098
  const seq = ++loadSeqRef.current
2099
+ const statePath = sessionId ? '/state?sessionId=' + encodeURIComponent(String(sessionId)) : '/state'
2056
2100
  try {
2057
- const payload = await call('/state', stateEtag ? { headers: { 'if-none-match': stateEtag } } : undefined)
2101
+ const payload = await call(statePath, stateEtag ? { headers: { 'if-none-match': stateEtag } } : undefined)
2058
2102
  if (seq !== loadSeqRef.current) return null // 已经有更新的一次请求在飞:这次结果作废
2059
2103
  // 304:内容没变,别白白重渲染 —— 前提是本地已经有一份能渲染的 body
2060
2104
  if (payload && payload.notModified) {
@@ -2072,7 +2116,7 @@ window.__ModuleLoader__.load({
2072
2116
  setSnap((prev) => ({ loading: false, error: String((error && error.message) || error), body: prev.body }))
2073
2117
  return null
2074
2118
  }
2075
- }, [])
2119
+ }, [sessionId])
2076
2120
 
2077
2121
  useEffect(() => { ensurePortedCss() }, [])
2078
2122
  usePoll(load, POLL_MS)
package/lib/index.js CHANGED
@@ -49,7 +49,7 @@ import {
49
49
 
50
50
  export const name = 'dsh-session-superagent'
51
51
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
52
- export const SERVER_VERSION = '0.9.283'
52
+ export const SERVER_VERSION = '0.9.285'
53
53
  export const inject = ['tools', 'agents', 'webServer']
54
54
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
55
55
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.283",
3
+ "version": "0.9.285",
4
4
  "description": "Session-level superagent for DeepSeek Harness: watch a GitHub repository and wake a session when something needs doing. Credentials never reach the model.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",