dsh-progress-union 0.5.7 → 0.5.12

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,66 @@
2
2
 
3
3
  本项目的所有值得记录的变更都写在这里。版本号遵循语义化版本。
4
4
 
5
+ ## 0.5.12 (2026-12-01)
6
+
7
+ **fix(快捷入口):板在右栏时点头部图标 = 模拟点掉页签上的 ×,再收起整栏——不再出现「收起后展开右栏,板还摊在那儿」。**
8
+
9
+ 0.5.11 的失败留档(为什么它不算修好):
10
+
11
+ - **现象**:0.5.11 把入口改成 `toggleExpanded()` 只折叠整栏。用户点完再展开右栏,进度板仍停在原位。用户原话:「我要的是临时关闭进度板并隐藏右侧边栏,不是恢复侧边栏发现进度板还在」。
12
+ - **根因**:`ISidebarRight` 上「藏起来」有两种语义——`toggleExpanded()` 只折叠列,活动页签还是本板;`close(tabId)` 才是页签上 × 的行为。0.5.11 只用了前者,所以本板从未被关掉。
13
+ - **fix**:命中「本板是当前活动页签」后,先 `ctx.sidebarRight.close(RIGHT_TAB_KIND)`(等价点 ×,临时关闭;页签类型仍注册,再点入口由 `openTab` 重新打开),再用 `isExpanded()` 复查后决定是否 `toggleExpanded()`——关页签若已让宿主自动折叠,就不再翻回展开。两步各自 try/catch,软依赖坏了不把异常抛进 React 事件。
14
+ - **test**:`test/entry-toggle.test.mjs` 扩到 8 条,新增「折叠态板仍是活动页签 → 只关页签、不反手展开」与「停在别的页签 → 不得关掉本板页签」两条守卫。全量 123 条通过;`scripts/check-surface-classes.mjs` 仍是 0.5.10 起就有的 3 条既有告警(本版未新增类名)。
15
+
16
+ ## 0.5.11 (2026-12-01)
17
+
18
+ **fix(快捷入口):头部图标改成开关——板已经在右侧边栏(或 better-sidebar 工作台)展开时先收起,而不是只会重复打开。**
19
+
20
+ 现象:0.5.10 把板收敛进右侧边栏后,右栏已经摊着进度板时再点头部图标,什么都不发生——看上去「点了没反应」。
21
+
22
+ - **根因**:头部入口注入的是 `openPanel`(纯 `ctx.sidebarRight.openTab(RIGHT_TAB_KIND)`)。页签已打开且右栏已展开时,`openTab` 只是重新聚焦同一页签,没有任何收起路径;而输入框迷你条那一路(`togglePanel`)早就会收起,两个入口行为不一致。
23
+ - **fix**:头部入口改注入 `openPanel + togglePanel`,点击走 `togglePanel`:右栏展开且正停在本板 → `toggleExpanded()` 收起;右栏展开但停在别的页签 → `openTab()` 把本板切到前台(不动展开态);两处都没展开 → `openTab()` 打开。`openPanel` 保留为兜底,旧宿主/缺注入时仍是「只会打开」,不会变哑。
24
+ - **fix(软面)**:`togglePanel` 现在同时问 better-sidebar 的底部工作台(`getSnapshot().state.bottomOpen` + 工作台当前 `active` 页签 === `dsh-progress-union:board`);命中就 `closeTab()` 收起那一面,不误伤宿主右栏。读快照或关闭抛错时静默回落,软依赖坏了不拖累原生那一路。
25
+ - **test**:新增 `test/entry-toggle.test.mjs`(7 条)——用 vm 真物化 client.js 并执行 `apply`,锁死四种点击语义 + 软面抛错回落;W3 守卫同步改为「头部入口必须注入右栏开关」。全量 122 条通过;`scripts/check-surface-classes.mjs` 的 3 条告警在 0.5.10 就存在(已用 HEAD 归档复现:检查器扫到自己的源码 + `pb-dock-enable` 未定义样式),本版未新增类名。
26
+ ## 0.5.10 (2026-12-01)
27
+
28
+ **fix(侧栏顶部):删掉板子自带的「全面展开 / 恢复半开 / 收起」三个按钮——它们点了本来就没有反应,全屏与收起交给右侧边栏自己的 chrome。**
29
+
30
+ 现象:右栏进度板顶部那排按钮里,「全面展开」按下去什么都不发生;「收起」同理。
31
+
32
+ - **根因**:`ProgressSidePanel` 渲染的三个按钮只调 `props.toggleFullscreen` / `props.collapse`。原生右栏页签里虽注入了这两个回调,但宿主 `toggleFullscreen(target)` 的前置条件很硬——`isTargetCurrent(target)` 且 `isExpanded()` 且不是 float host,任一不满足就直接 return(静默);而重写"全面展开"按钮的 `target` 又依赖 `document.activeElement` 落在侧栏内。better-sidebar 页签里这两个 prop 根本没传(`?.` 静默跳过),于是"点了没反应"成了常态。
33
+ - **fix**:三个按钮与它们的 locale 文案(`sideFull`/`sideHalf`/`sideCollapse`)、`tabInfo` 读取、`collapse`/`toggleFullscreen` 注入与 `toggleFullscreen` helper 一并删除。全屏用右侧边栏自己的全屏按钮(`Ctrl+Alt+Enter`),收起用页签上的关闭或侧栏折叠——两处都是宿主提供、状态本来就可信的控件。
34
+ - **test**:新增 W4 守卫,钉死「不得再渲染 `props.toggleFullscreen` / `props.collapse`」「三个文案不得残留」「注入面不得再传全屏切换」。
35
+ ## 0.5.10-rc.1 (2026-12-01)
36
+
37
+ **fix(入口面):进度板只住在右侧边栏;主区「完整面板」整块移除——那个面没有收拢入口,进去出不来。**
38
+
39
+ 现象:点头部入口(或右栏里的「完整面板」链接)后,板以整页大页铺满主区,右上角只有令牌与「Agent 更新」,没有任何收拢/返回会话的控件。
40
+
41
+ - **根因**:0.5.8 把头部图标固定到 `ctx.layout.selectPanel('progress-union')` 注册的主区面板。宿主的主区面板只负责「把某个 key 的面板铺满主区」,收拢动作属于面板自己;本插件从未提供,宿主也不代给,于是那一页成了单向门。
42
+ - **fix**:删掉 `main` 槽位注册与 `ProgressPanel` 组件(-386 行),头部入口与右栏「完整面板」链接一并去掉;头部入口改注入 `openPanel`(= `ctx.sidebarRight.openTab(RIGHT_TAB_KIND)`),只把右栏页签切到本板。全屏交给右侧边栏自身的 chrome(全屏按钮 / Ctrl+Alt+Enter),收起用页签关闭或侧栏折叠。
43
+ - **test**:新增 W3 守卫,钉死「不得再注册主区面板」「不得调用 layout.selectPanel」「完整面板组件已移除」。
44
+ ## 0.5.9 (2026-12-01)
45
+
46
+ **fix(致命):client 半整体加载失败——第 16 行漏分号使 star IIFE 被 ASI 拼成对字符串的调用。**
47
+
48
+ 现象:0.5.6→0.5.8 期间,装了本插件的现场**一个入口都没有**:会话头部那排图标里没有进度板、输入框上方没有迷你条、右栏「+」/更多菜单里没有进度板、better-sidebar 里也没有独立页签;而宿主半正常(`/dsh-progress/status` 照常 200,进度文件照常写)。0.5.7 的分面隔离、错误边界、顺序调整因此全部无效——它们都在 apply 里,而 apply 根本没被执行。
49
+
50
+ - **根因**:`client.js` 第 16 行 `const PROGRESS_EVENT = 'progress-union:changed'` 没有分号,紧接着第 23 行以 `(function () {` 开头的 star 内联块(v3 阶梯注入)。ASI 不会在「字符串字面量 + 换行 + `(`」之间插分号,整段被解析成 `'progress-union:changed'(function(){...})`(IIFE 当参数)。
51
+ - **后果**:宿主浏览器半是 factory-form CJS,materialization 时抛 `TypeError: "progress-union:changed" is not a function`;cordis 把该行记成 import/activate 失败,boot audit 只对**可选条目**打一行 console.warn,页面照常启动。于是插件静默消失,宿主半不受影响。
52
+ - **fix**:补分号,物化恢复(`apply: function`,`inject: [slots, locale, layout, sidebarRight, sidebarRightTabs, sessions]` 原样导出)。
53
+ - **test(物化守卫)**:新增 `test/client-materialize.test.mjs`,用最小 stub(window/document/localStorage/CustomEvent/React)在 `vm` 里真的执行 client.js 并调用 `factory(require)`,锁死 apply/inject 的导出形状。此前所有测试都只断言源码文本,没有一处真的物化过 client.js,所以这条缺陷能连过 0.5.7 / 0.5.8 两个版本。
54
+
55
+ ## 0.5.8 (2026-12-01)
56
+
57
+ **fix(独立入口):进度板在侧栏里不再「没有入口」,头部图标回到主区完整面板。**
58
+
59
+ 现象:装了 better-sidebar 之后,点头部图标看到的是它的「任务管理」(子代理页),本板既没有独立页签卡片、也不再以完整面板出现。
60
+
61
+ - **根因(入口不可发现)**:W1 的 `sidebarRightTabs.register` 只给了 `id/kind/priority/title`,没有 `guide` 条目。宿主 0.2.x 的 `guide()` 只汇总各类型的 `guide` 条目——没有它就进不了「+」/开始页;better-sidebar 接管开始页时同样只搬 `guide()`,本板因此在这两处都不出现,唯一入口只剩一枚头部图标。
62
+ - **根因(打开的不是本板)**:0.5.7 把头部图标改挂 `togglePanel → ctx.sidebarRight.openTab('progress-union')`,只能落进右栏那排 tab;而 better-sidebar 默认在检测到子代理时自动激活「任务管理」页(本次会话有子代理、带未读红点),眼前看到的就是子代理页,看起来像本板被绑到了子代理上。本板与子代理没有任何数据关系,反方向也不成立:better-sidebar 的「任务管理」未被替代。
63
+ - **fix(完整面板)**:头部图标注入的 `openPanel` 改回 `openFullPanel`(`ctx.layout.selectPanel('progress-union')`),主区整页面板重新成为主面;右栏窄条仍可从 `guide` 卡片与 + 菜单打开,两者互不替代。
64
+ - **feat(guide 条目)**:W1 注册补 `guide: [{ id, order: 20, title: t('nav'), description: t('bsDesc') }]`,在宿主开始页与 better-sidebar 接管页各得一张「进度板」卡片,且描述明写「不是 better-sidebar 的『任务管理』」。
5
65
  ## 0.5.7 (2026-12-01)
