dsh-config-sync-plugin 0.3.75 → 0.3.76
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 +13 -1
- package/README.md +13 -1
- package/client.js +127 -2
- package/index.js +48 -8
- package/package.json +1 -1
- package/runtime/apply.ps1 +1 -0
- package/runtime/tools/workspace-view.mjs +153 -0
- package/tools/selftest.mjs +23 -1
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.
|
|
22
|
+
| npm | `npm i dsh-config-sync-plugin` | Use it as a dependency, or add `"dsh-config-sync-plugin": "^0.3.76"` 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
|
|
|
@@ -222,6 +222,18 @@ Workspaces and sessions you hide/archive from the config-sync panel used to show
|
|
|
222
222
|
|
|
223
223
|
Since 0.3.75 this file is part of the `settings` sync: a push writes it to the repo as `settings\workspace-archives.json`, and a pull restores it to the same path on B. When B starts, DSH reads `archived:true` workspaces and filters them out of the workspace list; their sessions move to the archived group and stop showing. This is whole-file replace semantics — machine A is authoritative. Hiding is not deletion: the workspace/session files remain and can be restored by un-hiding in DSH.
|
|
224
224
|
|
|
225
|
+
### New "Workspace visibility" card in the panel (0.3.76)
|
|
226
|
+
|
|
227
|
+
A new **Workspace visibility** section brings both native DSH hiding mechanisms into one card:
|
|
228
|
+
|
|
229
|
+
| Action | Effect | Backing file |
|
|
230
|
+
|---|---|---|
|
|
231
|
+
| Visible | Workspace shown normally, all sessions visible | Drop the archive record; remove sessions from `archivedSessionIds` |
|
|
232
|
+
| Hide sessions | Workspace stays in the list, its sessions go to Archived | Sessions written to `global.archivedSessionIds` in `<DshHome>\storages\workspace.json` |
|
|
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
|
+
|
|
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.
|
|
236
|
+
|
|
225
237
|
## New sessions land in the default workspace (since 0.3.28)
|
|
226
238
|
|
|
227
239
|
A finished sync brings DSH back up, and the client opens a fresh session on startup. Where that session lands is decided by `global.defaultWorkspaceId` in `<DshHome>\storages\workspace.json` — and DSH writes that value only during **first-time initialization**, so after a few syncs it can be left pointing at whatever workspace was used last.
|
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.
|
|
18
|
+
| npm | `npm i dsh-config-sync-plugin` | 适合把它当依赖管理,或在 profile 的 `package.json` 里写 `"dsh-config-sync-plugin": "^0.3.76"` 后 `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
|
|
|
@@ -242,6 +242,18 @@ pwsh -File runtime\sync.ps1 pull `
|
|
|
242
242
|
|
|
243
243
|
0.3.75 起把这份状态纳入 `settings` 同步:推送时写进仓库 `settings\workspace-archives.json`,拉取时还原到 B 机同名文件。B 机 DSH 启动后读到 `archived:true` 的工作区,会在工作区列表里过滤掉,它名下的会话也一并归到「已归档」,不再显示。整份覆盖语义——A 机的隐藏状态为准;这是「隐藏」不是删除,工作区与会话文件仍在,随时可以在 DSH 里取消隐藏恢复。
|
|
244
244
|
|
|
245
|
+
### 配置同步面板新增「工作区显示」卡片(0.3.76)
|
|
246
|
+
|
|
247
|
+
面板新增一个**工作区显示**分区,把 DSH 原生两套隐藏机制放进同一张卡里直接操作:
|
|
248
|
+
|
|
249
|
+
| 操作 | 作用 | 落点 |
|
|
250
|
+
|---|---|---|
|
|
251
|
+
| 显示 | 工作区正常可见,会话全显示 | 清掉归档记录;会话移出 `archivedSessionIds` |
|
|
252
|
+
| 隐藏会话 | 工作区留在列表,名下会话进「已归档」 | 会话写进 `<DshHome>\storages\workspace.json` 的 `global.archivedSessionIds` |
|
|
253
|
+
| 归档工作区 | 整个工作区从列表消失,会话保留 | `<DshHome>\dsh-session-manager\workspace-archives.v1.json` 写 `archived:true` + 会话一并按隐藏处理 |
|
|
254
|
+
|
|
255
|
+
每个工作区可独立切三态;展开后还能对单个会话单独「隐藏 / 显示」,两者互不影响(会话操作只动那一条 `archivedSessionIds`,不改工作区归档记录)。改动直接写本机 DSH 的两套状态文件,不调 session-manager 的 Web API(那套 API 需要 DSH connection owner 凭证,插件路由拿不到)。会话列表有本地缓存,切换后重启或刷新会话列表生效。0.3.75 已把归档文件纳入同步,所以这里改的隐藏 / 归档状态也会跟着 push/pull 到另一台机。
|
|
256
|
+
|
|
245
257
|
## 同步后新会话落在默认工作区
|
|
246
258
|
|
|
247
259
|
`<DshHome>\storages\workspace.json` 的 `global.defaultWorkspaceId` 决定新会话落在哪。DSH 只在本机**首次初始化**写过一次,之后同步几轮就可能停在「上次用的工作区」。`post-exit.ps1` 在**客户端完全退出之后、重新拉起之前**把它校正到默认工作区(早写会被客户端退出时的回写盖掉)。
|
package/client.js
CHANGED
|
@@ -492,6 +492,23 @@ window.__ModuleLoader__.load({
|
|
|
492
492
|
return body
|
|
493
493
|
}
|
|
494
494
|
|
|
495
|
+
/** 工作区显示状态:三态(显示 / 隐藏会话 / 归档工作区)+ 会话级独立隐藏。 */
|
|
496
|
+
async function callWorkspaceView(payload) {
|
|
497
|
+
const res = await fetch('/config-sync/workspace-view', payload
|
|
498
|
+
? {
|
|
499
|
+
method: 'POST',
|
|
500
|
+
cache: 'no-store',
|
|
501
|
+
credentials: 'same-origin',
|
|
502
|
+
headers: jsonHeaders,
|
|
503
|
+
body: JSON.stringify(payload),
|
|
504
|
+
}
|
|
505
|
+
: { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
|
|
506
|
+
const text = await res.text()
|
|
507
|
+
let body
|
|
508
|
+
try { body = text ? JSON.parse(text) : null } catch { throw badJson(res) }
|
|
509
|
+
if (!res.ok || !body || body.ok !== true) throw new Error((body && body.error) || `${res.status}`)
|
|
510
|
+
return body
|
|
511
|
+
}
|
|
495
512
|
/** 取一份体检数据 + 生成脚本动作,供两个入口复用。 */
|
|
496
513
|
function useSync() {
|
|
497
514
|
const [data, setData] = react.useState(null)
|
|
@@ -1570,6 +1587,112 @@ window.__ModuleLoader__.load({
|
|
|
1570
1587
|
)
|
|
1571
1588
|
}
|
|
1572
1589
|
|
|
1590
|
+
function WorkspaceViewCard() {
|
|
1591
|
+
const [data, setData] = react.useState(null)
|
|
1592
|
+
const [err, setErr] = react.useState('')
|
|
1593
|
+
const [busy, setBusy] = react.useState(false)
|
|
1594
|
+
const [msg, setMsg] = react.useState('')
|
|
1595
|
+
const [expanded, setExpanded] = react.useState({})
|
|
1596
|
+
|
|
1597
|
+
const load = react.useCallback(async () => {
|
|
1598
|
+
setBusy(true); setErr('')
|
|
1599
|
+
try { setData(await callWorkspaceView()) }
|
|
1600
|
+
catch (e) { setErr(String((e && e.message) || e)) }
|
|
1601
|
+
finally { setBusy(false) }
|
|
1602
|
+
}, [])
|
|
1603
|
+
react.useEffect(() => { load() }, [load])
|
|
1604
|
+
|
|
1605
|
+
const changeWorkspace = react.useCallback(async (wsId, state) => {
|
|
1606
|
+
setBusy(true); setErr(''); setMsg('')
|
|
1607
|
+
try {
|
|
1608
|
+
const d = await callWorkspaceView({ action: 'workspace', workspaceId: wsId, state })
|
|
1609
|
+
setData(d)
|
|
1610
|
+
setMsg(M('已更新工作区显示状态', 'Workspace view state updated'))
|
|
1611
|
+
} catch (e) { setErr(String((e && e.message) || e)) }
|
|
1612
|
+
finally { setBusy(false) }
|
|
1613
|
+
}, [])
|
|
1614
|
+
|
|
1615
|
+
const changeSession = react.useCallback(async (sid, hidden) => {
|
|
1616
|
+
setBusy(true); setErr(''); setMsg('')
|
|
1617
|
+
try {
|
|
1618
|
+
const d = await callWorkspaceView({ action: 'session', sessionId: sid, hidden })
|
|
1619
|
+
setData(d)
|
|
1620
|
+
} catch (e) { setErr(String((e && e.message) || e)) }
|
|
1621
|
+
finally { setBusy(false) }
|
|
1622
|
+
}, [])
|
|
1623
|
+
|
|
1624
|
+
const stateLabel = (st) => st === 'archive' ? M('归档', 'Archived')
|
|
1625
|
+
: st === 'hide-sessions' ? M('隐藏会话', 'Sessions hidden')
|
|
1626
|
+
: st === 'partial' ? M('部分隐藏', 'Partly hidden')
|
|
1627
|
+
: M('显示', 'Visible')
|
|
1628
|
+
|
|
1629
|
+
const opts = [
|
|
1630
|
+
['normal', M('显示', 'Visible')],
|
|
1631
|
+
['hide-sessions', M('隐藏会话', 'Sessions hidden')],
|
|
1632
|
+
['archive', M('归档工作区', 'Archive workspace')],
|
|
1633
|
+
]
|
|
1634
|
+
|
|
1635
|
+
if (!data || !data.available) {
|
|
1636
|
+
return h('div', { style: S.card },
|
|
1637
|
+
h('div', { style: S.cardTitle }, M('工作区显示状态', 'Workspace visibility')),
|
|
1638
|
+
h('div', { style: S.hint }, err ? M(`读取失败:${err}`, `Read failed: ${err}`) : M('本机还没有工作区数据,DSH 初始化后可用。', 'No workspace data yet — available after DSH initializes.')))
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
const wss = data.workspaces || []
|
|
1642
|
+
const archived = wss.filter(w => w.state === 'archive').length
|
|
1643
|
+
return h('div', { style: S.card },
|
|
1644
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', flexWrap: 'wrap' } },
|
|
1645
|
+
h('div', { style: S.cardTitle }, M('工作区显示状态', 'Workspace visibility')),
|
|
1646
|
+
h('div', { style: { ...S.hint, flex: 1, minWidth: '160px' } },
|
|
1647
|
+
M('三态切换工作区;展开后逐个隐藏 / 显示会话。改动写入本机 DSH,重启或刷新会话列表后生效。', 'Switch a workspace between three states; expand to hide/show individual sessions. Changes write to local DSH and take effect after restarting or refreshing the session list.')),
|
|
1648
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: load }, busy ? M('刷新中…', 'Refreshing…') : M('刷新', 'Refresh')),
|
|
1649
|
+
),
|
|
1650
|
+
msg ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-success-primary, #1a7f37)' } }, msg) : null,
|
|
1651
|
+
err ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-error-primary)' } }, err) : null,
|
|
1652
|
+
h('div', { style: S.footnote }, M(`共 ${wss.length} 个工作区,${archived} 个已归档;归档的工作区会从列表消失,会话仍保留。`, `${wss.length} workspaces, ${archived} archived; archived ones disappear from the list, sessions are kept.`)),
|
|
1653
|
+
wss.length === 0
|
|
1654
|
+
? h('div', { style: S.footnote }, M('没有工作区。', 'No workspaces.'))
|
|
1655
|
+
: h('div', { style: { display: 'flex', flexDirection: 'column', gap: '6px', marginTop: '2px' } },
|
|
1656
|
+
wss.map(w => {
|
|
1657
|
+
const open = !!expanded[w.workspaceId]
|
|
1658
|
+
return h('div', { key: w.workspaceId, style: { border: '1px solid var(--dsw-alias-border-l1)', borderRadius: '8px', padding: '8px 10px' } },
|
|
1659
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', flexWrap: 'wrap' } },
|
|
1660
|
+
h('button', {
|
|
1661
|
+
type: 'button', style: S.btn, onClick: () => setExpanded(e => ({ ...e, [w.workspaceId]: !open })),
|
|
1662
|
+
title: open ? M('收起会话', 'Collapse sessions') : M('展开会话', 'Expand sessions'),
|
|
1663
|
+
}, open ? '▾' : '▸'),
|
|
1664
|
+
h('span', { style: { fontSize: '12px', fontWeight: 600, minWidth: '90px' } }, w.title || w.workspaceId.slice(0, 8)),
|
|
1665
|
+
h('span', { style: chipStyle(w.state === 'archive' ? 'warn' : w.state === 'normal' ? 'ok' : 'pull') }, stateLabel(w.state)),
|
|
1666
|
+
h('span', { style: { ...S.footnote, flex: 1 } }, M(`${w.sessionCount} 会话 · ${w.hiddenCount} 隐藏`, `${w.sessionCount} sessions · ${w.hiddenCount} hidden`)),
|
|
1667
|
+
h('select', {
|
|
1668
|
+
value: w.state === 'partial' ? 'partial' : w.state,
|
|
1669
|
+
disabled: busy,
|
|
1670
|
+
onChange: (e) => { if (e.target.value !== 'partial') changeWorkspace(w.workspaceId, e.target.value) },
|
|
1671
|
+
style: { fontSize: '12px', padding: '3px 6px', borderRadius: '6px', border: '1px solid var(--dsw-alias-border-l1)', background: 'var(--dsw-alias-bg-base)', color: 'var(--dsw-alias-label-primary)' },
|
|
1672
|
+
},
|
|
1673
|
+
w.state === 'partial' ? h('option', { value: 'partial' }, stateLabel('partial')) : null,
|
|
1674
|
+
opts.map(([v, label]) => h('option', { key: v, value: v }, label)),
|
|
1675
|
+
),
|
|
1676
|
+
),
|
|
1677
|
+
open
|
|
1678
|
+
? h('div', { style: { display: 'flex', flexDirection: 'column', gap: '2px', marginTop: '6px', paddingLeft: '18px' } },
|
|
1679
|
+
(w.sessions || []).length === 0
|
|
1680
|
+
? h('div', { style: S.footnote }, M('这个工作区还没有会话。', 'No sessions in this workspace.'))
|
|
1681
|
+
: w.sessions.map(s => h('div', { key: s.id, style: { display: 'flex', alignItems: 'center', gap: '8px', fontSize: '12px', lineHeight: '18px' } },
|
|
1682
|
+
h('span', { style: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', color: s.hidden ? 'var(--dsw-alias-label-tertiary)' : 'var(--dsw-alias-label-secondary)' } }, s.id),
|
|
1683
|
+
h('button', {
|
|
1684
|
+
type: 'button', style: S.btn, disabled: busy,
|
|
1685
|
+
onClick: () => changeSession(s.id, !s.hidden),
|
|
1686
|
+
}, s.hidden ? M('显示', 'Show') : M('隐藏', 'Hide')),
|
|
1687
|
+
)),
|
|
1688
|
+
)
|
|
1689
|
+
: null,
|
|
1690
|
+
)
|
|
1691
|
+
}),
|
|
1692
|
+
),
|
|
1693
|
+
h('div', { style: S.footnote }, M('会话改动只动这一条;工作区三态作用于整组。', 'Session changes affect only that session; workspace states affect the whole group.')),
|
|
1694
|
+
)
|
|
1695
|
+
}
|
|
1573
1696
|
function ScopeCard() {
|
|
1574
1697
|
const [state, setState] = react.useState(null)
|
|
1575
1698
|
const [open, setOpen] = react.useState({})
|
|
@@ -2468,6 +2591,7 @@ window.__ModuleLoader__.load({
|
|
|
2468
2591
|
'Push/pull must run after DSH fully exits: generate, quit, then double-click.')),
|
|
2469
2592
|
)
|
|
2470
2593
|
|
|
2594
|
+
const workspaceViewCard = h(WorkspaceViewCard, {})
|
|
2471
2595
|
const remoteCard = data ? h(RemoteCard, { data, onSaved: refresh }) : null
|
|
2472
2596
|
const autoCard = data ? h(AutoCard, { data, onSaved: refresh }) : null
|
|
2473
2597
|
// 「还原备份」自己拿 status 里的 backup 段(快照列表),改动后让父层 refresh 重新读
|
|
@@ -2558,6 +2682,7 @@ window.__ModuleLoader__.load({
|
|
|
2558
2682
|
conflictCard
|
|
2559
2683
|
? Section(M('同步冲突', 'Sync conflicts'), M('这些文件挡住了拉取:逐项选完保存,再点「立即拉取」', 'These files block the pull: pick per file, save, then pull'), [conflictCard])
|
|
2560
2684
|
: null,
|
|
2685
|
+
Section(M('工作区显示', 'Workspace visibility'), M('三态切换工作区,展开后单独控制会话的隐藏 / 显示', 'Switch workspace states; expand to hide/show individual sessions'), [workspaceViewCard]),
|
|
2561
2686
|
Section(M('本机路径', 'Local paths'), M('每台机器确认一次即可:仓库里用占位符,落地时按这里展开', 'Confirm once per machine: the repo stores placeholders, expanded with these paths'), [rootsCard]),
|
|
2562
2687
|
Section(M('同步目标', 'Sync targets'), M('仓库与远端都是本机设置,改完即生效', 'Repo and remote are local settings, applied at once'), [repoCard, remoteCard].filter(Boolean)),
|
|
2563
2688
|
Section(M('自动化与插件更新', 'Automation & plugin update'), M('退出后自动做什么、插件自己怎么升级', 'What runs automatically after exit, and how the plugin upgrades'), [autoCard, updCard].filter(Boolean)),
|
|
@@ -3212,7 +3337,7 @@ window.__ModuleLoader__.load({
|
|
|
3212
3337
|
} catch { /* 插件路由还没起好就静默跳过,面板里仍会显示同一结果 */ }
|
|
3213
3338
|
}
|
|
3214
3339
|
|
|
3215
|
-
// ==================== 0.3.
|
|
3340
|
+
// ==================== 0.3.76:会话缓存守卫(客户端半身) ====================
|
|
3216
3341
|
// 宿主侧没法拦 agent-busy(它是 sessionController 内部抛的 RemoteError),
|
|
3217
3342
|
// 所以在这里包一层 sessions.create:撞上就上报、清缓存、去掉旧 sessionId 重试一次。
|
|
3218
3343
|
const BUSY_RE = /session\/agent-busy|is owned by subagent routing/i
|
|
@@ -3309,7 +3434,7 @@ window.__ModuleLoader__.load({
|
|
|
3309
3434
|
// 界面还没完全起来时 fetch 可能扑空,所以稍等一会儿再查;只查一次,不轮询。
|
|
3310
3435
|
try { setTimeout(announceLastResult, 1500) } catch { }
|
|
3311
3436
|
|
|
3312
|
-
// 0.3.
|
|
3437
|
+
// 0.3.76:给客户端的 sessions 服务套上 agent-busy 自愈钩子。
|
|
3313
3438
|
// 拿不到 sessions(老版本宿主 / 服务还没起来)就静默跳过,面板功能不受影响。
|
|
3314
3439
|
try {
|
|
3315
3440
|
if (typeof ctx.get === 'function') {
|
package/index.js
CHANGED
|
@@ -24,8 +24,10 @@ import { closeSync, existsSync, mkdirSync, mkdtempSync, openSync, readdirSync, r
|
|
|
24
24
|
import { homedir, hostname, tmpdir } from 'node:os'
|
|
25
25
|
import { basename, dirname, isAbsolute, join, relative } from 'node:path'
|
|
26
26
|
import { fileURLToPath } from 'node:url'
|
|
27
|
-
// 0.3.
|
|
27
|
+
// 0.3.76:会话投影缓存守卫(agent-busy 自动清缓存,让缓存按日志重建)
|
|
28
28
|
import { runGuard, clearSessionCaches, appendGuardLog } from './runtime/tools/session-cache-guard.mjs'
|
|
29
|
+
// 0.3.76:工作区显示状态(三态 + 会话独立隐藏),自包含读写 DSH 两个权威文件
|
|
30
|
+
import { readView, setWorkspaceState, setSessionState } from './runtime/tools/workspace-view.mjs'
|
|
29
31
|
|
|
30
32
|
const pluginRequire = createRequire(import.meta.url)
|
|
31
33
|
|
|
@@ -39,8 +41,10 @@ const ROUTE_CONFLICT = '/config-sync/conflict'
|
|
|
39
41
|
// 0.3.30:跨机路径确认(每台机器把自己的根目录报给插件一次)与问题反馈(落仓库 feedback\ 再推 GitHub)
|
|
40
42
|
const ROUTE_ROOTS = '/config-sync/roots'
|
|
41
43
|
const ROUTE_FEEDBACK = '/config-sync/feedback'
|
|
42
|
-
// 0.3.
|
|
44
|
+
// 0.3.76:会话投影缓存守卫(GET 只读扫描 / POST scan|sweep|clear|busy)
|
|
43
45
|
const ROUTE_CACHE_GUARD = '/config-sync/cache-guard'
|
|
46
|
+
// 0.3.76:工作区显示状态(GET 读 / POST workspace 三态 | session 独立隐藏)
|
|
47
|
+
const ROUTE_WORKSPACE_VIEW = '/config-sync/workspace-view'
|
|
44
48
|
const SETTINGS_NAME = 'dsh-config-sync.json'
|
|
45
49
|
/** 本插件自己的安装目录(插件根,含 runtime\ 与 index.js)—— 插件备份还原时的目标。 */
|
|
46
50
|
const PLUGIN_ROOT = fileURLToPath(new URL('.', import.meta.url)).replace(/[\\/]+$/, '')
|
|
@@ -237,7 +241,7 @@ function readSettings(dshHome) {
|
|
|
237
241
|
// 同步完成重启前把 DSH 的「默认工作区」校正到谁:
|
|
238
242
|
// 留空 = 自动找名字/路径是 default-workspace 的工作区;可填工作区路径或 ID;填 off 关闭。
|
|
239
243
|
defaultWorkspace: typeof raw.defaultWorkspace === 'string' ? raw.defaultWorkspace : '',
|
|
240
|
-
// 0.3.
|
|
244
|
+
// 0.3.76:会话投影缓存守卫,默认开。关掉后既不定时扫描,也不理会客户端的 agent-busy 上报。
|
|
241
245
|
cacheGuard: raw.cacheGuard !== false,
|
|
242
246
|
}
|
|
243
247
|
}
|
|
@@ -1180,7 +1184,7 @@ async function inspect(config) {
|
|
|
1180
1184
|
const pending = c.items.filter((it) => !it.choice).length
|
|
1181
1185
|
return { exists: true, total: c.items.length, pending, at: c.at || '', backupDir: c.backupDir || '' }
|
|
1182
1186
|
})(),
|
|
1183
|
-
// 0.3.
|
|
1187
|
+
// 0.3.76:会话投影缓存守卫状态(面板「会话缓存守卫」卡用)
|
|
1184
1188
|
cacheGuard: cacheGuardSnapshot(config),
|
|
1185
1189
|
}
|
|
1186
1190
|
}
|
|
@@ -1962,7 +1966,7 @@ async function handleSettings(req, res, config) {
|
|
|
1962
1966
|
const autoPull = has('autoPull') ? body.autoPull === true : before.autoPull
|
|
1963
1967
|
const autoPush = has('autoPush') ? body.autoPush === true : before.autoPush
|
|
1964
1968
|
const autoRestart = has('autoRestart') ? body.autoRestart !== false : before.autoRestart
|
|
1965
|
-
// 0.3.
|
|
1969
|
+
// 0.3.76:会话投影缓存守卫开关,字段没给就沿用原值
|
|
1966
1970
|
const cacheGuard = has('cacheGuard') ? body.cacheGuard !== false : before.cacheGuard
|
|
1967
1971
|
|
|
1968
1972
|
if (!has('repoPath') && !has('remoteUrl') && !has('sshKey') &&
|
|
@@ -4022,7 +4026,7 @@ function newIssueUrl(repo, title, text, config) {
|
|
|
4022
4026
|
return `https://github.com/${repo}/issues/new?${q}`
|
|
4023
4027
|
}
|
|
4024
4028
|
|
|
4025
|
-
// ============================ 0.3.
|
|
4029
|
+
// ============================ 0.3.76:会话投影缓存守卫 ============================
|
|
4026
4030
|
// 背景:UI 点「新建会话」时会挑一条 summary.blank===true 的会话复用,挑中了 origin=subagent
|
|
4027
4031
|
// 的子会话就会被宿主拒绝(session/agent-busy:is owned by subagent routing)。
|
|
4028
4032
|
// 起因是投影缓存停在 session/created 那一刻(blank=true、seq=-1),而会话日志早就推进过,
|
|
@@ -4209,6 +4213,36 @@ async function handleCacheGuard(req, res, config) {
|
|
|
4209
4213
|
}
|
|
4210
4214
|
}
|
|
4211
4215
|
|
|
4216
|
+
// 0.3.76:工作区显示状态。自包含读写,不依赖 session-manager API(那个要 owner 凭证)。
|
|
4217
|
+
async function handleWorkspaceView(req, res, config) {
|
|
4218
|
+
const dshHome = dshHomeOf(config)
|
|
4219
|
+
if (req.method === 'GET') {
|
|
4220
|
+
try { sendJson(res, 200, { ok: true, ...readView(dshHome) }) }
|
|
4221
|
+
catch (error) { sendJson(res, 400, { ok: false, error: String((error && error.message) || error) }) }
|
|
4222
|
+
return
|
|
4223
|
+
}
|
|
4224
|
+
if (req.method !== 'POST') { sendJson(res, 405, { ok: false, error: 'GET/POST only' }); return }
|
|
4225
|
+
if (!originAllowed(req)) { sendJson(res, 403, { ok: false, error: 'cross-origin request rejected' }); return }
|
|
4226
|
+
try {
|
|
4227
|
+
const raw = await readBody(req)
|
|
4228
|
+
const body = raw.trim() ? JSON.parse(raw) : {}
|
|
4229
|
+
const action = String(body.action || '')
|
|
4230
|
+
if (action === 'workspace') {
|
|
4231
|
+
const view = setWorkspaceState(dshHome, String(body.workspaceId || ''), String(body.state || ''))
|
|
4232
|
+
sendJson(res, 200, { ok: true, ...view })
|
|
4233
|
+
return
|
|
4234
|
+
}
|
|
4235
|
+
if (action === 'session') {
|
|
4236
|
+
const view = setSessionState(dshHome, String(body.sessionId || ''), body.hidden === true)
|
|
4237
|
+
sendJson(res, 200, { ok: true, ...view })
|
|
4238
|
+
return
|
|
4239
|
+
}
|
|
4240
|
+
throw new Error(t('action 只能是 workspace / session', 'action must be workspace / session'))
|
|
4241
|
+
} catch (error) {
|
|
4242
|
+
sendJson(res, 400, { ok: false, error: String((error && error.message) || error) })
|
|
4243
|
+
}
|
|
4244
|
+
}
|
|
4245
|
+
|
|
4212
4246
|
async function handleFeedback(req, res, config) {
|
|
4213
4247
|
const dshHome = config?.dshHome || process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
4214
4248
|
const url = new URL(req.url || '/', 'http://127.0.0.1')
|
|
@@ -4430,12 +4464,18 @@ export function apply(ctx, config) {
|
|
|
4430
4464
|
path: ROUTE_FEEDBACK,
|
|
4431
4465
|
handler: withLang(handleFeedback),
|
|
4432
4466
|
}))
|
|
4433
|
-
// 0.3.
|
|
4467
|
+
// 0.3.76:会话投影缓存守卫(GET 只读扫描 / POST scan|sweep|clear|busy)
|
|
4434
4468
|
scoped.effect(() => scoped.webServer.register({
|
|
4435
4469
|
kind: 'exact',
|
|
4436
4470
|
path: ROUTE_CACHE_GUARD,
|
|
4437
4471
|
handler: withLang(handleCacheGuard),
|
|
4438
4472
|
}))
|
|
4473
|
+
// 0.3.76:工作区显示状态卡片
|
|
4474
|
+
scoped.effect(() => scoped.webServer.register({
|
|
4475
|
+
kind: 'exact',
|
|
4476
|
+
path: ROUTE_WORKSPACE_VIEW,
|
|
4477
|
+
handler: withLang(handleWorkspaceView),
|
|
4478
|
+
}))
|
|
4439
4479
|
})
|
|
4440
4480
|
// 开关打开才排一次启动检查(默认关 = 什么都不做)
|
|
4441
4481
|
scheduleAutoStart(config)
|
|
@@ -4443,7 +4483,7 @@ export function apply(ctx, config) {
|
|
|
4443
4483
|
// status 不用再为首屏那 2.5 秒的 ls-remote 埋单。
|
|
4444
4484
|
typeof setTimeout === 'function' ? setTimeout(() => { try { warmRemoteProbe(config) } catch { } }, 300) : null
|
|
4445
4485
|
installQuitWhenAllWindowsClosed(ctx)
|
|
4446
|
-
// 0.3.
|
|
4486
|
+
// 0.3.76:会话投影缓存守卫的定时扫描(默认开,设置里可关)
|
|
4447
4487
|
scheduleCacheGuard(config)
|
|
4448
4488
|
} catch (error) {
|
|
4449
4489
|
// 不抛:缺 webServer 的 profile 里这个插件静默不激活即可
|
package/package.json
CHANGED
package/runtime/apply.ps1
CHANGED
|
@@ -900,6 +900,7 @@ $localPluginMap = [ordered]@{
|
|
|
900
900
|
'dsh-our-free-model-2.8.0' = 'dsh-our-free-model'
|
|
901
901
|
'dsh-purge-1.4.0' = 'dsh-purge'
|
|
902
902
|
'dsh-config-sync-plugin-0.3.69' = 'dsh-config-sync-plugin'
|
|
903
|
+
'dsh-config-sync-plugin-0.3.76' = 'dsh-config-sync-plugin'
|
|
903
904
|
'dsh-config-sync-plugin-0.3.75' = 'dsh-config-sync-plugin'
|
|
904
905
|
'dsh-config-sync-plugin-0.3.74' = 'dsh-config-sync-plugin'
|
|
905
906
|
'dsh-config-sync-plugin-0.3.73' = 'dsh-config-sync-plugin'
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* workspace-view — 配置同步面板「工作区显示状态」卡片的宿主侧工具(0.3.76)
|
|
3
|
+
*
|
|
4
|
+
* 职责:在本插件内自包含地读写 DSH 的两套原生隐藏/归档状态文件,不依赖
|
|
5
|
+
* session-manager 的 web API(那个 API 需要 DSH connection owner 凭证,插件
|
|
6
|
+
* 自己的路由拿不到)。
|
|
7
|
+
*
|
|
8
|
+
* 两个权威落点:
|
|
9
|
+
* 1) <DshHome>\storages\workspace.json -> global.archivedSessionIds[] 会话级「隐藏」
|
|
10
|
+
* 2) <DshHome>\dsh-session-manager\workspace-archives.v1.json
|
|
11
|
+
* -> workspaces[wsId] = {workspaceId, archived:true, archivedAt, sessionIds, pending}
|
|
12
|
+
* 工作区级「归档」
|
|
13
|
+
*
|
|
14
|
+
* 三态(工作区):
|
|
15
|
+
* normal 显示:无 archive 记录 + 该工作区会话都不在 archivedSessionIds
|
|
16
|
+
* hide-sessions 隐藏会话:无 archive 记录 + 该工作区所有会话进 archivedSessionIds(工作区仍留列表)
|
|
17
|
+
* archive 归档工作区:写 archive 记录 archived:true + 所有会话进 archivedSessionIds(工作区从列表消失)
|
|
18
|
+
* partial 部分会话被单独隐藏(只读状态,前端显示但切换时按用户所选三态归一化)
|
|
19
|
+
*
|
|
20
|
+
* 会话级独立操作:隐藏/显示单个会话只增删 global.archivedSessionIds 里的一个 id,
|
|
21
|
+
* 不碰工作区 archive 记录 —— 与工作区三态互不影响。
|
|
22
|
+
*
|
|
23
|
+
* 格式保持:两个文件原本都是 UTF-8 无 BOM、LF、2 空格缩进、末尾一个 \n。
|
|
24
|
+
* 写回统一用 JSON.stringify(obj, null, 2) + '\n',实测与原文件逐字节一致。
|
|
25
|
+
*/
|
|
26
|
+
import * as fs from 'node:fs'
|
|
27
|
+
import { join } from 'node:path'
|
|
28
|
+
|
|
29
|
+
const WS_REL = ['storages', 'workspace.json']
|
|
30
|
+
const ARCH_REL = ['dsh-session-manager', 'workspace-archives.v1.json']
|
|
31
|
+
|
|
32
|
+
function readJson(path) {
|
|
33
|
+
try {
|
|
34
|
+
const s = fs.readFileSync(path, 'utf8').replace(/^\uFEFF/, '')
|
|
35
|
+
return JSON.parse(s)
|
|
36
|
+
} catch {
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 覆盖写:先写临时文件再 copyFile 覆盖(Windows 上 copyFile 覆盖是原子的),失败回退直写。 */
|
|
42
|
+
function writeJsonAtomic(path, obj) {
|
|
43
|
+
const text = JSON.stringify(obj, null, 2) + '\n'
|
|
44
|
+
const tmp = `${path}.wv-${process.pid}-${Date.now()}.tmp`
|
|
45
|
+
try {
|
|
46
|
+
fs.writeFileSync(tmp, text, 'utf8')
|
|
47
|
+
try {
|
|
48
|
+
fs.copyFileSync(tmp, path)
|
|
49
|
+
} finally {
|
|
50
|
+
try { fs.unlinkSync(tmp) } catch { }
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
try { fs.unlinkSync(tmp) } catch { }
|
|
54
|
+
fs.writeFileSync(path, text, 'utf8')
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function archivePath(dshHome) { return join(dshHome, ...ARCH_REL) }
|
|
59
|
+
function workspacePath(dshHome) { return join(dshHome, ...WS_REL) }
|
|
60
|
+
|
|
61
|
+
/** 读视图:列出所有工作区 + 每个工作区下会话的隐藏状态 + 三态归一化。 */
|
|
62
|
+
export function readView(dshHome) {
|
|
63
|
+
const ws = readJson(workspacePath(dshHome))
|
|
64
|
+
const arch = readJson(archivePath(dshHome))
|
|
65
|
+
if (!ws || !ws.tables || !ws.tables.workspaces) {
|
|
66
|
+
return { ok: true, available: false, workspaces: [] }
|
|
67
|
+
}
|
|
68
|
+
const globalArchived = new Set(Array.isArray(ws.global?.archivedSessionIds) ? ws.global.archivedSessionIds : [])
|
|
69
|
+
const archMap = (arch && arch.workspaces && typeof arch.workspaces === 'object') ? arch.workspaces : {}
|
|
70
|
+
const workspaces = []
|
|
71
|
+
for (const [wsId, rec] of Object.entries(ws.tables.workspaces)) {
|
|
72
|
+
if (!rec || typeof rec !== 'object') continue
|
|
73
|
+
const sessionIds = Array.isArray(rec.sessionIds) ? rec.sessionIds.slice() : []
|
|
74
|
+
const archRec = archMap[wsId]
|
|
75
|
+
const workspaceArchived = Boolean(archRec && archRec.archived === true)
|
|
76
|
+
const sessions = sessionIds.map((sid) => ({ id: sid, hidden: globalArchived.has(sid) }))
|
|
77
|
+
const hiddenCount = sessions.filter((s) => s.hidden).length
|
|
78
|
+
let state = 'normal'
|
|
79
|
+
if (workspaceArchived) state = 'archive'
|
|
80
|
+
else if (hiddenCount > 0 && hiddenCount === sessions.length && sessions.length > 0) state = 'hide-sessions'
|
|
81
|
+
else if (hiddenCount > 0) state = 'partial'
|
|
82
|
+
workspaces.push({
|
|
83
|
+
workspaceId: wsId,
|
|
84
|
+
title: rec.title || wsId,
|
|
85
|
+
path: typeof rec.path === 'string' ? rec.path : '',
|
|
86
|
+
sessionCount: sessions.length,
|
|
87
|
+
hiddenCount,
|
|
88
|
+
state,
|
|
89
|
+
archived: workspaceArchived,
|
|
90
|
+
archivedAt: workspaceArchived && typeof archRec.archivedAt === 'number' ? archRec.archivedAt : 0,
|
|
91
|
+
sessions,
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
return { ok: true, available: true, workspaces }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** 切换一个工作区的三态。state ∈ normal | hide-sessions | archive。 */
|
|
98
|
+
export function setWorkspaceState(dshHome, workspaceId, state) {
|
|
99
|
+
const wsPath = workspacePath(dshHome)
|
|
100
|
+
const archPath = archivePath(dshHome)
|
|
101
|
+
const ws = readJson(wsPath)
|
|
102
|
+
if (!ws || !ws.tables || !ws.tables.workspaces || !ws.tables.workspaces[workspaceId]) {
|
|
103
|
+
throw new Error(`工作区不存在:${workspaceId}`)
|
|
104
|
+
}
|
|
105
|
+
if (!['normal', 'hide-sessions', 'archive'].includes(state)) {
|
|
106
|
+
throw new Error(`不支持的工作区状态:${state}`)
|
|
107
|
+
}
|
|
108
|
+
const rec = ws.tables.workspaces[workspaceId]
|
|
109
|
+
const sids = Array.isArray(rec.sessionIds) ? rec.sessionIds.slice() : []
|
|
110
|
+
const arch = readJson(archPath) || { version: 1, workspaces: {} }
|
|
111
|
+
if (!arch.workspaces || typeof arch.workspaces !== 'object') arch.workspaces = {}
|
|
112
|
+
const ga = new Set(Array.isArray(ws.global?.archivedSessionIds) ? ws.global.archivedSessionIds : [])
|
|
113
|
+
if (!ws.global || typeof ws.global !== 'object') ws.global = {}
|
|
114
|
+
|
|
115
|
+
if (state === 'archive') {
|
|
116
|
+
arch.workspaces[workspaceId] = {
|
|
117
|
+
workspaceId,
|
|
118
|
+
archived: true,
|
|
119
|
+
archivedAt: Date.now(),
|
|
120
|
+
sessionIds: sids,
|
|
121
|
+
pending: [],
|
|
122
|
+
}
|
|
123
|
+
for (const sid of sids) ga.add(sid)
|
|
124
|
+
} else {
|
|
125
|
+
// normal / hide-sessions 都不该留工作区归档记录
|
|
126
|
+
delete arch.workspaces[workspaceId]
|
|
127
|
+
if (state === 'hide-sessions') {
|
|
128
|
+
for (const sid of sids) ga.add(sid)
|
|
129
|
+
} else {
|
|
130
|
+
for (const sid of sids) ga.delete(sid)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
ws.global.archivedSessionIds = Array.from(ga)
|
|
135
|
+
writeJsonAtomic(wsPath, ws)
|
|
136
|
+
writeJsonAtomic(archPath, arch)
|
|
137
|
+
return readView(dshHome)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** 单独隐藏/显示一个会话:只增删 global.archivedSessionIds,不碰工作区归档记录。 */
|
|
141
|
+
export function setSessionState(dshHome, sessionId, hidden) {
|
|
142
|
+
const wsPath = workspacePath(dshHome)
|
|
143
|
+
const ws = readJson(wsPath)
|
|
144
|
+
if (!ws || !ws.global || typeof ws.global !== 'object') {
|
|
145
|
+
throw new Error('workspace.json 缺少 global 段')
|
|
146
|
+
}
|
|
147
|
+
const ga = new Set(Array.isArray(ws.global.archivedSessionIds) ? ws.global.archivedSessionIds : [])
|
|
148
|
+
if (hidden) ga.add(sessionId)
|
|
149
|
+
else ga.delete(sessionId)
|
|
150
|
+
ws.global.archivedSessionIds = Array.from(ga)
|
|
151
|
+
writeJsonAtomic(wsPath, ws)
|
|
152
|
+
return readView(dshHome)
|
|
153
|
+
}
|
package/tools/selftest.mjs
CHANGED
|
@@ -94,7 +94,7 @@ function check(label, cond, detail = '') {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
console.log('== dsh-config-sync-plugin 宿主半身自检 ==')
|
|
97
|
-
check('apply() 注册了路由', routes.size ===
|
|
97
|
+
check('apply() 注册了路由', routes.size === 12 && routes.has('/config-sync/update') && routes.has('/config-sync/scope') && routes.has('/config-sync/extra-config') && routes.has('/config-sync/conflict') && routes.has('/config-sync/roots') && routes.has('/config-sync/feedback') && routes.has('/config-sync/cache-guard') && routes.has('/config-sync/workspace-view'), `实际 ${routes.size} 条:${[...routes.keys()].join(', ')}`)
|
|
98
98
|
|
|
99
99
|
const status = await call('/config-sync/status', { headers: { host: 'localhost:3080' } })
|
|
100
100
|
const body = JSON.parse(status.body || '{}')
|
|
@@ -1594,5 +1594,27 @@ console.log('== 同步清单的两类新提示 ==')
|
|
|
1594
1594
|
}
|
|
1595
1595
|
|
|
1596
1596
|
console.log('')
|
|
1597
|
+
|
|
1598
|
+
console.log('')
|
|
1599
|
+
console.log('== 工作区显示状态卡片 ==')
|
|
1600
|
+
{
|
|
1601
|
+
const wvTool = join(pluginRootSelf, 'runtime', 'tools', 'workspace-view.mjs')
|
|
1602
|
+
const wvSrc = existsSync(wvTool) ? readFileSync(wvTool, 'utf8') : ''
|
|
1603
|
+
check('workspace-view 工具模块存在且导出三函数',
|
|
1604
|
+
wvSrc.includes('export function readView') && wvSrc.includes('export function setWorkspaceState') && wvSrc.includes('export function setSessionState'), 'runtime/tools/workspace-view.mjs')
|
|
1605
|
+
const idxSrc = existsSync(join(pluginRootSelf, 'index.js')) ? readFileSync(join(pluginRootSelf, 'index.js'), 'utf8') : ''
|
|
1606
|
+
check('宿主导入 workspace-view 并注册 /config-sync/workspace-view',
|
|
1607
|
+
idxSrc.includes("from './runtime/tools/workspace-view.mjs'")
|
|
1608
|
+
&& idxSrc.includes("const ROUTE_WORKSPACE_VIEW = '/config-sync/workspace-view'")
|
|
1609
|
+
&& idxSrc.includes('handleWorkspaceView'), 'index.js 的接线')
|
|
1610
|
+
const cliSrc = existsSync(join(pluginRootSelf, 'client.js')) ? readFileSync(join(pluginRootSelf, 'client.js'), 'utf8') : ''
|
|
1611
|
+
check('客户端有 WorkspaceViewCard 且三态与会话独立操作都接到路由',
|
|
1612
|
+
cliSrc.includes('function WorkspaceViewCard()')
|
|
1613
|
+
&& cliSrc.includes("fetch('/config-sync/workspace-view'")
|
|
1614
|
+
&& cliSrc.includes("action: 'workspace'") && cliSrc.includes("action: 'session'")
|
|
1615
|
+
&& cliSrc.includes("M('归档工作区', 'Archive workspace')") && cliSrc.includes("M('隐藏会话', 'Sessions hidden')")
|
|
1616
|
+
&& cliSrc.includes('workspaceViewCard'), 'client.js 的卡片')
|
|
1617
|
+
check('面板新增「工作区显示」分区', cliSrc.includes("Section(M('工作区显示', 'Workspace visibility')"), '分区装配')
|
|
1618
|
+
}
|
|
1597
1619
|
process.exit(failures === 0 ? 0 : 1)
|
|
1598
1620
|
|