dsh-config-sync-plugin 0.3.81 → 0.3.83

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.en.md CHANGED
@@ -19,7 +19,7 @@ The package name is **`dsh-config-sync-plugin`** (the `dsh-config-sync` name on
19
19
 
20
20
  | Way | Command / entry | Notes |
21
21
  |---|---|---|
22
- | npm | `npm i dsh-config-sync-plugin` | Use it as a dependency, or add `"dsh-config-sync-plugin": "^0.3.81"` to the profile's `package.json` and run `pnpm i`. The name matches the `cordis.patch.yml` insert name and the install folder `dsh-config-sync-plugin-<ver>` |
22
+ | npm | `npm i dsh-config-sync-plugin` | Use it as a dependency, or add `"dsh-config-sync-plugin": "^0.3.82"` to the profile's `package.json` and run `pnpm i`. The name matches the `cordis.patch.yml` insert name and the install folder `dsh-config-sync-plugin-<ver>` |
23
23
  | Marketplace | client → Plugins → Discover → “Config Sync” | Installs from the git commit registered in `market-index.json` |
24
24
  | Offline tgz | `releases\dsh-config-sync-plugin-<ver>.tgz` | GitHub Release asset for air-gapped machines; the panel's Update button downloads the same file |
25
25
 
@@ -232,7 +232,7 @@ A new **Workspace visibility** section brings both native DSH hiding mechanisms
232
232
  | Hide sessions | Workspace stays in the list, its sessions go to Archived | Sessions written to `global.archivedSessionIds` in `<DshHome>\storages\workspace.json` |
233
233
  | Archive workspace | Workspace disappears from the list, sessions kept | `<DshHome>\dsh-session-manager\workspace-archives.v1.json` gets `archived:true` and its sessions hidden too |
234
234
 
235
- Each workspace switches between the three states independently; expanding it lets you hide/show a single session without touching others (a session toggle changes only that one `archivedSessionIds` entry, never the workspace archive record). Changes write the two native DSH state files directly — the session-manager Web API needs a DSH connection-owner credential the plugin route does not have. The session list is cached locally, so restart or refresh the session list to see the effect. Since 0.3.75 the archive file is synced, so these states travel with push/pull too.
235
+ Each workspace switches between the three states independently; expanding it lets you hide/show a single session without touching others (a session toggle changes only that one `archivedSessionIds` entry, never the workspace archive record). Changes do not call the session-manager Web API (it needs a DSH connection-owner credential the plugin route does not have) — they go through the host `workspaceRegistry`, which persists and pushes the session-list update, so toggles apply immediately (see 0.3.82). Since 0.3.75 the archive file is synced, so these states travel with push/pull too.
236
236
 
237
237
  ### Panel: session names, Edit button, click-to-expand and quick jump (0.3.77)
238
238
 
@@ -253,6 +253,15 @@ Two display fixes on top of 0.3.77:
253
253
  1. **Jump order matches section order**: the quick-jump tabs now follow the exact render order of the sections (Overview / Sync conflicts [when present] / Local paths [when expanded] / Targets / Automation & updates / Scripts / Restore / Content / Plugin data / Workspace visibility / Feedback). The two conditional sections (conflicts, local paths) appear in the tabs only when their cards are shown.
254
254
  2. **Scroll lands below the title**: the sticky title bar now uses an opaque background (same fill as panel cards), so content no longer shows through it; jumping to a tab sets the scroll offset from the title bar's actual height, so the target section lands fully below the title instead of being covered.
255
255
 
256
+ ### Workspace visibility card: agent sessions collapsed by default + instant hide/show (0.3.82)
257
+
258
+ Two changes to the "Workspace visibility" card:
259
+
260
+ 1. **Agent (subagent) sessions are collapsed by default**: the card lists only your own sessions. A "Show agents" checkbox in the header row reveals agent child sessions and reports how many were folded away. 80 of the 99 registered sessions on this machine were agent sessions (mnemon reviews and delegated tasks each leave one behind), flooding the list so you could not find your own.
261
+ 2. **Hide/show takes effect immediately**: toggling the workspace tri-state or a single session used to only rewrite the on-disk state file, leaving the host's in-memory `archivedSessionIds` stale — a client restart or session-list refresh was required. It now goes through the host `workspaceRegistry` (`archiveSession` / `unarchiveSession`), which persists and pushes the session-list update, so toggles apply the moment you click. If the host service is unavailable it falls back to the previous file-based write and the card hint says which path was used.
262
+
263
+ Reading the owning workspace and the session title stays self-contained; the session-manager Web API is not used.
264
+
256
265
  ### Workspace visibility card session names now match the DSH panel (0.3.81)
257
266
 
258
267
  Fixes session names in the "Workspace visibility" card differing from the DSH session panel.
@@ -643,6 +652,7 @@ The log shows which path ran: `文件比较(快筛):比对 N 个,深哈
643
652
 
644
653
  | Date | Version | Summary |
645
654
  |---|---|---|
655
+ | 2026-11-23 | 0.3.82 | Workspace visibility card collapses agent sessions by default; hide/show goes through workspaceRegistry and applies instantly (no restart) |
646
656
  | 2026-11-21 | 0.3.75 | Sync hidden/archived workspaces across machines (workspace-archives.v1.json into settings); hidden workspaces and sessions stay hidden on B after pull |
647
657
  | 2026-11-19 | 0.3.69 | Carry billion-context compaction state across machines (bili-state.mjs); two new notice kinds (plugin-missing / context-state) |
648
658
  | 2026-11-19 | 0.3.68 | Session projection-cache guard (fixes agent-busy session creation) |
package/README.md CHANGED
@@ -15,7 +15,7 @@ DSH 插件:左侧栏多一行「配置同步」,点开是整页体检面板
15
15
 
16
16
  | 方式 | 命令 / 入口 | 说明 |
17
17
  |---|---|---|
18
- | npm | `npm i dsh-config-sync-plugin` | 适合把它当依赖管理,或在 profile 的 `package.json` 里写 `"dsh-config-sync-plugin": "^0.3.81"` 后 `pnpm i`;包名与 `cordis.patch.yml` 里注册的名字、插件目录 `dsh-config-sync-plugin-<ver>` 一致 |
18
+ | npm | `npm i dsh-config-sync-plugin` | 适合把它当依赖管理,或在 profile 的 `package.json` 里写 `"dsh-config-sync-plugin": "^0.3.82"` 后 `pnpm i`;包名与 `cordis.patch.yml` 里注册的名字、插件目录 `dsh-config-sync-plugin-<ver>` 一致 |
19
19
  | 插件市场 | 客户端「插件市场 → 发现」搜「配置同步」 | 走 `market-index.json` 登记的 git 提交,版本与 README 对齐 |
20
20
  | 离线 tgz | `releases\dsh-config-sync-plugin-<ver>.tgz` | GitHub Release 附件,适合内网机器;面板「更新」按钮下载的也是它 |
21
21
 
@@ -252,7 +252,7 @@ pwsh -File runtime\sync.ps1 pull `
252
252
  | 隐藏会话 | 工作区留在列表,名下会话进「已归档」 | 会话写进 `<DshHome>\storages\workspace.json` 的 `global.archivedSessionIds` |
253
253
  | 归档工作区 | 整个工作区从列表消失,会话保留 | `<DshHome>\dsh-session-manager\workspace-archives.v1.json` 写 `archived:true` + 会话一并按隐藏处理 |
254
254
 
255
- 每个工作区可独立切三态;展开后还能对单个会话单独「隐藏 / 显示」,两者互不影响(会话操作只动那一条 `archivedSessionIds`,不改工作区归档记录)。改动直接写本机 DSH 的两套状态文件,不调 session-manager 的 Web API(那套 API 需要 DSH connection owner 凭证,插件路由拿不到)。会话列表有本地缓存,切换后重启或刷新会话列表生效。0.3.75 已把归档文件纳入同步,所以这里改的隐藏 / 归档状态也会跟着 push/pull 到另一台机。
255
+ 每个工作区可独立切三态;展开后还能对单个会话单独「隐藏 / 显示」,两者互不影响(会话操作只动那一条 `archivedSessionIds`,不改工作区归档记录)。改动不调 session-manager 的 Web API(那套 API 需要 DSH connection owner 凭证,插件路由拿不到),而是经宿主 `workspaceRegistry` 落盘并推送会话列表更新,切换后立刻生效(详见 0.3.82)。0.3.75 已把归档文件纳入同步,所以这里改的隐藏 / 归档状态也会跟着 push/pull 到另一台机。
256
256
 
257
257
  ### 配置同步面板:会话名称、修改按钮、点行展开与快速跳转(0.3.77)
258
258
 
@@ -273,6 +273,15 @@ pwsh -File runtime\sync.ps1 pull `
273
273
  1. **跳转顺序对齐卡片**:快捷标签顺序改为与分区实际渲染顺序完全一致(概览 / 同步冲突[有冲突时] / 本机路径[展开时] / 同步目标 / 自动化与插件更新 / 生成脚本 / 还原备份 / 同步内容 / 插件数据 / 工作区显示 / 问题反馈)。同步冲突、本机路径两个条件分区只在卡片存在时才出现在标签里。
274
274
  2. **滚动落点在标题下方**:标题栏改为不透明背景(面板卡片同色),滚动时内容不再从标题背后透出;点标签跳转时按标题栏实际高度设置滚动落点,目标分区完整显示在标题下方,不再被遮住。
275
275
 
276
+ ### 工作区显示卡片:默认折叠智能体会话 + 隐藏/显示即时生效(0.3.82)
277
+
278
+ 「工作区显示」卡片两处改动:
279
+
280
+ 1. **默认折叠智能体(subagent)子会话**:卡片只列你自己的会话,标题行新增「显示智能体」勾选项,需要时勾上才把智能体子会话一并列出,并显示被折叠的条数。本机 99 条登记会话里有 80 条是智能体子会话(mnemon 审查 / 派生任务都会留一条),一屏全是它们,自己的会话反而找不到。
281
+ 2. **隐藏/显示即时生效**:之前切三态或单条会话只改磁盘上的状态文件,宿主内存里的 `archivedSessionIds` 不更新,必须重启客户端或刷新会话列表才看到变化。现在改走宿主的 `workspaceRegistry`(`archiveSession` / `unarchiveSession`),落盘的同时触发会话列表推送,面板上切完立刻生效。宿主服务取不到时自动退回原来的文件写法,并在卡片提示里说明走的是哪条路。
282
+
283
+ 会话所属工作区与会话标题的读取仍然自包含,不依赖 session-manager 的 Web API。
284
+
276
285
  ### 工作区显示卡片的会话名称与 DSH 面板保持一致(0.3.81)
277
286
 
278
287
  修复「工作区显示」卡片里会话名称与 DSH 会话面板显示不一致的问题。
@@ -625,6 +634,7 @@ pwsh -File sync.ps1 push -ScanHistory
625
634
 
626
635
  | 日期 | 版本 | 要点 |
627
636
  |---|---|---|
637
+ | 2026-11-23 | 0.3.82 | 工作区显示卡片默认折叠智能体会话;隐藏/显示改走 workspaceRegistry,切完即时生效(不再需要重启) |
628
638
  | 2026-11-21 | 0.3.75 | 隐藏/归档的工作区跨机同步(workspace-archives.v1.json 纳入 settings),B 机拉取后不再显示已隐藏的工作区与会话 |
629
639
  | 2026-11-19 | 0.3.69 | 跨机搬运 billion-context 压缩状态(bili-state.mjs);同步清单新增 plugin-missing / context-state 两类提示 |
630
640
  | 2026-11-19 | 0.3.68 | 会话投影缓存守卫,治 agent-busy 建会话失败 |
package/client.js CHANGED
@@ -503,8 +503,13 @@ window.__ModuleLoader__.load({
503
503
  }
504
504
 
505
505
  /** 工作区显示状态:三态(显示 / 隐藏会话 / 归档工作区)+ 会话级独立隐藏。 */
506
- async function callWorkspaceView(payload) {
507
- const res = await fetch('/config-sync/workspace-view', payload
506
+ async function callWorkspaceView(payload, opts) {
507
+ // 两类默认折叠的会话各有一个开关:agents=1 放回智能体,blank=1 放回空会话。
508
+ const q = []
509
+ if (opts && opts.includeAgents) q.push('agents=1')
510
+ if (opts && opts.includeBlank) q.push('blank=1')
511
+ const query = q.length > 0 ? '?' + q.join('&') : ''
512
+ const res = await fetch('/config-sync/workspace-view' + query, payload
508
513
  ? {
509
514
  method: 'POST',
510
515
  cache: 'no-store',
@@ -1604,33 +1609,42 @@ window.__ModuleLoader__.load({
1604
1609
  const [msg, setMsg] = react.useState('')
1605
1610
  const [expanded, setExpanded] = react.useState({})
1606
1611
  const [editing, setEditing] = react.useState({})
1612
+ // 默认折叠智能体(subagent)会话:一屏全是子会话时根本找不到自己的会话。
1613
+ const [showAgents, setShowAgents] = react.useState(false)
1614
+ // 默认折叠空会话:建了没聊过、或者只是 Mnemon 空闲审查的父容器,列出只会干扰。
1615
+ const [showBlank, setShowBlank] = react.useState(false)
1607
1616
 
1608
1617
  const load = react.useCallback(async () => {
1609
1618
  setBusy(true); setErr('')
1610
- try { setData(await callWorkspaceView()) }
1619
+ try { setData(await callWorkspaceView(null, { includeAgents: showAgents, includeBlank: showBlank })) }
1611
1620
  catch (e) { setErr(String((e && e.message) || e)) }
1612
1621
  finally { setBusy(false) }
1613
- }, [])
1622
+ }, [showAgents, showBlank])
1614
1623
  react.useEffect(() => { load() }, [load])
1615
1624
 
1616
1625
  const changeWorkspace = react.useCallback(async (wsId, state) => {
1617
1626
  setBusy(true); setErr(''); setMsg('')
1618
1627
  try {
1619
- const d = await callWorkspaceView({ action: 'workspace', workspaceId: wsId, state })
1628
+ const d = await callWorkspaceView({ action: 'workspace', workspaceId: wsId, state, includeAgents: showAgents, includeBlank: showBlank }, { includeAgents: showAgents, includeBlank: showBlank })
1620
1629
  setData(d)
1621
- setMsg(M('已更新工作区显示状态', 'Workspace view state updated'))
1630
+ setMsg(d.live === true
1631
+ ? M('已更新,会话列表已同步', 'Updated — the session list is in sync')
1632
+ : M('已更新;宿主服务暂不可用,已直接写入状态文件', 'Updated; host service unavailable, wrote the state file directly'))
1622
1633
  } catch (e) { setErr(String((e && e.message) || e)) }
1623
1634
  finally { setBusy(false) }
1624
- }, [])
1635
+ }, [showAgents, showBlank])
1625
1636
 
1626
1637
  const changeSession = react.useCallback(async (sid, hidden) => {
1627
1638
  setBusy(true); setErr(''); setMsg('')
1628
1639
  try {
1629
- const d = await callWorkspaceView({ action: 'session', sessionId: sid, hidden })
1640
+ const d = await callWorkspaceView({ action: 'session', sessionId: sid, hidden, includeAgents: showAgents, includeBlank: showBlank }, { includeAgents: showAgents, includeBlank: showBlank })
1630
1641
  setData(d)
1642
+ setMsg(d.live === true
1643
+ ? M('已更新,会话列表已同步', 'Updated — the session list is in sync')
1644
+ : M('已更新;宿主服务暂不可用,已直接写入状态文件', 'Updated; host service unavailable, wrote the state file directly'))
1631
1645
  } catch (e) { setErr(String((e && e.message) || e)) }
1632
1646
  finally { setBusy(false) }
1633
- }, [])
1647
+ }, [showAgents, showBlank])
1634
1648
 
1635
1649
  const stateLabel = (st) => st === 'archive' ? M('归档', 'Archived')
1636
1650
  : st === 'hide-sessions' ? M('隐藏会话', 'Sessions hidden')
@@ -1652,16 +1666,45 @@ window.__ModuleLoader__.load({
1652
1666
 
1653
1667
  const wss = data.workspaces || []
1654
1668
  const archived = wss.filter(w => w.state === 'archive').length
1669
+ const agentHidden = Number(data.agentHidden || 0)
1670
+ const blankHidden = Number(data.blankHidden || 0)
1655
1671
  return h('div', { style: S.card },
1656
1672
  h('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', flexWrap: 'wrap' } },
1657
1673
  h('div', { style: S.cardTitle }, M('工作区显示状态', 'Workspace visibility')),
1658
1674
  h('div', { style: { ...S.hint, flex: 1, minWidth: '160px' } },
1659
- M('点工作区展开会话;点「修改」后才可切换状态。改动写入本机 DSH,重启或刷新会话列表后生效。', 'Click a workspace to expand sessions; click Edit to change states. Changes write to local DSH and take effect after restarting or refreshing the session list.')),
1675
+ M('点工作区展开会话;点「修改」后才可切换状态。改动即时生效,会话列表会跟着变。', 'Click a workspace to expand sessions; click Edit to change states. Changes apply immediately and the session list follows.')),
1676
+ h('label', {
1677
+ style: { display: 'inline-flex', alignItems: 'center', gap: '4px', fontSize: '12px', color: 'var(--dsw-alias-label-secondary)', cursor: 'pointer' },
1678
+ title: M('默认隐藏空会话(没跑过对话的历史条目)与 Mnemon 空闲审查的父容器,勾选后一并列出', 'Blank sessions (never used) and Mnemon idle-review parents are hidden by default; tick to list them too'),
1679
+ },
1680
+ h('input', {
1681
+ type: 'checkbox',
1682
+ checked: showBlank,
1683
+ disabled: busy,
1684
+ onChange: (e) => setShowBlank(e.target.checked === true),
1685
+ }),
1686
+ h('span', null, M('显示空会话', 'Show blank')),
1687
+ ),
1688
+ h('label', {
1689
+ style: { display: 'inline-flex', alignItems: 'center', gap: '4px', fontSize: '12px', color: 'var(--dsw-alias-label-secondary)', cursor: 'pointer' },
1690
+ title: M('默认隐藏智能体(subagent)会话,勾选后一并列出', 'Agent (subagent) sessions are hidden by default; tick to list them too'),
1691
+ },
1692
+ h('input', {
1693
+ type: 'checkbox',
1694
+ checked: showAgents,
1695
+ disabled: busy,
1696
+ onChange: (e) => setShowAgents(e.target.checked === true),
1697
+ }),
1698
+ h('span', null, M('显示智能体', 'Show agents')),
1699
+ ),
1660
1700
  h('button', { type: 'button', style: S.btn, disabled: busy, onClick: load }, busy ? M('刷新中…', 'Refreshing…') : M('刷新', 'Refresh')),
1661
1701
  ),
1662
1702
  msg ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-success-primary, #1a7f37)' } }, msg) : null,
1663
1703
  err ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-error-primary)' } }, err) : null,
1664
- h('div', { style: S.footnote }, M('共 ' + wss.length + ' 个工作区,' + archived + ' 个已归档;归档的工作区会从列表消失,会话仍保留。', wss.length + ' workspaces, ' + archived + ' archived; archived ones disappear from the list, sessions are kept.')),
1704
+ h('div', { style: S.footnote },
1705
+ M('共 ' + wss.length + ' 个工作区,' + archived + ' 个已归档;归档的工作区会从列表消失,会话仍保留。', wss.length + ' workspaces, ' + archived + ' archived; archived ones disappear from the list, sessions are kept.')
1706
+ + (agentHidden > 0 && !showAgents ? M('已隐藏 ' + agentHidden + ' 条智能体会话。', ' ' + agentHidden + ' agent sessions hidden.') : '')
1707
+ + (blankHidden > 0 && !showBlank ? M('已隐藏 ' + blankHidden + ' 条空会话(含空闲审查父容器)。', ' ' + blankHidden + ' blank sessions hidden (incl. idle-review parents).') : '')),
1665
1708
  wss.length === 0
1666
1709
  ? h('div', { style: S.footnote }, M('没有工作区。', 'No workspaces.'))
1667
1710
  : h('div', { style: { display: 'flex', flexDirection: 'column', gap: '6px', marginTop: '2px' } },
package/index.js CHANGED
@@ -28,6 +28,8 @@ import { fileURLToPath } from 'node:url'
28
28
  import { runGuard, clearSessionCaches, appendGuardLog } from './runtime/tools/session-cache-guard.mjs'
29
29
  // 0.3.76:工作区显示状态(三态 + 会话独立隐藏),自包含读写 DSH 两个权威文件
30
30
  import { readView, setWorkspaceState, setSessionState } from './runtime/tools/workspace-view.mjs'
31
+ // 0.3.82:实时通道。拿不到 workspaceRegistry 时,这两个函数内部自动退回上面的文件写法。
32
+ import { setWorkspaceStateLive, setSessionStateLive } from './runtime/tools/workspace-view.mjs'
31
33
 
32
34
  const pluginRequire = createRequire(import.meta.url)
33
35
 
@@ -4036,6 +4038,22 @@ function ctxLoggerInfo(text) {
4036
4038
  try { loggerRef?.info?.(text) } catch { /* 没有 logger 就算了 */ }
4037
4039
  }
4038
4040
 
4041
+ /**
4042
+ * 0.3.82:拿宿主的 workspaceRegistry 服务(工作区账本的唯一权威)。
4043
+ * apply 执行时 registry 可能还没 start,热重载又会换实例,所以每次请求都惰性取一遍。
4044
+ */
4045
+ let ctxRef = null
4046
+ function workspaceRegistryOf() {
4047
+ try {
4048
+ const ctx = ctxRef
4049
+ if (!ctx) return null
4050
+ const reg = typeof ctx.get === 'function' ? ctx.get('workspaceRegistry') : (ctx.workspaceRegistry || null)
4051
+ return reg && typeof reg.archiveSession === 'function' ? reg : null
4052
+ } catch {
4053
+ return null
4054
+ }
4055
+ }
4056
+
4039
4057
  const cacheGuardState = {
4040
4058
  timer: null,
4041
4059
  interval: null,
@@ -4214,10 +4232,18 @@ async function handleCacheGuard(req, res, config) {
4214
4232
  }
4215
4233
 
4216
4234
  // 0.3.76:工作区显示状态。自包含读写,不依赖 session-manager API(那个要 owner 凭证)。
4235
+ // 0.3.82:改成优先走 workspaceRegistry(宿主服务)→ 落盘同时触发 session-list feed,
4236
+ // 面板上切隐藏/显示即时生效;拿不到 registry 时函数内部退回纯文件写法(live:false)。
4237
+ // 0.3.83:视图默认多折叠一类「空会话」(创建后没发过消息、也没跑过 turn),
4238
+ // 以及 Mnemon 空闲审查的父容器(它只有 subagent/catalog,按空会话判定),
4239
+ // 面板不会再列出一堆空白条目。`?agents=1` / `?blank=1` 分别把两类放回来。
4217
4240
  async function handleWorkspaceView(req, res, config) {
4218
4241
  const dshHome = dshHomeOf(config)
4242
+ const registry = workspaceRegistryOf()
4243
+ const includeAgents = Boolean(req.url && /[?&]agents=1\b/.test(req.url))
4244
+ const includeBlank = Boolean(req.url && /[?&]blank=1\b/.test(req.url))
4219
4245
  if (req.method === 'GET') {
4220
- try { sendJson(res, 200, { ok: true, ...readView(dshHome) }) }
4246
+ try { sendJson(res, 200, { ok: true, ...readView(dshHome, { includeAgents, includeBlank }) }) }
4221
4247
  catch (error) { sendJson(res, 400, { ok: false, error: String((error && error.message) || error) }) }
4222
4248
  return
4223
4249
  }
@@ -4227,13 +4253,15 @@ async function handleWorkspaceView(req, res, config) {
4227
4253
  const raw = await readBody(req)
4228
4254
  const body = raw.trim() ? JSON.parse(raw) : {}
4229
4255
  const action = String(body.action || '')
4256
+ const withAgents = body.includeAgents === true
4257
+ const withBlank = body.includeBlank === true
4230
4258
  if (action === 'workspace') {
4231
- const view = setWorkspaceState(dshHome, String(body.workspaceId || ''), String(body.state || ''))
4259
+ const view = await setWorkspaceStateLive(dshHome, String(body.workspaceId || ''), String(body.state || ''), { registry, includeAgents: withAgents, includeBlank: withBlank })
4232
4260
  sendJson(res, 200, { ok: true, ...view })
4233
4261
  return
4234
4262
  }
4235
4263
  if (action === 'session') {
4236
- const view = setSessionState(dshHome, String(body.sessionId || ''), body.hidden === true)
4264
+ const view = await setSessionStateLive(dshHome, String(body.sessionId || ''), body.hidden === true, { registry, includeAgents: withAgents, includeBlank: withBlank })
4237
4265
  sendJson(res, 200, { ok: true, ...view })
4238
4266
  return
4239
4267
  }
@@ -4410,6 +4438,7 @@ async function handleFeedback(req, res, config) {
4410
4438
  export function apply(ctx, config) {
4411
4439
  try {
4412
4440
  try { loggerRef = ctx?.logger || null } catch { }
4441
+ try { ctxRef = ctx || null } catch { }
4413
4442
  ctx.inject(['webServer'], (scoped) => {
4414
4443
  // 每个请求按 accept-language 决定返回中文还是英文:AsyncLocalStorage 让 t() 在
4415
4444
  // 任何异步后续里都能读到本次请求的语言,不用把语言参数一层层往下传。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-config-sync-plugin",
3
- "version": "0.3.81",
3
+ "version": "0.3.83",
4
4
  "type": "module",
5
5
  "description": "在 DSH 设置里查看 dsh-config 仓库与本机的同步状态,并生成退出后执行的 push/pull 脚本。同步动作本身不在应用内执行。面板与文案跟随客户端语言(中文/English)。",
6
6
  "main": "./index.js",
@@ -57,4 +57,4 @@
57
57
  "check": "node --check index.js && node --check client.js",
58
58
  "verify": "node tools/selftest.mjs && node tools/clientcheck.mjs"
59
59
  }
60
- }
60
+ }
@@ -116,14 +116,19 @@ function cleanTitle(text) {
116
116
  return s
117
117
  }
118
118
 
119
- /** 从单个会话日志文件提取标题。返回 {title} 并写入缓存。 */
119
+ /**
120
+ * 从单个会话日志文件提取标题、来源与空会话标记。返回 {title, origin, blank} 并写入缓存。
121
+ * origin 取自日志首个 `session` 头事件:`subagent` 表示智能体(子)会话;
122
+ * blank 表示从没跑过对话(没有 turn/start、没有首条用户消息)。
123
+ * 面板「工作区显示」卡片默认把这两类都折叠掉,只留用户自己真正聊过的会话。
124
+ */
120
125
  function titleFromFile(file) {
121
126
  let mtime = 0
122
- try { mtime = fs.statSync(file).mtimeMs } catch { return { title: '' } }
127
+ try { mtime = fs.statSync(file).mtimeMs } catch { return { title: '', origin: '', blank: false } }
123
128
  const key = `${file}:${mtime}`
124
129
  const hit = TITLE_CACHE.get(key)
125
130
  if (hit) return hit
126
- let result = { title: '' }
131
+ let result = { title: '', origin: '', blank: false }
127
132
  try {
128
133
  const buf = fs.readFileSync(file)
129
134
  let text = ''
@@ -140,10 +145,17 @@ function titleFromFile(file) {
140
145
  let fallbackTitle = '' // fallback 标题(取最后一条)
141
146
  let anyTitle = '' // 无 source 信息的兜底标题(取最后一条)
142
147
  let firstUserText = ''
148
+ let origin = '' // 会话来源:subagent = 智能体子会话
149
+ let sawTurn = false // 出现过 turn/start:真正跑过对话
143
150
  for (const line of text.split('\n')) {
144
151
  if (!line) continue
145
152
  let ev
146
153
  try { ev = JSON.parse(line) } catch { continue }
154
+ if (!origin && ev.type === 'session') {
155
+ if (typeof ev.origin === 'string') origin = ev.origin
156
+ else if (ev.data && typeof ev.data.origin === 'string') origin = ev.data.origin
157
+ }
158
+ if (ev.type === 'turn/start') sawTurn = true
147
159
  if (ev.type === 'session/title' && ev.data && typeof ev.data.title === 'string') {
148
160
  const kind = ev.data.source && ev.data.source.kind
149
161
  if (kind === 'provider') providerTitle = ev.data.title
@@ -160,9 +172,15 @@ function titleFromFile(file) {
160
172
  }
161
173
  }
162
174
  // 优先级与 DSH 面板一致:provider 正式标题 > fallback > 无来源 title > 首条用户消息
163
- result = { title: cleanTitle(providerTitle) || cleanTitle(fallbackTitle) || cleanTitle(anyTitle) || cleanTitle(firstUserText) }
175
+ result = {
176
+ title: cleanTitle(providerTitle) || cleanTitle(fallbackTitle) || cleanTitle(anyTitle) || cleanTitle(firstUserText),
177
+ origin,
178
+ // 空会话:从没跑过对话(没有 turn/start,也没有首条用户消息)。DSH 自己也算 blank,
179
+ // 这里独立算一遍,因为面板要据此把「新建了没发消息」的会话藏起来。
180
+ blank: !sawTurn && !firstUserText,
181
+ }
164
182
  } catch {
165
- result = { title: '' }
183
+ result = { title: '', origin: '', blank: false }
166
184
  }
167
185
  if (TITLE_CACHE.size > 400) TITLE_CACHE.clear()
168
186
  TITLE_CACHE.set(key, result)
@@ -192,27 +210,56 @@ function buildSessionLogIndex(dshHome) {
192
210
  return byId
193
211
  }
194
212
 
195
- /** 读视图:列出所有工作区 + 每个工作区下会话的隐藏状态 + 三态归一化 + 会话名称。 */
196
- export function readView(dshHome) {
213
+ /**
214
+ * 读视图:列出所有工作区 + 每个工作区下会话的隐藏状态 + 三态归一化 + 会话名称。
215
+ * 默认只留用户自己真正聊过的会话,折叠两类会话:
216
+ * ① 智能体会话(origin === 'subagent');
217
+ * ② 空会话(blank:从没跑过对话)。
218
+ * options.includeAgents=true 时把智能体也算进来;options.includeBlank=true 时把空会话也算进来。
219
+ * 三态与计数都只按保留下来的会话计算。
220
+ *
221
+ * 「Mnemon 空闲审查」的父容器(mnemon-review-owner-v1-*)被一并折叠:
222
+ * 它自己的 header 没有 origin(不是 subagent),但日志里只有一个 subagent/catalog
223
+ * 事件、没有 turn/start,因此按空会话判定隐藏;真正的审查内容在它指向的
224
+ * mnemon-review-v1-* 子会话里,那个带 origin=subagent,属于第 ① 类。
225
+ */
226
+ export function readView(dshHome, options = {}) {
227
+ const includeAgents = options.includeAgents === true
228
+ const includeBlank = options.includeBlank === true
197
229
  const ws = readJson(workspacePath(dshHome))
198
230
  const arch = readJson(archivePath(dshHome))
199
231
  if (!ws || !ws.tables || !ws.tables.workspaces) {
200
- return { ok: true, available: false, workspaces: [] }
232
+ return { ok: true, available: false, workspaces: [], includeAgents, includeBlank, agentHidden: 0, blankHidden: 0 }
201
233
  }
202
234
  const globalArchived = new Set(Array.isArray(ws.global?.archivedSessionIds) ? ws.global.archivedSessionIds : [])
203
235
  const archMap = (arch && arch.workspaces && typeof arch.workspaces === 'object') ? arch.workspaces : {}
204
236
  const logIndex = buildSessionLogIndex(dshHome)
205
237
  const workspaces = []
238
+ let totalAgents = 0
239
+ let totalBlank = 0
206
240
  for (const [wsId, rec] of Object.entries(ws.tables.workspaces)) {
207
241
  if (!rec || typeof rec !== 'object') continue
208
242
  const sessionIds = Array.isArray(rec.sessionIds) ? rec.sessionIds.slice() : []
209
243
  const archRec = archMap[wsId]
210
244
  const workspaceArchived = Boolean(archRec && archRec.archived === true)
211
- const sessions = sessionIds.map((sid) => {
245
+ const all = sessionIds.map((sid) => {
212
246
  const log = logIndex.get(sid)
213
- const title = log ? titleFromFile(log).title : ''
214
- return { id: sid, title, hidden: globalArchived.has(sid) }
247
+ const meta = log ? titleFromFile(log) : { title: '', origin: '', blank: false }
248
+ return {
249
+ id: sid,
250
+ title: meta.title,
251
+ hidden: globalArchived.has(sid),
252
+ agent: meta.origin === 'subagent',
253
+ blank: meta.blank === true,
254
+ }
215
255
  })
256
+ const agentCount = all.filter((s) => s.agent).length
257
+ const blankCount = all.filter((s) => !s.agent && s.blank).length
258
+ totalAgents += agentCount
259
+ totalBlank += blankCount
260
+ // 两道过滤独立生效:智能体一类、空会话一类。
261
+ let sessions = includeAgents ? all : all.filter((s) => !s.agent)
262
+ if (!includeBlank) sessions = sessions.filter((s) => !s.blank)
216
263
  const hiddenCount = sessions.filter((s) => s.hidden).length
217
264
  let state = 'normal'
218
265
  if (workspaceArchived) state = 'archive'
@@ -224,13 +271,15 @@ export function readView(dshHome) {
224
271
  path: typeof rec.path === 'string' ? rec.path : '',
225
272
  sessionCount: sessions.length,
226
273
  hiddenCount,
274
+ agentCount,
275
+ blankCount,
227
276
  state,
228
277
  archived: workspaceArchived,
229
278
  archivedAt: workspaceArchived && typeof archRec.archivedAt === 'number' ? archRec.archivedAt : 0,
230
279
  sessions,
231
280
  })
232
281
  }
233
- return { ok: true, available: true, workspaces }
282
+ return { ok: true, available: true, workspaces, includeAgents, includeBlank, agentHidden: totalAgents, blankHidden: totalBlank }
234
283
  }
235
284
 
236
285
  /** 切换一个工作区的三态。state ∈ normal | hide-sessions | archive。 */
@@ -290,3 +339,130 @@ export function setSessionState(dshHome, sessionId, hidden) {
290
339
  writeJsonAtomic(wsPath, ws)
291
340
  return readView(dshHome)
292
341
  }
342
+
343
+ /* ===================== 实时通道(0.3.82) =====================
344
+ * 直接改 JSON 文件只能改磁盘,宿主内存里的 workspaceRegistry.archivedSessionIds
345
+ * 与 session-list feed 都不会更新 —— 这就是以前「必须重启 DSH 才生效」的原因。
346
+ *
347
+ * 正路是走 workspaceRegistry 的三个公开方法:
348
+ * registry.archiveSession(id, {stopActivity}) → enqueueOperation → setState
349
+ * → global.set(state) 落盘 + storage domain changed
350
+ * → api-workspace-controller 的 feed.changed 发布 {type:'archived', archivedSessionIds}
351
+ * → 会话列表实时更新,无需重启。
352
+ * registry.unarchiveSession(id) 同理。
353
+ *
354
+ * registry 拿不到(插件先于 registry 启动、或宿主版本变更)时,自动退回上面的
355
+ * 纯文件写法并标记 live:false,保证功能不丢,只是需要刷新才生效。
356
+ */
357
+
358
+ /** 用 registry 改单个会话的隐藏状态;registry 不可用时返回 {via:'file'}。 */
359
+ async function applySessionState(registry, sessionId, hidden) {
360
+ if (!registry || typeof registry.archiveSession !== 'function') return { via: 'file', stopped: false }
361
+ if (hidden) {
362
+ const already = Array.isArray(registry.archivedSessionIds) && registry.archivedSessionIds.includes(sessionId)
363
+ if (already) return { via: 'live', stopped: false }
364
+ try {
365
+ await registry.archiveSession(sessionId, { stopActivity: false })
366
+ return { via: 'live', stopped: false }
367
+ } catch (error) {
368
+ const text = String((error && (error.code || error.name || error.message)) || '')
369
+ // 会话正在跑(有活动)时宿主会拒绝;带上 stopActivity 再试一次,先停掉活动再归档。
370
+ if (/active/i.test(text)) {
371
+ await registry.archiveSession(sessionId, { stopActivity: true })
372
+ return { via: 'live', stopped: true }
373
+ }
374
+ throw error
375
+ }
376
+ }
377
+ if (typeof registry.unarchiveSession !== 'function') return { via: 'file', stopped: false }
378
+ await registry.unarchiveSession(sessionId)
379
+ return { via: 'live', stopped: false }
380
+ }
381
+
382
+ /** 用 registry 内存里的 archivedSessionIds 修正视图的 hidden 标记(文件可能还没落盘)。 */
383
+ function withRegistryHidden(view, registry) {
384
+ if (!registry || !Array.isArray(registry.archivedSessionIds)) return view
385
+ const set = new Set(registry.archivedSessionIds)
386
+ const workspaces = (view.workspaces || []).map((w) => {
387
+ const sessions = (w.sessions || []).map((s) => ({ ...s, hidden: set.has(s.id) }))
388
+ const hiddenCount = sessions.filter((s) => s.hidden).length
389
+ let state = 'normal'
390
+ if (w.archived) state = 'archive'
391
+ else if (hiddenCount > 0 && hiddenCount === sessions.length && sessions.length > 0) state = 'hide-sessions'
392
+ else if (hiddenCount > 0) state = 'partial'
393
+ return { ...w, sessions, hiddenCount, state }
394
+ })
395
+ return { ...view, workspaces }
396
+ }
397
+
398
+ /**
399
+ * 实时切换工作区三态。成功后返回的状态是重新 readView 出来的快照。
400
+ * options.registry 传宿主 workspaceRegistry;传 null/undefined 时退回文件写法。
401
+ */
402
+ export async function setWorkspaceStateLive(dshHome, workspaceId, state, options = {}) {
403
+ const { registry = null, includeAgents = false, includeBlank = false } = options
404
+ if (!['normal', 'hide-sessions', 'archive'].includes(state)) {
405
+ throw new Error(`不支持的工作区状态:${state}`)
406
+ }
407
+ const wsPath = workspacePath(dshHome)
408
+ const archPath = archivePath(dshHome)
409
+ const ws = readJson(wsPath)
410
+ if (!ws || !ws.tables || !ws.tables.workspaces || !ws.tables.workspaces[workspaceId]) {
411
+ throw new Error(`工作区不存在:${workspaceId}`)
412
+ }
413
+ const rec = ws.tables.workspaces[workspaceId]
414
+ const sids = Array.isArray(rec.sessionIds) ? rec.sessionIds.slice() : []
415
+
416
+ // 工作区归档记录(session-manager 侧)先按旧写法写好:registry 只管会话级 archivedSessionIds。
417
+ const arch = readJson(archPath) || { version: 1, workspaces: {} }
418
+ if (!arch.workspaces || typeof arch.workspaces !== 'object') arch.workspaces = {}
419
+ if (state === 'archive') {
420
+ arch.workspaces[workspaceId] = {
421
+ workspaceId,
422
+ archived: true,
423
+ archivedAt: Date.now(),
424
+ sessionIds: sids,
425
+ pending: [],
426
+ }
427
+ } else {
428
+ delete arch.workspaces[workspaceId]
429
+ }
430
+ writeJsonAtomic(archPath, arch)
431
+
432
+ const live = Boolean(registry && typeof registry.archiveSession === 'function')
433
+ if (!live) {
434
+ // 没 registry:完全按旧的文件写法(含 global.archivedSessionIds),行为不变。
435
+ return { ...setWorkspaceState(dshHome, workspaceId, state), live: false }
436
+ }
437
+
438
+ const errors = []
439
+ let stopped = 0
440
+ const results = await Promise.all(sids.map(async (sid) => {
441
+ try {
442
+ const r = await applySessionState(registry, sid, state !== 'normal')
443
+ if (r.stopped) stopped += 1
444
+ return r
445
+ } catch (error) {
446
+ errors.push(`${sid}: ${String((error && error.message) || error)}`)
447
+ return { via: 'error' }
448
+ }
449
+ }))
450
+ if (errors.length > 0) {
451
+ // 实时通道部分失败:退回文件写法把状态对齐,避免「写了一半」。
452
+ const fallback = setWorkspaceState(dshHome, workspaceId, state)
453
+ return { ...fallback, live: false, fallbackFrom: 'registry', stopped, errors }
454
+ }
455
+ void results
456
+ return { ...withRegistryHidden(readView(dshHome, { includeAgents, includeBlank }), registry), live: true, stopped }
457
+ }
458
+
459
+ /** 实时隐藏/显示单个会话。 */
460
+ export async function setSessionStateLive(dshHome, sessionId, hidden, options = {}) {
461
+ const { registry = null, includeAgents = false, includeBlank = false } = options
462
+ const live = Boolean(registry && typeof registry.archiveSession === 'function')
463
+ if (!live) {
464
+ return { ...setSessionState(dshHome, sessionId, hidden), live: false }
465
+ }
466
+ const r = await applySessionState(registry, sessionId, hidden)
467
+ return { ...withRegistryHidden(readView(dshHome, { includeAgents, includeBlank }), registry), live: true, stopped: r.stopped ? 1 : 0 }
468
+ }
@@ -1617,6 +1617,51 @@ console.log('== 工作区显示状态卡片 ==')
1617
1617
  check('面板新增「工作区显示」分区', cliSrc.includes("Section(M('工作区显示', 'Workspace visibility')"), '分区装配')
1618
1618
  }
1619
1619
 
1620
+ console.log('')
1621
+ console.log('== 0.3.82:工作区显示卡片折叠智能体 + 隐藏/显示即时生效 ==')
1622
+ {
1623
+ const wvSrc = existsSync(join(pluginRootSelf, 'runtime', 'tools', 'workspace-view.mjs')) ? readFileSync(join(pluginRootSelf, 'runtime', 'tools', 'workspace-view.mjs'), 'utf8') : ''
1624
+ const idxSrc = existsSync(join(pluginRootSelf, 'index.js')) ? readFileSync(join(pluginRootSelf, 'index.js'), 'utf8') : ''
1625
+ const cliSrc = existsSync(join(pluginRootSelf, 'client.js')) ? readFileSync(join(pluginRootSelf, 'client.js'), 'utf8') : ''
1626
+
1627
+ // 1) 智能体折叠:标题提取同时给出 origin,readView 支持 includeAgents 过滤
1628
+ check('智能体折叠:titleFromFile 同时返回 origin',
1629
+ wvSrc.includes("let result = { title: '', origin: '', blank: false }")
1630
+ && wvSrc.includes('if (!origin && ev.type === \'session\')')
1631
+ && wvSrc.includes('origin,'), 'workspace-view.mjs 的头事件解析')
1632
+ check('智能体折叠:readView 默认过滤 origin=subagent 并回报 agentHidden',
1633
+ wvSrc.includes('const includeAgents = options.includeAgents === true')
1634
+ && wvSrc.includes("agent: meta.origin === 'subagent'")
1635
+ && wvSrc.includes('let sessions = includeAgents ? all : all.filter((s) => !s.agent)')
1636
+ && wvSrc.includes('agentHidden: totalAgents'), 'workspace-view.mjs 的 readView')
1637
+ check('智能体折叠:卡片默认不显示、可勾选「显示智能体」',
1638
+ cliSrc.includes('const [showAgents, setShowAgents] = react.useState(false)')
1639
+ && cliSrc.includes("M('显示智能体', 'Show agents')")
1640
+ && cliSrc.includes("q.push('agents=1')"), 'client.js 的勾选框')
1641
+
1642
+ // 2) 即时生效:走 workspaceRegistry 而不是直接改文件
1643
+ check('即时生效:workspace-view 导出实时通道两函数',
1644
+ wvSrc.includes('export async function setWorkspaceStateLive')
1645
+ && wvSrc.includes('export async function setSessionStateLive')
1646
+ && wvSrc.includes('registry.archiveSession(sessionId, { stopActivity: false })')
1647
+ && wvSrc.includes('registry.unarchiveSession(sessionId)'), 'workspace-view.mjs 的实时通道')
1648
+ check('即时生效:宿主惰性取 workspaceRegistry',
1649
+ idxSrc.includes('let ctxRef = null')
1650
+ && idxSrc.includes('function workspaceRegistryOf()')
1651
+ && idxSrc.includes("ctx.get('workspaceRegistry')")
1652
+ && idxSrc.includes('ctxRef = ctx || null'), 'index.js 的 registry 取用')
1653
+ check('即时生效:路由改用 Live 版本并透传 registry',
1654
+ idxSrc.includes("import { setWorkspaceStateLive, setSessionStateLive } from './runtime/tools/workspace-view.mjs'")
1655
+ && idxSrc.includes('await setWorkspaceStateLive(') && idxSrc.includes('await setSessionStateLive(')
1656
+ && idxSrc.includes('{ registry, includeAgents: withAgents, includeBlank: withBlank }'), 'index.js 的 handleWorkspaceView')
1657
+ check('即时生效:registry 拿不到时退回文件写法并标记 live:false',
1658
+ wvSrc.includes('return { ...setWorkspaceState(dshHome, workspaceId, state), live: false }')
1659
+ && wvSrc.includes("live: false, fallbackFrom: 'registry'"), 'workspace-view.mjs 的降级')
1660
+ check('即时生效:卡片按 live 给不同提示(不再说「重启后生效」)',
1661
+ cliSrc.includes("d.live === true") && cliSrc.includes("M('已更新,会话列表已同步', 'Updated — the session list is in sync')")
1662
+ && !cliSrc.includes('重启或刷新会话列表后生效'), 'client.js 的提示措辞')
1663
+ }
1664
+
1620
1665
  console.log('')
1621
1666
  console.log('== 配置同步页面 5 点调整 ==')
1622
1667
  {
@@ -1626,7 +1671,7 @@ console.log('== 配置同步页面 5 点调整 ==')
1626
1671
  check('会话名称:工具从 session 日志提取 title 并随 readView 返回',
1627
1672
  wvSrc.includes('zstdDecompressSync') && wvSrc.includes('buildSessionLogIndex')
1628
1673
  && wvSrc.includes("'session/title'") && wvSrc.includes('title: rec.title || wsId')
1629
- && wvSrc.includes('const title = log ? titleFromFile(log).title'), 'workspace-view.mjs 的标题提取')
1674
+ && wvSrc.includes("const meta = log ? titleFromFile(log) : { title: '', origin: '', blank: false }"), 'workspace-view.mjs 的标题提取')
1630
1675
  check('会话名称:与 DSH 面板一致——优先 provider 正式标题,不再取第一条 fallback',
1631
1676
  wvSrc.includes('providerTitle') && wvSrc.includes("kind === 'provider'")
1632
1677
  && wvSrc.includes('cleanTitle(providerTitle) || cleanTitle(fallbackTitle)')