6
66
 
7
67
  **fix(头部入口找回) + feat(better-sidebar 独立页签) —— 两条互不合并的工作流。**
package/client.js CHANGED
@@ -8,12 +8,11 @@ window.__ModuleLoader__.load({
8
8
  const NS = 'progressUnion'
9
9
  const API = '/progress-union'
10
10
  const STATUS_API = '/dsh-progress/status'
11
- const PANEL_ID = 'progress-union'
12
11
  const RIGHT_TAB_ID = 'dsh-progress-union'
13
12
  const RIGHT_TAB_KIND = 'progress-union'
14
13
  // better-sidebar 独立页签的 id(= SidebarTab.type)。与 RIGHT_TAB_KIND 是两个不同的入口面。
15
14
  const BS_TAB_ID = 'dsh-progress-union:board'
16
- const PROGRESS_EVENT = 'progress-union:changed'
15
+ const PROGRESS_EVENT = 'progress-union:changed';
17
16
 
18
17
  /* __STAR_INLINE_BEGIN__ — 手写内联 star 面板(v1→v2→v3 阶梯,_tools/star-row 计划)。
19
18
  * 本仓浏览器半边是手写 JS/无 TS 构建,插不进 star-row-copy.ts,故内联等价实现
@@ -24,7 +23,7 @@ window.__ModuleLoader__.load({
24
23
  var REPO_URL = "https://github.com/drscrewdriver/dsh-progress-union";
25
24
  var STAR_NS = "progress-union";
26
25
  var STAR_GEN = "v3"; /* ladder:gen */
27
- var STAR_VERSION = "0.5.7"; /* ladder:ver */
26
+ var STAR_VERSION = "0.5.12"; /* ladder:ver */
28
27
  var LANGS = ["zh", "en", "ja", "ko", "fr", "de", "it", "ru", "es", "pt"];
29
28
 
30
29
  // 三代共享:GitHub 单色 mark(octicon 轮廓,fill 随 currentColor)。
@@ -471,12 +470,8 @@ window.__ModuleLoader__.load({
471
470
  sideDetails: '详情',
472
471
  sideCurrentTask: '当前任务',
473
472
  sidePending: '待完成',
474
- sideCollapse: '收起',
475
- sideFull: '全面展开',
476
473
  lastSync: '同步于',
477
474
  syncFailed: '同步失败',
478
- sideHalf: '恢复半开',
479
- sideOpenFull: '完整面板',
480
475
  sideEditable: '可直接修改',
481
476
  sideEmptyDone: '还没有完成的任务',
482
477
  sideEmptyPending: '没有待完成的任务',
@@ -646,12 +641,8 @@ window.__ModuleLoader__.load({
646
641
  sideDetails: 'Details',
647
642
  sideCurrentTask: 'Current task',
648
643
  sidePending: 'Pending',
649
- sideCollapse: 'Collapse',
650
- sideFull: 'Fullscreen',
651
644
  lastSync: 'Synced',
652
645
  syncFailed: 'Sync failed',
653
- sideHalf: 'Half width',
654
- sideOpenFull: 'Full board',
655
646
  sideEditable: 'Editable',
656
647
  sideEmptyDone: 'Nothing completed yet',
657
648
  sideEmptyPending: 'Nothing pending',
@@ -1098,7 +1089,10 @@ window.__ModuleLoader__.load({
1098
1089
  onMouseLeave: () => setHovered(false),
1099
1090
  onClick: () => {
1100
1091
  try {
1101
- props.openPanel?.()
1092
+ // 快捷入口是开关:板已经在右栏展开时先收起,其余情况才打开。
1093
+ // togglePanel 缺失时退回旧行为(只打开),入口不因此变哑。
1094
+ const activate = props.togglePanel || props.openPanel
1095
+ activate?.()
1102
1096
  } catch (_error) {
1103
1097
  // The mini bar and sidebar remain available.
1104
1098
  }
@@ -1641,7 +1635,7 @@ window.__ModuleLoader__.load({
1641
1635
  try {
1642
1636
  props.openPanel?.()
1643
1637
  } catch (_error) {
1644
- // The full panel remains reachable from the sidebar.
1638
+ // The right sidebar tab stays the only surface for the board.
1645
1639
  }
1646
1640
  }
1647
1641
 
@@ -2341,8 +2335,6 @@ window.__ModuleLoader__.load({
2341
2335
  function ProgressSidePanel(props) {
2342
2336
  const t = makeT(props)
2343
2337
  const { sessionId } = props
2344
- const useTabInfo = props.useTabInfo
2345
- const tabInfo = useTabInfo ? useTabInfo() : undefined
2346
2338
  const { snapshot, setSnapshot, error: readError, lastSyncAt, refresh } = useProgressData(sessionId)
2347
2339
  const usageView = usageSummary(useSessionUsage(sessionId, props.usage))
2348
2340
  const [saving, setSaving] = useState(false)
@@ -2411,21 +2403,6 @@ window.__ModuleLoader__.load({
2411
2403
  [sessionId, setSnapshot],
2412
2404
  )
2413
2405
 
2414
- const collapse = () => {
2415
- try {
2416
- props.collapse?.()
2417
- } catch (_error) {
2418
- // The chrome control remains available.
2419
- }
2420
- }
2421
-
2422
- const openFull = () => {
2423
- try {
2424
- props.openFullPanel?.()
2425
- } catch (_error) {
2426
- // The sidebar icon remains available.
2427
- }
2428
- }
2429
2406
 
2430
2407
  const items = snapshot?.items || []
2431
2408
  const latestDone = items
@@ -2477,12 +2454,6 @@ window.__ModuleLoader__.load({
2477
2454
  },
2478
2455
  snapshot?.enabled === false ? t('autoOff') : t('autoOn'),
2479
2456
  ),
2480
- h(
2481
- 'button',
2482
- { type: 'button', className: 'pb-btn', onClick: () => props.toggleFullscreen?.() },
2483
- tabInfo?.sidebar?.fullscreen ? t('sideHalf') : t('sideFull'),
2484
- ),
2485
- h('button', { type: 'button', className: 'pb-btn', onClick: collapse }, t('sideCollapse')),
2486
2457
  ),
2487
2458
  ),
2488
2459
  h('p', { className: 'pb-side-sub' }, t('subtitle')),
@@ -2633,7 +2604,6 @@ window.__ModuleLoader__.load({
2633
2604
  h(
2634
2605
  'footer',
2635
2606
  { className: 'pb-side-footer' },
2636
- h('button', { type: 'button', className: 'pb-side-link', onClick: openFull }, t('sideOpenFull')),
2637
2607
  h('button', { type: 'button', className: 'pb-side-link', onClick: refresh }, t('refresh')),
2638
2608
  h('span', null, `${t('revision')} ${snapshot.revision}`),
2639
2609
  h(
@@ -2661,392 +2631,6 @@ window.__ModuleLoader__.load({
2661
2631
  )
2662
2632
  }
2663
2633
 
2664
- function ProgressPanel(props) {
2665
- const t = makeT(props)
2666
- const sessionId = props.useSessions
2667
- ? props.useSessions((state) => {
2668
- const rows = Object.values(state.byId || {})
2669
- const current = rows.find((row) => (row.retainedBy?.mainView ?? 0) > 0)
2670
- return current?.id
2671
- })
2672
- : undefined
2673
-
2674
- const [snapshot, setSnapshot] = useState(null)
2675
- const usageView = usageSummary(useSessionUsage(sessionId, props.usage))
2676
- const [loading, setLoading] = useState(true)
2677
- const [saving, setSaving] = useState(false)
2678
- const [loadError, setLoadError] = useState('')
2679
- const [actionError, setActionError] = useState('')
2680
- const [tick, setTick] = useState(0)
2681
- const revisionRef = useRef(0)
2682
-
2683
- useEffect(() => {
2684
- revisionRef.current = snapshot?.revision ?? 0
2685
- }, [snapshot?.revision])
2686
-
2687
- useEffect(() => {
2688
- if (!sessionId) return undefined
2689
- // The full main panel keeps agent updates on just like the sidebar
2690
- // body; there is no cleanup, so leaving the panel does not disable it.
2691
- setPanelActive(sessionId, true)
2692
- return undefined
2693
- }, [sessionId])
2694
-
2695
- const enableAuto = async () => {
2696
- if (!sessionId) return
2697
- await setAgentEnabled(sessionId, true)
2698
- setTick((value) => value + 1)
2699
- }
2700
-
2701
- useEffect(() => {
2702
- if (!sessionId) {
2703
- setSnapshot(null)
2704
- setLoading(false)
2705
- return undefined
2706
- }
2707
-
2708
- let active = true
2709
- let controller
2710
- setLoading(true)
2711
-
2712
- const load = async () => {
2713
- if (controller) controller.abort()
2714
- const ownController = (controller = new AbortController())
2715
- try {
2716
- const response = await fetch(
2717
- `${API}/snapshot?sessionId=${encodeURIComponent(sessionId)}`,
2718
- { credentials: 'same-origin', cache: 'no-store', signal: ownController.signal },
2719
- )
2720
- if (!response.ok) throw new Error(`HTTP ${response.status}`)
2721
- const next = await response.json()
2722
- if (!active) return
2723
- revisionRef.current = next.revision
2724
- setSnapshot(next)
2725
- setLoadError('')
2726
- setLoading(false)
2727
- } catch (error) {
2728
- if (!active || error?.name === 'AbortError') return
2729
- setLoadError(errorText(error))
2730
- setLoading(false)
2731
- }
2732
- }
2733
-
2734
- load()
2735
- const interval = window.setInterval(load, 3000)
2736
- const onVisibility = () => {
2737
- if (document.visibilityState === 'visible') load()
2738
- }
2739
- document.addEventListener('visibilitychange', onVisibility)
2740
-
2741
- return () => {
2742
- active = false
2743
- window.clearInterval(interval)
2744
- controller?.abort()
2745
- document.removeEventListener('visibilitychange', onVisibility)
2746
- }
2747
- }, [sessionId, tick])
2748
-
2749
- const mutate = useCallback(
2750
- async (changes) => {
2751
- if (!sessionId) return false
2752
- setSaving(true)
2753
- setActionError('')
2754
- try {
2755
- let result = await postChanges(sessionId, revisionRef.current, changes)
2756
- if (result.response.status === 409 && result.body?.snapshot) {
2757
- revisionRef.current = result.body.snapshot.revision
2758
- setSnapshot(result.body.snapshot)
2759
- result = await postChanges(sessionId, revisionRef.current, changes)
2760
- }
2761
- const { response, body } = result
2762
- if (!response.ok || !body || body.ok === false) {
2763
- if (body?.snapshot) {
2764
- revisionRef.current = body.snapshot.revision
2765
- setSnapshot(body.snapshot)
2766
- }
2767
- throw new Error(body?.error || `HTTP ${response.status}`)
2768
- }
2769
- revisionRef.current = body.revision
2770
- setSnapshot(body)
2771
- broadcastProgress(sessionId, body)
2772
- const addedTitles = (Array.isArray(changes) ? changes : [])
2773
- .filter((change) => change && !change.id && !change.remove && typeof change.title === 'string')
2774
- .map((change) => change.title.trim())
2775
- .filter(Boolean)
2776
- if (addedTitles.length > 0) {
2777
- props.wakeAgent?.(
2778
- sessionId,
2779
- `我在进度板新增了任务${addedTitles.map((title) => `「${title}」`).join('、')}。请按新任务推进。`,
2780
- )
2781
- }
2782
- return true
2783
- } catch (error) {
2784
- setActionError(errorText(error))
2785
- return false
2786
- } finally {
2787
- setSaving(false)
2788
- }
2789
- },
2790
- [sessionId],
2791
- )
2792
-
2793
- const patch = useCallback(
2794
- (item, fields) => mutate([{ id: item.id, ...fields }]),
2795
- [mutate],
2796
- )
2797
-
2798
- const items = snapshot?.items || []
2799
- const summary = snapshot?.summary || { total: 0, done: 0, doing: 0, todo: 0, blocked: 0, percent: 0 }
2800
- const doing = items.filter((item) => item.status === 'doing')
2801
- const todo = items.filter((item) => item.status === 'todo')
2802
- const blocked = items.filter((item) => item.status === 'blocked')
2803
- const done = items.filter((item) => item.status === 'done')
2804
-
2805
- const move = (item, direction) => {
2806
- const index = items.findIndex((candidate) => candidate.id === item.id)
2807
- const neighbor = items[index + direction]
2808
- if (!neighbor) return
2809
- mutate([
2810
- { id: item.id, order: neighbor.order },
2811
- { id: neighbor.id, order: item.order },
2812
- ])
2813
- }
2814
-
2815
- const renderItem = (item) => {
2816
- const index = items.findIndex((candidate) => candidate.id === item.id)
2817
- return h(ItemCard, {
2818
- key: item.id,
2819
- item,
2820
- t,
2821
- disabled: saving,
2822
- canMoveUp: index > 0,
2823
- canMoveDown: index >= 0 && index < items.length - 1,
2824
- onPatch: (fields) => patch(item, fields),
2825
- onRemove: () => mutate([{ id: item.id, remove: true }]),
2826
- onMove: (direction) => move(item, direction),
2827
- })
2828
- }
2829
-
2830
- if (!sessionId) {
2831
- return h(
2832
- 'div',
2833
- { className: 'pb-root' },
2834
- h('style', null, CSS),
2835
- h(
2836
- 'div',
2837
- { className: 'pb-inner' },
2838
- h(
2839
- 'header',
2840
- { className: 'pb-head' },
2841
- h(
2842
- 'div',
2843
- null,
2844
- h('h1', { className: 'pb-title' }, t('title')),
2845
- h('p', { className: 'pb-sub' }, t('subtitle')),
2846
- ),
2847
- ),
2848
- h(
2849
- 'div',
2850
- { className: 'pb-empty' },
2851
- h('h2', null, t('noSessionTitle')),
2852
- h('p', null, t('noSessionBody')),
2853
- ),
2854
- ),
2855
- )
2856
- }
2857
-
2858
- const focus = doing[0] || null
2859
- const updated = snapshot ? new Date(snapshot.updatedAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) : ''
2860
-
2861
- return h(
2862
- 'div',
2863
- { className: 'pb-root' },
2864
- h('style', null, CSS),
2865
- h(
2866
- 'div',
2867
- { className: 'pb-inner' },
2868
- h(
2869
- 'header',
2870
- { className: 'pb-head' },
2871
- h(
2872
- 'div',
2873
- null,
2874
- h('h1', { className: 'pb-title' }, t('title')),
2875
- h('p', { className: 'pb-sub' }, t('subtitle')),
2876
- ),
2877
- h(
2878
- 'div',
2879
- { className: 'pb-head-right' },
2880
- saving ? h('span', { className: 'pb-saving' }, t('saving')) : null,
2881
- snapshot?.pendingUserChanges
2882
- ? h('span', { className: 'pb-badge-pending' }, `${t('pending')} · ${snapshot.pendingUserChanges}`)
2883
- : null,
2884
- usageView
2885
- ? h(
2886
- 'span',
2887
- { className: 'pb-usage pb-usage-inline', title: usageTooltip(usageView, t) },
2888
- `${formatTokens(usageView.total)} tok${
2889
- usageView.cost == null ? '' : ` · ≈${formatCny(usageView.cost)}`
2890
- }`,
2891
- )
2892
- : null,
2893
- h(
2894
- 'button',
2895
- {
2896
- type: 'button',
2897
- className: snapshot?.enabled === false ? 'pb-btn pb-btn-primary' : 'pb-btn',
2898
- title: t('autoHint'),
2899
- onClick: async () => {
2900
- if (!sessionId) return
2901
- await setAgentEnabled(sessionId, snapshot?.enabled === false)
2902
- setTick((value) => value + 1)
2903
- },
2904
- },
2905
- snapshot?.enabled === false ? t('autoOff') : t('autoOn'),
2906
- ),
2907
- h(
2908
- 'span',
2909
- { className: 'pb-live', title: t('footerHint') },
2910
- h('i', { className: 'pb-dot' }),
2911
- t('live'),
2912
- ),
2913
- ),
2914
- ),
2915
- h(LlmAssistNotice, { assistant: snapshot?.assistant, t: props.t }),
2916
- snapshot?.enabled === false
2917
- ? h(
2918
- 'div',
2919
- { className: 'pb-warn' },
2920
- `${t('autoWarn')} `,
2921
- h(
2922
- 'button',
2923
- { type: 'button', className: 'pb-btn', onClick: enableAuto },
2924
- t('autoEnable'),
2925
- ),
2926
- )
2927
- : null,
2928
- loadError
2929
- ? h(
2930
- 'div',
2931
- { className: 'pb-warn pb-warn-error' },
2932
- `${t('readError')}${loadError} `,
2933
- h(
2934
- 'button',
2935
- { type: 'button', className: 'pb-btn', onClick: () => setTick((value) => value + 1) },
2936
- t('retry'),
2937
- ),
2938
- )
2939
- : null,
2940
- actionError
2941
- ? h(
2942
- 'div',
2943
- { className: 'pb-warn pb-warn-error' },
2944
- `${t('saveError')}${actionError}`,
2945
- )
2946
- : null,
2947
- snapshot?.storageError
2948
- ? h('div', { className: 'pb-warn' }, `${t('storageWarn')} ${snapshot.storageError}`)
2949
- : null,
2950
- loading && !snapshot
2951
- ? h('div', { className: 'pb-loading' }, t('loading'))
2952
- : h(
2953
- React.Fragment,
2954
- null,
2955
- h(
2956
- 'section',
2957
- { className: 'pb-overview' },
2958
- h(
2959
- 'div',
2960
- { className: 'pb-overview-top' },
2961
- h(
2962
- 'div',
2963
- { className: 'pb-big' },
2964
- String(summary.percent),
2965
- h('small', null, '%'),
2966
- ),
2967
- h(
2968
- 'div',
2969
- { className: 'pb-counts' },
2970
- h('span', { className: 'pb-chip' }, t('statusDone'), h('strong', null, summary.done)),
2971
- h('span', { className: 'pb-chip' }, t('statusDoing'), h('strong', null, summary.doing)),
2972
- h('span', { className: 'pb-chip' }, t('statusTodo'), h('strong', null, summary.todo)),
2973
- h('span', { className: 'pb-chip' }, t('statusBlocked'), h('strong', null, summary.blocked)),
2974
- ),
2975
- ),
2976
- h('div', { className: 'pb-bar' }, h('i', { style: { width: `${summary.percent}%` } })),
2977
- h(
2978
- 'div',
2979
- { className: 'pb-focus' },
2980
- focus
2981
- ? h(
2982
- React.Fragment,
2983
- null,
2984
- h('span', null, `${t('doingTitle')}:`),
2985
- h('b', null, focus.title),
2986
- focus.current ? h('span', null, ` · ${focus.current}`) : null,
2987
- )
2988
- : h('span', null, summary.total > 0 && summary.done === summary.total ? t('allDone') : t('noDoing')),
2989
- summary.blocked > 0 ? h('span', { className: 'pb-badge-pending' }, `${summary.blocked} ${t('blockedCount')}`) : null,
2990
- ),
2991
- ),
2992
- snapshot?.items?.length === 0
2993
- ? h(
2994
- 'div',
2995
- { className: 'pb-empty' },
2996
- h('h2', null, t('emptyTitle')),
2997
- h('p', null, t('emptyBody')),
2998
- )
2999
- : h(
3000
- React.Fragment,
3001
- null,
3002
- doing.length
3003
- ? h(Section, { title: t('doingTitle'), count: doing.length }, doing.map(renderItem))
3004
- : h(
3005
- 'section',
3006
- { className: 'pb-section' },
3007
- h('p', { className: 'pb-loading', style: { padding: '14px 0' } }, t('emptyDoing')),
3008
- ),
3009
- todo.length
3010
- ? h(Section, { title: t('todoTitle'), count: todo.length }, todo.map(renderItem))
3011
- : null,
3012
- blocked.length
3013
- ? h(
3014
- Section,
3015
- { title: t('blockedTitle'), count: blocked.length, hint: t('blockedHint') },
3016
- blocked.map(renderItem),
3017
- )
3018
- : null,
3019
- done.length
3020
- ? h(
3021
- 'details',
3022
- { className: 'pb-done-box' },
3023
- h('summary', null, `${t('doneTitle')} · ${done.length} ${t('doneCount')}`),
3024
- h('div', { className: 'pb-list' }, done.map(renderItem)),
3025
- )
3026
- : null,
3027
- ),
3028
- h(AddTask, {
3029
- t,
3030
- disabled: saving,
3031
- onAdd: (title) =>
3032
- mutate([{ title, status: 'todo', percent: 0, current: '', next: '', approach: '', note: '' }]),
3033
- }),
3034
- h(
3035
- 'footer',
3036
- { className: 'pb-footer' },
3037
- h('span', null, `${t('editHint')}`),
3038
- h('span', { className: 'pb-sep' }, '·'),
3039
- h('span', null, `${t('footerHint')}`),
3040
- h('span', { className: 'pb-sep' }, '·'),
3041
- h('span', null, `${t('lastUpdate')} ${updated}`),
3042
- h('span', null, `${t('revision')} ${snapshot?.revision ?? 0}`),
3043
- h('span', null, snapshot?.persistent ? t('saved') : t('memoryOnly')),
3044
- ),
3045
- ),
3046
- ),
3047
- )
3048
- }
3049
-
3050
2634
  return {
3051
2635
  inject: ['slots', 'locale', 'layout', 'sidebarRight', 'sidebarRightTabs', 'sessions'],
3052
2636
  apply(ctx) {
@@ -3164,18 +2748,75 @@ window.__ModuleLoader__.load({
3164
2748
  },
3165
2749
  }
3166
2750
 
3167
- const togglePanel = () => {
3168
- const active = ctx.sidebarRight.active()
3169
- if (ctx.sidebarRight.isExpanded() && active?.kind === RIGHT_TAB_KIND) {
3170
- ctx.sidebarRight.toggleExpanded()
3171
- return
2751
+ /*
2752
+ * 板可能住在两个面:宿主右侧边栏(sidebar.right.pane.tab)和
2753
+ * better-sidebar 的底部工作台(W2 页签)。右栏被接管后两边状态互不可见,
2754
+ * 所以判可见性时两处都问一遍;问不出来就当作「没展开」,入口只会打开。
2755
+ */
2756
+ const betterSidebarRef = { service: null }
2757
+
2758
+ const activeBetterSidebarTabId = () => {
2759
+ const service = betterSidebarRef.service
2760
+ if (!service || typeof service.getSnapshot !== 'function') return ''
2761
+ let state = null
2762
+ try {
2763
+ const snapshot = service.getSnapshot()
2764
+ state = snapshot && snapshot.state ? snapshot.state : null
2765
+ } catch (_error) {
2766
+ return ''
3172
2767
  }
3173
- ctx.sidebarRight.openTab(RIGHT_TAB_KIND)
2768
+ if (!state || state.bottomOpen !== true) return ''
2769
+ const walk = (node) => {
2770
+ if (!node || typeof node !== 'object') return ''
2771
+ if (node.kind === 'leaf') return typeof node.active === 'string' ? node.active : ''
2772
+ return walk(node.a) || walk(node.b)
2773
+ }
2774
+ return walk(state.bottomSplits)
3174
2775
  }
3175
- const openFullPanel = () => ctx.layout.selectPanel(PANEL_ID)
3176
- const toggleFullscreen = () => {
3177
- const target = ctx.sidebarRight.focusedTarget() ?? ctx.sidebarRight.commandTarget()
3178
- if (target) ctx.sidebarRight.toggleFullscreen(target)
2776
+
2777
+ /*
2778
+ * 快捷入口的第二问:板此刻是不是已经在眼前。命中就收起并返回 true,
2779
+ * 让入口表现得像开关,而不是「点了没反应」(0.5.10 的现场)。
2780
+ *
2781
+ * 「收起」按用户点页签上的 × 来算,而不是只把整栏折叠:只折叠会把本板
2782
+ * 留在活动页签里,下次展开右栏又看见它,等于没关(0.5.11 的现场)。
2783
+ * 所以先模拟点掉 ×(close 页签),再把整栏收起来;两步各自兜住软依赖。
2784
+ */
2785
+ const hideBoardIfShown = () => {
2786
+ const service = betterSidebarRef.service
2787
+ try {
2788
+ if (service && activeBetterSidebarTabId() === BS_TAB_ID && typeof service.closeTab === 'function') {
2789
+ service.closeTab(BS_TAB_ID)
2790
+ return true
2791
+ }
2792
+ } catch (_error) {
2793
+ // 软依赖:better-sidebar 的半面坏了也不该堵住宿主右栏那一路。
2794
+ }
2795
+ let active
2796
+ try {
2797
+ active = ctx.sidebarRight.active()
2798
+ } catch (_error) {
2799
+ return false
2800
+ }
2801
+ if (active?.kind !== RIGHT_TAB_KIND) return false
2802
+ // 1) 模拟页签上的 ×:临时关掉本板。页签类型仍注册着,再点入口就重新打开。
2803
+ try {
2804
+ if (typeof ctx.sidebarRight.close === 'function') ctx.sidebarRight.close(RIGHT_TAB_KIND)
2805
+ } catch (_error) {
2806
+ // 关不掉也不能挡住收起:折叠那一步照做。
2807
+ }
2808
+ // 2) 收起右侧边栏;若关页签后宿主已经自动折叠,就不再翻回展开。
2809
+ try {
2810
+ if (ctx.sidebarRight.isExpanded()) ctx.sidebarRight.toggleExpanded()
2811
+ } catch (_error) {
2812
+ // 收起失败只是一次点击没达成,不把异常抛进 React 事件里。
2813
+ }
2814
+ return true
2815
+ }
2816
+
2817
+ const togglePanel = () => {
2818
+ if (hideBoardIfShown()) return
2819
+ ctx.sidebarRight.openTab(RIGHT_TAB_KIND)
3179
2820
  }
3180
2821
 
3181
2822
  safeEffect(
@@ -3186,6 +2827,20 @@ window.__ModuleLoader__.load({
3186
2827
  kind: RIGHT_TAB_KIND,
3187
2828
  priority: 'extension',
3188
2829
  title: () => t('nav'),
2830
+ /*
2831
+ * 引导页条目 = 独立入口。没有它,类型虽然注册成功,却只存在于
2832
+ * 「已打开的 tab」里:侧栏被 better-sidebar 接管时(它把宿主
2833
+ * guide() 的条目搬进自己的开始页),用户没有任何地方能点开本板,
2834
+ * 只能先点头部按钮,入口不可发现。
2835
+ */
2836
+ guide: [
2837
+ {
2838
+ id: RIGHT_TAB_ID,
2839
+ order: 20,
2840
+ title: () => t('nav'),
2841
+ description: () => t('bsDesc'),
2842
+ },
2843
+ ],
3189
2844
  }),
3190
2845
  )
3191
2846
 
@@ -3199,9 +2854,6 @@ window.__ModuleLoader__.load({
3199
2854
  key: RIGHT_TAB_ID,
3200
2855
  locale: NS,
3201
2856
  inject: () => ({
3202
- collapse: () => ctx.sidebarRight.toggleExpanded(),
3203
- toggleFullscreen,
3204
- openFullPanel,
3205
2857
  wakeAgent,
3206
2858
  usage: usageApi,
3207
2859
  }),
@@ -3211,22 +2863,6 @@ window.__ModuleLoader__.load({
3211
2863
  ),
3212
2864
  )
3213
2865
 
3214
- safeEffect(
3215
- 'full panel',
3216
- () =>
3217
- ctx.slots.inject('main', () =>
3218
- ctx.slots.register(
3219
- {
3220
- name: 'main',
3221
- key: PANEL_ID,
3222
- locale: NS,
3223
- inject: () => ({ wakeAgent, usage: usageApi }),
3224
- },
3225
- ProgressPanel,
3226
- ),
3227
- ),
3228
- )
3229
-
3230
2866
  safeEffect(
3231
2867
  'header button',
3232
2868
  () =>
@@ -3239,7 +2875,9 @@ window.__ModuleLoader__.load({
3239
2875
  // 裁切方向未实测,靠前是安全侧——最坏也只是排在别人前面,不会先被挤掉。
3240
2876
  order: 5,
3241
2877
  locale: NS,
3242
- inject: () => ({ openPanel: togglePanel }),
2878
+ // 头部入口只把右栏页签切到本板:主区那个「完整面板」是全屏大页、
2879
+ // 自身没有收拢入口,全屏/收起一律交给右侧边栏自己的 chrome。
2880
+ inject: () => ({ openPanel, togglePanel }),
3243
2881
  },
3244
2882
  ProgressHeaderButton,
3245
2883
  ),
@@ -3277,6 +2915,7 @@ window.__ModuleLoader__.load({
3277
2915
  ctx.inject(['betterSidebar'], (bs) => {
3278
2916
  const service = bs.betterSidebar
3279
2917
  if (!service || typeof service.registerTab !== 'function') return
2918
+ betterSidebarRef.service = service
3280
2919
  bs.effect(
3281
2920
  () =>
3282
2921
  service.registerTab({
@@ -3286,15 +2925,14 @@ window.__ModuleLoader__.load({
3286
2925
  icon: (size) => h(ProgressNavIcon, { size: size || 16 }),
3287
2926
  order: 120,
3288
2927
  single: true,
3289
- // collapse / toggleFullscreen 故意不传:ProgressSidePanel 里都是 ?. 调用,
3290
- // 传了反而会在 better-sidebar 里出现点了没反应的全屏/收起按钮。
2928
+ // 板子自身不再画全屏/收起/完整面板按钮(0.5.10 起一律交给右栏 chrome),
2929
+ // 所以这里也没有任何 chrome 回调要传。
3291
2930
  component: (tabProps) =>
3292
2931
  h(ProgressSidePanel, {
3293
2932
  sessionId: tabProps && tabProps.scope ? tabProps.scope.sessionId : undefined,
3294
2933
  t,
3295
2934
  usage: usageApi,
3296
2935
  wakeAgent,
3297
- openFullPanel,
3298
2936
  }),
3299
2937
  }),
3300
2938
  'progress-union: better-sidebar tab',
package/dsh.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "dsh-external/dsh-progress-union",
3
- "version": "0.5.7",
3
+ "version": "0.5.12",
4
4
  "main": "./index.js",
5
5
  "description": "进度结合原型:board 槽位真相源(用户可编辑、diff+ack 增量同步、staleness nudge)× 鲸程时间引擎(step 计数、ETA 三档 board>todo>local>prior、悬浮迷你条),并向压缩插件暴露只读三层进度锚点 progressAnchor(board 语义锚 + time 时间锚 + userEdits 未确认改动,service 与 HTTP 双平面)。",
6
6
  "engines": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-progress-union",
3
- "version": "0.5.7",
3
+ "version": "0.5.12",
4
4
  "type": "module",
5
5
  "description": "进度结合原型:dsh-progress-board 槽位真相源 × 鲸程 widget 时间/ETA 引擎,另向压缩插件暴露只读三层进度锚点(service + HTTP 双平面)。基于 l3j3y3/dsh-progress-board (MIT) 与 uuhihj/task-progress-bar dsh-progress-widget (MIT)。",
6
6
  "license": "MIT",
@@ -0,0 +1,124 @@
1
+ /**
2
+ * 物化守卫:client.js 必须「加载即可执行」。
3
+ *
4
+ * 宿主浏览器半是 factory-form CJS:materialization(factory(require))阶段任何顶层
5
+ * 抛错都会让整块客户区消失——头部图标、输入框迷你条、右栏页签、better-sidebar 页签
6
+ * 全部不出现,而宿主半(index.js)照常工作,现场只剩「入口没了」。
7
+ *
8
+ * 真实事故(0.5.8):第 16 行 `const PROGRESS_EVENT = 'progress-union:changed'` 漏分号,
9
+ * 紧随其后的 star IIFE 以 `(function () {` 开头,被 ASI 拼成对字符串的调用:
10
+ * TypeError: "progress-union:changed" is not a function
11
+ * 本测试用同一套最小 stub 在 vm 里真的物化一次,锁死这条路径。
12
+ */
13
+ import assert from 'node:assert/strict'
14
+ import fs from 'node:fs'
15
+ import test from 'node:test'
16
+ import vm from 'node:vm'
17
+ import { fileURLToPath } from 'node:url'
18
+
19
+ const clientFile = fileURLToPath(new URL('../client.js', import.meta.url))
20
+
21
+ function noop() {}
22
+
23
+ function materialize() {
24
+ const definitions = []
25
+ const storage = { getItem: () => null, setItem: noop, removeItem: noop }
26
+ const React = {
27
+ createElement: (...args) => ({ __el: args }),
28
+ Fragment: 'fragment',
29
+ useState: (value) => [value, noop],
30
+ useEffect: noop,
31
+ useMemo: (factory) => factory(),
32
+ useCallback: (factory) => factory,
33
+ useRef: (value) => ({ current: value }),
34
+ Component: class { constructor(props) { this.props = props; this.state = {} } setState() {} },
35
+ memo: (component) => component,
36
+ forwardRef: (component) => component,
37
+ createContext: () => ({ Provider: 'provider', Consumer: 'consumer' }),
38
+ }
39
+ const window = {
40
+ __ModuleLoader__: { load: (definition) => definitions.push(definition) },
41
+ localStorage: storage,
42
+ sessionStorage: storage,
43
+ addEventListener: noop,
44
+ removeEventListener: noop,
45
+ matchMedia: () => ({ matches: false, addEventListener: noop, removeEventListener: noop }),
46
+ location: { href: 'http://127.0.0.1/' },
47
+ navigator: { language: 'zh-CN' },
48
+ }
49
+ const document = {
50
+ createElement: () => ({ style: {}, setAttribute: noop, appendChild: noop, classList: { add: noop, remove: noop } }),
51
+ createTextNode: () => ({}),
52
+ head: { appendChild: noop, removeChild: noop },
53
+ body: { appendChild: noop, removeChild: noop },
54
+ documentElement: { dataset: {}, style: {} },
55
+ addEventListener: noop,
56
+ removeEventListener: noop,
57
+ querySelector: () => null,
58
+ querySelectorAll: () => [],
59
+ getElementById: () => null,
60
+ }
61
+ const sandbox = {
62
+ window,
63
+ document,
64
+ localStorage: storage,
65
+ sessionStorage: storage,
66
+ navigator: { language: 'zh-CN' },
67
+ fetch: () => Promise.resolve({ ok: true, json: () => Promise.resolve({}) }),
68
+ console,
69
+ setTimeout,
70
+ clearTimeout,
71
+ setInterval,
72
+ clearInterval,
73
+ queueMicrotask,
74
+ URL,
75
+ URLSearchParams,
76
+ TextEncoder,
77
+ TextDecoder,
78
+ CustomEvent: class { constructor(type, init) { this.type = type; this.detail = init && init.detail } },
79
+ Event: class { constructor(type) { this.type = type } },
80
+ crypto: { randomUUID: () => 'stub-uuid' },
81
+ }
82
+ sandbox.globalThis = sandbox
83
+ sandbox.self = sandbox
84
+ const context = vm.createContext(sandbox)
85
+ vm.runInContext(fs.readFileSync(clientFile, 'utf8'), context, { filename: 'client.js' })
86
+ return definitions
87
+ }
88
+
89
+ function requireStub(specifier) {
90
+ if (specifier === 'react') {
91
+ return {
92
+ createElement: (...args) => ({ __el: args }),
93
+ Fragment: 'fragment',
94
+ useState: (value) => [value, noop],
95
+ useEffect: noop,
96
+ useMemo: (factory) => factory(),
97
+ useCallback: (factory) => factory,
98
+ useRef: (value) => ({ current: value }),
99
+ Component: class {},
100
+ memo: (component) => component,
101
+ forwardRef: (component) => component,
102
+ createContext: () => ({ Provider: 'provider' }),
103
+ }
104
+ }
105
+ if (specifier === 'react-dom') return { render: noop, createRoot: () => ({ render: noop, unmount: noop }) }
106
+ return { jsx: () => ({}), jsxs: () => ({}), Fragment: 'fragment' }
107
+ }
108
+
109
+ test('物化守卫:client.js 脚本执行后注册了唯一 factory', () => {
110
+ const definitions = materialize()
111
+ assert.equal(definitions.length, 1)
112
+ assert.equal(definitions[0].id, 'dsh-progress-union')
113
+ assert.equal(typeof definitions[0].factory, 'function')
114
+ })
115
+
116
+ test('物化守卫:factory(require) 不抛错,导出 apply 与 inject', () => {
117
+ const definitions = materialize()
118
+ const exported = definitions[0].factory(requireStub)
119
+ assert.equal(typeof exported, 'object')
120
+ assert.equal(typeof exported.apply, 'function')
121
+ assert.ok(Array.isArray(exported.inject))
122
+ assert.ok(exported.inject.includes('slots'))
123
+ assert.ok(exported.inject.includes('locale'))
124
+ })
@@ -78,7 +78,7 @@ test('W1: 头部入口注册仍在,且带渲染兜底与分面隔离', () => {
78
78
  // 分面隔离:任一入口注册失败不得中止 apply(否则图标/迷你条/右栏页签一起消失)
79
79
  assert.match(src, /const safeEffect = \(label, register\) =>/, '必须有分面隔离助手')
80
80
  const safeCalls = src.match(/^\s+safeEffect\($/gm) || []
81
- assert.equal(safeCalls.length, 7, '七个入口面都必须经 safeEffect 注册')
81
+ assert.equal(safeCalls.length, 6, '六个入口面(设置×2 / 右栏类型 / 右栏面板 / 头部 / 迷你条)都必须经 safeEffect 注册')
82
82
  const bare = src.match(/ctx\.effect\(\s*\n\s*\(\) =>\s*\n\s*ctx\.(slots|sidebarRightTabs)/g) || []
83
83
  assert.equal(bare.length, 0, '不得残留裸 ctx.effect 入口注册')
84
84
  })
@@ -150,3 +150,23 @@ test('宿主 snapshot/status 两路由的客户端消费形状', async () => {
150
150
  assert.equal(status.task.current, 0)
151
151
  assert.ok(Array.isArray(status.tasks))
152
152
  })
153
+
154
+ test('W3: 板只住在右侧边栏——不再注册主区完整面板', () => {
155
+ // 事故:主区面板没有收拢入口,点进去就回不到会话(进去出不来)。
156
+ const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
157
+ assert.match(src, /const openPanel = \(\) => ctx\.sidebarRight\.openTab\(RIGHT_TAB_KIND\)/, '头部/迷你条入口必须打开右栏页签')
158
+ assert.match(src, /inject: \(\) => \(\{ openPanel, togglePanel \}\)/, '头部入口注入的必须是右栏开关(可见则收起,不可见则打开)')
159
+ assert.doesNotMatch(src, /ctx\.slots\.inject\('main'/, '不得再注册主区完整面板')
160
+ assert.doesNotMatch(src, /layout\.selectPanel/, '不得再切主区面板')
161
+ assert.doesNotMatch(src, /function ProgressPanel\(/, '完整面板组件应已移除')
162
+ })
163
+
164
+ test('W4: 侧栏顶部不再画自带的 全面展开/收起/完整面板 按钮(交给右栏 chrome)', () => {
165
+ // 事故:三个按钮都在,但 toggleFullscreen / collapse 在右栏页签里根本没注入(better-sidebar 里更没处传),
166
+ // 点了没反应才是常态。右栏自身的 chrome 已经有全屏与关闭,不再重复造。
167
+ const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
168
+ assert.doesNotMatch(src, /props\.toggleFullscreen/, '不得再渲染自带的全屏按钮')
169
+ assert.doesNotMatch(src, /props\.collapse/, '不得再渲染自带的收起按钮')
170
+ assert.doesNotMatch(src, /t\('sideFull'\)|t\('sideHalf'\)|t\('sideCollapse'\)/, '三个死按钮的文案不得残留')
171
+ assert.doesNotMatch(src, /toggleFullscreen/, '注入面不得再传全屏切换')
172
+ })
@@ -0,0 +1,216 @@
1
+ /**
2
+ * 入口开关守卫(0.5.12):快捷入口在板已经展开时必须能把它连同右栏一起收起来。
3
+ *
4
+ * 现场两轮:0.5.10 点头部图标「没反应」(只 openTab);0.5.11 改成只折叠整栏,
5
+ * 于是用户再展开右栏发现板还在——「收起」并没有真的关掉板。契约:
6
+ * - 右栏正停在本板页签 → close(KIND) 模拟点页签上的 ×,再 toggleExpanded()
7
+ * 收起整栏;已自动折叠就不再翻回展开;不再 openTab;
8
+ * - 右栏展开但停在别的页签 → openTab()(把本板切到前台),不动展开态,不关别人;
9
+ * - better-sidebar 工作台停在本板 → closeTab(BS_TAB_ID)(软面,独立);
10
+ * - 板没在眼前 → openTab()。
11
+ * 判据全部是「问不出来就当没展开」,软面抛错不拖累宿主右栏那一路。
12
+ */
13
+ import assert from 'node:assert/strict'
14
+ import fs from 'node:fs'
15
+ import test from 'node:test'
16
+ import vm from 'node:vm'
17
+ import { fileURLToPath } from 'node:url'
18
+
19
+ const clientFile = fileURLToPath(new URL('../client.js', import.meta.url))
20
+ const KIND = 'progress-union'
21
+ const BS_ID = 'dsh-progress-union:board'
22
+
23
+ function noop() {}
24
+
25
+ function requireStub(specifier) {
26
+ if (specifier === 'react') {
27
+ return {
28
+ createElement: (...args) => ({ __el: args }),
29
+ Fragment: 'fragment',
30
+ useState: (value) => [value, noop],
31
+ useEffect: noop,
32
+ useMemo: (factory) => factory(),
33
+ useCallback: (factory) => factory,
34
+ useRef: (value) => ({ current: value }),
35
+ Component: class {},
36
+ memo: (component) => component,
37
+ forwardRef: (component) => component,
38
+ createContext: () => ({ Provider: 'provider' }),
39
+ }
40
+ }
41
+ if (specifier === 'react-dom') return { render: noop, createRoot: () => ({ render: noop, unmount: noop }) }
42
+ return { jsx: () => ({}), jsxs: () => ({}), Fragment: 'fragment' }
43
+ }
44
+
45
+ function materialize() {
46
+ const definitions = []
47
+ const storage = { getItem: () => null, setItem: noop, removeItem: noop }
48
+ const window = {
49
+ __ModuleLoader__: { load: (definition) => definitions.push(definition) },
50
+ localStorage: storage,
51
+ sessionStorage: storage,
52
+ addEventListener: noop,
53
+ removeEventListener: noop,
54
+ matchMedia: () => ({ matches: false, addEventListener: noop, removeEventListener: noop }),
55
+ location: { href: 'http://127.0.0.1/' },
56
+ navigator: { language: 'zh-CN' },
57
+ }
58
+ const document = {
59
+ createElement: () => ({ style: {}, setAttribute: noop, appendChild: noop, classList: { add: noop, remove: noop } }),
60
+ createTextNode: () => ({}),
61
+ head: { appendChild: noop, removeChild: noop },
62
+ body: { appendChild: noop, removeChild: noop },
63
+ documentElement: { dataset: {}, style: {} },
64
+ addEventListener: noop,
65
+ removeEventListener: noop,
66
+ querySelector: () => null,
67
+ querySelectorAll: () => [],
68
+ getElementById: () => null,
69
+ }
70
+ const sandbox = {
71
+ window,
72
+ document,
73
+ localStorage: storage,
74
+ sessionStorage: storage,
75
+ navigator: { language: 'zh-CN' },
76
+ fetch: () => Promise.resolve({ ok: true, json: () => Promise.resolve({}) }),
77
+ console,
78
+ setTimeout,
79
+ clearTimeout,
80
+ setInterval,
81
+ clearInterval,
82
+ queueMicrotask,
83
+ URL,
84
+ URLSearchParams,
85
+ TextEncoder,
86
+ TextDecoder,
87
+ CustomEvent: class { constructor(type, init) { this.type = type; this.detail = init && init.detail } },
88
+ Event: class { constructor(type) { this.type = type } },
89
+ crypto: { randomUUID: () => 'stub-uuid' },
90
+ }
91
+ sandbox.globalThis = sandbox
92
+ sandbox.self = sandbox
93
+ const context = vm.createContext(sandbox)
94
+ vm.runInContext(fs.readFileSync(clientFile, 'utf8'), context, { filename: 'client.js' })
95
+ return definitions
96
+ }
97
+
98
+ function boot(options = {}) {
99
+ const calls = { openTab: [], toggleExpanded: 0, closeTab: [], close: [], headerEntries: [] }
100
+ const betterSidebar = options.betterSidebar
101
+ const ctx = {
102
+ effect: (fn) => {
103
+ const disposer = fn()
104
+ return typeof disposer === 'function' ? disposer : noop
105
+ },
106
+ get: () => undefined,
107
+ locale: { register: () => noop, bind: () => (key) => key },
108
+ slots: {
109
+ inject: (name, cb) => cb(),
110
+ register: (opts) => {
111
+ if (opts.name === 'conversation.session.header.utilities') calls.headerEntries.push(opts)
112
+ return noop
113
+ },
114
+ },
115
+ sidebarRight: {
116
+ openTab: (kind) => calls.openTab.push(kind),
117
+ focus: noop,
118
+ active: () => options.active,
119
+ isExpanded: () => options.expanded === true,
120
+ toggleExpanded: () => { calls.toggleExpanded += 1 },
121
+ close: (kind) => calls.close.push(kind),
122
+ },
123
+ sidebarRightTabs: { register: () => noop },
124
+ sessions: { binding: () => undefined },
125
+ inject: (deps, cb) => {
126
+ if (Array.isArray(deps) && deps.includes('betterSidebar') && betterSidebar) {
127
+ cb({ betterSidebar, effect: (fn) => fn() })
128
+ }
129
+ return noop
130
+ },
131
+ }
132
+ const exported = materialize()[0].factory(requireStub)
133
+ exported.apply(ctx)
134
+ const header = calls.headerEntries[0]
135
+ assert.ok(header, '头部入口必须注册')
136
+ return { calls, header }
137
+ }
138
+
139
+ test('头部入口注入开关本身,而不是只会打开的 openTab', () => {
140
+ const { header } = boot({})
141
+ const injected = header.inject()
142
+ assert.equal(typeof injected.togglePanel, 'function', '头部入口必须拿到 togglePanel')
143
+ assert.equal(typeof injected.openPanel, 'function', '保留 openPanel 作为兜底')
144
+ })
145
+
146
+ test('板已在右栏展开:先模拟点掉页签上的 ×,再收起整栏,不再重复 openTab', () => {
147
+ const { calls, header } = boot({ expanded: true, active: { id: 'dsh-progress-union', kind: KIND } })
148
+ header.inject().togglePanel()
149
+ assert.deepEqual(calls.close, [KIND], '必须像点 × 一样把本板页签关掉(否则下次展开又看见它)')
150
+ assert.equal(calls.toggleExpanded, 1, '收起整栏')
151
+ assert.deepEqual(calls.openTab, [], '可见时不得再开一次')
152
+ })
153
+
154
+ test('板是活动页签但右栏已折叠:入口只关页签,不反手展开整栏', () => {
155
+ const { calls, header } = boot({ expanded: false, active: { id: 'dsh-progress-union', kind: KIND } })
156
+ header.inject().togglePanel()
157
+ assert.deepEqual(calls.close, [KIND], '板还在页签里就要关掉')
158
+ assert.equal(calls.toggleExpanded, 0, '已折叠时不得再 toggle(会翻回展开)')
159
+ assert.deepEqual(calls.openTab, [], '不得再开一次')
160
+ })
161
+
162
+ test('右栏停在别的页签:入口把本板切到前台,不动展开态', () => {
163
+ const { calls, header } = boot({ expanded: true, active: { id: 'files', kind: 'files' } })
164
+ header.inject().togglePanel()
165
+ assert.deepEqual(calls.openTab, [KIND])
166
+ assert.deepEqual(calls.close, [], '别的页签展开时不得关掉本板页签')
167
+ assert.equal(calls.toggleExpanded, 0, '别的页签展开时不得整栏收起')
168
+ })
169
+
170
+ test('右栏收起时:入口打开本板', () => {
171
+ const { calls, header } = boot({ expanded: false, active: undefined })
172
+ header.inject().togglePanel()
173
+ assert.deepEqual(calls.openTab, [KIND])
174
+ })
175
+
176
+ test('better-sidebar 工作台停在本板:入口收起那一面(软依赖,不误伤右栏)', () => {
177
+ const betterSidebar = {
178
+ registerTab: () => noop,
179
+ getSnapshot: () => ({
180
+ state: { bottomOpen: true, bottomSplits: { kind: 'leaf', tabs: [{ id: BS_ID }], active: BS_ID } },
181
+ }),
182
+ closeTab: (id) => { closeCalls.push(id) },
183
+ }
184
+ const closeCalls = []
185
+ const { calls, header } = boot({ expanded: true, active: { id: 'files', kind: 'files' }, betterSidebar })
186
+ header.inject().togglePanel()
187
+ assert.deepEqual(closeCalls, [BS_ID], '工作台上的本板必须被关掉')
188
+ assert.deepEqual(calls.close, [], '不得顺手关掉宿主右栏的页签')
189
+ assert.equal(calls.toggleExpanded, 0, '不得顺手收起宿主右栏')
190
+ assert.deepEqual(calls.openTab, [], '收起后不得再开一次')
191
+ })
192
+
193
+ test('better-sidebar 工作台收起/停在别的页签:入口回到宿主右栏那一路', () => {
194
+ for (const state of [
195
+ { bottomOpen: false, bottomSplits: { kind: 'leaf', tabs: [{ id: BS_ID }], active: BS_ID } },
196
+ { bottomOpen: true, bottomSplits: { kind: 'leaf', tabs: [{ id: 'editor:a.js' }], active: 'editor:a.js' } },
197
+ ]) {
198
+ const closeCalls = []
199
+ const betterSidebar = { registerTab: () => noop, getSnapshot: () => ({ state }), closeTab: (id) => closeCalls.push(id) }
200
+ const { calls, header } = boot({ expanded: false, betterSidebar })
201
+ header.inject().togglePanel()
202
+ assert.deepEqual(closeCalls, [], '不该关别的东西')
203
+ assert.deepEqual(calls.openTab, [KIND], '仍要能打开宿主右栏的本板')
204
+ }
205
+ })
206
+
207
+ test('better-sidebar 半面抛错:入口不哑,回落到宿主右栏', () => {
208
+ const betterSidebar = {
209
+ registerTab: () => noop,
210
+ getSnapshot: () => { throw new Error('boom') },
211
+ closeTab: () => { throw new Error('boom') },
212
+ }
213
+ const { calls, header } = boot({ expanded: false, betterSidebar })
214
+ header.inject().togglePanel()
215
+ assert.deepEqual(calls.openTab, [KIND])
216
+ })