dsh-split-workspace 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +30 -2
  2. package/lib/client.js +914 -32
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -71,13 +71,20 @@ dsh --profile web
71
71
 
72
72
  ### 开始分屏
73
73
 
74
- - 点击侧边栏底部的分屏图标:用当前会话和列表中的下一个会话开始分屏。
74
+ - 点击侧边栏底部的分屏图标会弹出分屏菜单:**添加分屏 / 退出分屏 / 最小化分屏 / 重置分屏**。
75
+ - **添加分屏** 会打开多选弹框;勾选两个或更多会话后点确定即可分屏。已经处于分屏时弹框会默认勾选当前窗格的会话,可以取消勾选来移除窗格,也可以继续添加新会话,最终按勾选结果重新分屏。
76
+ - 也可以直接在会话列表里操作:右键会话(或点行尾的「⋯」)→ **加入分屏** / **退出分屏**。还没进入分屏时,第一次「加入分屏」会先放进**待分屏**,再加一个会话才会真正进入分屏;已经在分屏时则直接加入当前分屏。反向「退出分屏」会把该会话移出分屏,只剩一个会话时自动退出分屏。
75
77
  - 或者把侧边栏里的会话拖到对话区:放下的会话成为第二个窗格。
76
78
  - 分屏后,把另一个会话拖到某个窗格即可替换;也可以用窗格标题栏的分屏按钮为新窗格选择会话。
77
79
  - 拖动侧边栏会话经过窗格边缘时,窗格会预览放下后的布局,并用虚线占位标出即将加入的会话;松开即应用该布局。
80
+ - **重置分屏** 会清空本插件在 localStorage / sessionStorage 里的全部键、已保存布局、崩溃保护、最小化标记和窗格临时缓存;当分屏因为缓存或异常状态怎么都起不来时,点它即可恢复到干净状态。
78
81
 
79
82
  ## 功能
80
83
 
84
+ - **侧边栏分屏菜单**:底部分屏按钮弹出「添加分屏 / 退出分屏 / 最小化分屏 / 重置分屏」,其中退出和最小化与顶部工具栏完全一致。
85
+ - **多选添加分屏**:弹框可搜索、可多选;已分屏时默认勾选当前窗格,可取消或追加,按最终勾选结果分屏。
86
+ - **会话右键集成**:原生右键菜单新增「加入分屏 / 退出分屏」,未分屏时先进入待分屏,满两个才分屏;退出到只剩一个自动退出分屏。
87
+ - **一键重置**:清空插件相关的 localStorage / sessionStorage、布局、崩溃保护和临时缓存,避免异常状态卡住分屏。
81
88
  - **不限数量的原生窗格**:没有四窗格上限,窗口放得下多少会话就能开多少。
82
89
  - **自动布局**:2 个窗格左右分栏,3 个呈 L 形,4 个田字 2×2,5 个以上按行优先的均衡网格排列。
83
90
  - **拖拽自由排布**:拖动窗格标题栏到另一个窗格的左/右/上/下,可手动堆叠或分栏。
@@ -111,11 +118,15 @@ dsh --profile web
111
118
 
112
119
  - `window.__dshSplitWorkspace.health()`:版本、宿主、窗格、几何、持久化树、崩溃保护。
113
120
  - `window.__dshSplitWorkspace.split(sessionId)`:把会话加为窗格。
121
+ - `window.__dshSplitWorkspace.addToSplit(sessionId)` / `removeFromSplit(sessionId)`:加入 / 退出分屏(未分屏时先进入待分屏)。
122
+ - `window.__dshSplitWorkspace.pending()`:当前待分屏的会话 id。
123
+ - `window.__dshSplitWorkspace.openAddSplitDialog()`:打开多选添加分屏弹框。
114
124
  - `window.__dshSplitWorkspace.arrange("auto")`:重新适配自动布局(旧模式名会被接受并忽略)。
115
125
  - `window.__dshSplitWorkspace.focusChat()`、`closeFocused()`。
116
126
  - `window.__dshSplitWorkspace.reflow()`:拖动预览状态(排查占位/闭合行为用)。
117
127
  - `window.__dshSplitWorkspace.setEnabled(false)`:总开关。
118
128
  - `window.__dshSplitWorkspace.reset()`:清除已保存布局。
129
+ - `window.__dshSplitWorkspace.resetAll()`:连同 localStorage / sessionStorage 与临时缓存一起彻底重置(等同菜单里的「重置分屏」)。
119
130
 
120
131
  ## 快捷键
121
132
 
@@ -235,13 +246,20 @@ dsh --profile web
235
246
 
236
247
  **Start splitting**
237
248
 
238
- - Click the split icon in the sidebar footer (beside Settings) — it starts a split with the current conversation and the next listed one.
249
+ - Click the split icon in the sidebar footer (beside Settings) to open the split menu: **Add split / Exit split / Minimize / Reset split**.
250
+ - **Add split** opens a multi-select dialog. Check two or more conversations and confirm. While already split, the dialog pre-selects the current panes: uncheck one to remove its pane, check more to extend, and the final selection becomes the split.
251
+ - You can also use the session list: right-click a conversation (or its row `⋯` button) and pick **Add to split** / **Leave split**. Outside split mode the first pick is parked as a *pending split*; adding a second conversation starts the split. Inside split mode the conversation joins the current split immediately. Leaving removes it, and dropping to one conversation exits split mode.
239
252
  - Or drag a conversation from the sidebar onto the conversation column: the dropped conversation becomes the second pane.
240
253
  - Once split, drag another conversation onto a pane to replace it, or use a pane header's split buttons to choose the session for a new pane.
241
254
  - While a sidebar conversation is dragged over a pane edge, the panes lay themselves out as they will after the drop and a dashed placeholder names the incoming conversation — release to commit exactly that layout.
255
+ - **Reset split** clears every plugin-owned localStorage / sessionStorage key, the saved layout, the crash guard, the minimized flag and pane caches, so a split stuck by stale state can always start again.
242
256
 
243
257
  ### Features
244
258
 
259
+ - **Sidebar split menu** — the footer button opens Add / Exit / Minimize / Reset; Exit and Minimize are the same actions as the split toolbar.
260
+ - **Multi-select add** — searchable dialog; pre-selects current panes, lets you uncheck or extend, and rebuilds the split from the final selection.
261
+ - **Session-menu integration** — the stock right-click menu gains Add to split / Leave split. Outside split mode the first pick waits in a pending split until a second conversation is added; removing down to one pane exits the split.
262
+ - **One-click reset** — wipes plugin localStorage/sessionStorage, layout, crash guard and temporary caches.
245
263
  - **Unlimited native panes** — no four-pane cap; add as many conversations as
246
264
  the window can show.
247
265
  - **Automatic layout** — 2 panes as columns, 3 as an L, 4 as a 2×2 田字, and
@@ -325,6 +343,13 @@ architecture the upstream plugin uses.
325
343
  - `window.__dshSplitWorkspace.health()` — version, host, panes, geometry,
326
344
  persisted tree, crash guard.
327
345
  - `window.__dshSplitWorkspace.split(sessionId)` — add a session as a pane.
346
+ - `window.__dshSplitWorkspace.addToSplit(sessionId)` /
347
+ `removeFromSplit(sessionId)` — add to / leave the split (the first pick
348
+ outside split mode waits in the pending split).
349
+ - `window.__dshSplitWorkspace.pending()` — conversations waiting for a second
350
+ pick before the split starts.
351
+ - `window.__dshSplitWorkspace.openAddSplitDialog()` — open the multi-select add
352
+ dialog.
328
353
  - `window.__dshSplitWorkspace.arrange("auto")` — re-fit the automatic layout
329
354
  (legacy mode names are accepted and ignored).
330
355
  - `window.__dshSplitWorkspace.focusChat()`, `closeFocused()`.
@@ -332,6 +357,9 @@ architecture the upstream plugin uses.
332
357
  (diagnostics for the hole/collapse behaviour).
333
358
  - `window.__dshSplitWorkspace.setEnabled(false)` — kill switch.
334
359
  - `window.__dshSplitWorkspace.reset()` — clear the saved layout.
360
+ - `window.__dshSplitWorkspace.resetAll()` — also wipe the plugin's
361
+ localStorage / sessionStorage keys and temporary caches (same as the menu's
362
+ Reset split).
335
363
 
336
364
  ### Keyboard
337
365
 
package/lib/client.js CHANGED
@@ -73,7 +73,7 @@ window.__ModuleLoader__.load({
73
73
  // ---------------------------------------------------------------------
74
74
 
75
75
  const PLUGIN_ID = "dsh-split-workspace";
76
- const PLUGIN_VERSION = "0.4.3";
76
+ const PLUGIN_VERSION = "0.5.0";
77
77
  const LOG_PREFIX = "[dsh-split-workspace]";
78
78
  const TREE_KEY = "dsh.split-workspace.tree.v1";
79
79
  const OPEN_KEY = "dsh.split-workspace.open.v2";
@@ -480,7 +480,7 @@ window.__ModuleLoader__.load({
480
480
  host); it only gets one console note and a health() flag.
481
481
  0.2.1-rc.2 signed off by the release verifier on the isolated real
482
482
  0.2.1 desktop host (docs/VERIFICATION-2026-10-19.md). */
483
- const TESTED_RELEASES = ["0.2.0-rc.2", "0.2.1-rc.2"];
483
+ const TESTED_RELEASES = ["0.2.0-rc.2", "0.2.1-rc.2", "0.2.2-rc.3"];
484
484
  /** The conversation column must be at least this big to be usable. */
485
485
  const COLUMN_MIN_WIDTH = 360;
486
486
  const COLUMN_MIN_HEIGHT = 240;
@@ -538,7 +538,7 @@ window.__ModuleLoader__.load({
538
538
  helpOpen: "Split view help",
539
539
  helpClose: "Close",
540
540
  helpShortcuts: "Shortcuts",
541
- helpGestures: "Drag a conversation from the sidebar onto the page to start a split. Drag a pane by its header to move it: its slot closes and a dashed hole previews where it will land. Drag the dividers to resize. ✕ closes a pane.",
541
+ helpGestures: "Use the sidebar-footer split menu (Add split / Exit split / Minimize / Reset split) or drag a conversation from the sidebar onto the page to start a split. Right-click a conversation for Add to split / Leave split. Drag a pane by its header to move it: its slot closes and a dashed hole previews where it will land. Drag the dividers to resize. ✕ closes a pane.",
542
542
  helpDisable: "Disable split view: run window.__dshSplitWorkspace.setEnabled(false), or set localStorage 'dsh.split-workspace.enabled.v1' to \"0\". Reset the layout: window.__dshSplitWorkspace.reset().",
543
543
  helpDiagnostics: "Diagnostics: window.__dshSplitWorkspace.health() — see the README section “Safety, recovery and diagnostics”.",
544
544
  tipTitle: "Split view is on",
@@ -558,6 +558,24 @@ window.__ModuleLoader__.load({
558
558
  dragHint: "Drop into a pane to split",
559
559
  dragHintPane: "Release to place the pane",
560
560
  pickerEmpty: "No other conversations available",
561
+ menuTitle: "Split view menu",
562
+ menuAddSplit: "Add split",
563
+ menuAddToSplit: "Add to split",
564
+ menuMinimizeSplit: "Minimize split",
565
+ menuResetSplit: "Reset split",
566
+ resetDone: "Split view data cleared — layout, cache and temporary state were removed.",
567
+ pendingAdded: "Added to the pending split. Add one more conversation to start splitting.",
568
+ pendingBadge: "{n} pending",
569
+ addSplitTitle: "Add split",
570
+ addSplitHint: "Select the conversations to split. Unchecking a pane removes it; fewer than two conversations exits split view.",
571
+ addSplitSelected: "{n} selected",
572
+ addSplitConfirm: "OK",
573
+ addSplitCancel: "Cancel",
574
+ addSplitEmpty: "No conversations available",
575
+ addSplitInSplit: "In split",
576
+ addSplitPending: "Pending",
577
+ splitExited: "Split view closed",
578
+ splitLeft: "Left split view",
561
579
  };
562
580
  const ZH = {
563
581
  label: "分屏视图",
@@ -612,7 +630,7 @@ window.__ModuleLoader__.load({
612
630
  helpOpen: "分屏帮助",
613
631
  helpClose: "关闭",
614
632
  helpShortcuts: "快捷键",
615
- helpGestures: "从左侧会话列表把对话拖到页面即可开始分屏;拖住面板标题栏可移动面板:原位置收起,虚线空位预览落点。拖动分隔条可调整大小,✕ 关闭面板。",
633
+ helpGestures: "点击侧边栏底部的分屏按钮打开菜单(添加分屏 / 退出分屏 / 最小化分屏 / 重置分屏),或从左侧会话列表把对话拖到页面即可分屏;右键会话可加入 / 退出分屏。拖住面板标题栏可移动面板:原位置收起,虚线空位预览落点。拖动分隔条可调整大小,✕ 关闭面板。",
616
634
  helpDisable: "停用分屏:运行 window.__dshSplitWorkspace.setEnabled(false),或将 localStorage 'dsh.split-workspace.enabled.v1' 设为 \"0\"。重置布局:window.__dshSplitWorkspace.reset()。",
617
635
  helpDiagnostics: "诊断:window.__dshSplitWorkspace.health() — 详见 README“安全性、恢复与诊断”。",
618
636
  tipTitle: "分屏视图已开启",
@@ -632,6 +650,24 @@ window.__ModuleLoader__.load({
632
650
  dragHint: "拖入面板即可分屏",
633
651
  dragHintPane: "松开即可放置面板",
634
652
  pickerEmpty: "没有可用的其他会话",
653
+ menuTitle: "分屏菜单",
654
+ menuAddSplit: "添加分屏",
655
+ menuAddToSplit: "加入分屏",
656
+ menuMinimizeSplit: "最小化分屏",
657
+ menuResetSplit: "重置分屏",
658
+ resetDone: "分屏数据已重置 — 布局、缓存与临时状态已清空。",
659
+ pendingAdded: "已加入待分屏,再添加一个会话即可开始分屏。",
660
+ pendingBadge: "{n} 个待分屏",
661
+ addSplitTitle: "添加分屏",
662
+ addSplitHint: "勾选要分屏的会话;取消勾选会移除对应面板,少于两个会话将退出分屏。",
663
+ addSplitSelected: "已选 {n} 个",
664
+ addSplitConfirm: "确定",
665
+ addSplitCancel: "取消",
666
+ addSplitEmpty: "没有可用的会话",
667
+ addSplitInSplit: "分屏中",
668
+ addSplitPending: "待分屏",
669
+ splitExited: "已退出分屏",
670
+ splitLeft: "已退出分屏",
635
671
  };
636
672
 
637
673
  /** Fallback translator: every locale wrapper unwraps back to this. */
@@ -756,11 +792,130 @@ window.__ModuleLoader__.load({
756
792
  }
757
793
  .dsv-layout-icon svg { display: block; }
758
794
  .dsv-footer-btn {
795
+ position: relative;
759
796
  display: inline-flex; align-items: center; justify-content: center;
760
797
  width: 28px; height: 28px; padding: 0; border: 0; border-radius: 7px;
761
798
  background: transparent; color: var(--dsw-alias-label-secondary); cursor: pointer;
762
799
  }
763
- .dsv-footer-btn:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
800
+ .dsv-footer-btn:hover,
801
+ .dsv-footer-btn[data-open="true"] { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
802
+ .dsv-footer-btn[data-open="true"] { color: var(--dsw-static-deepseek-500); }
803
+ .dsv-footer-badge {
804
+ position: absolute; top: -3px; right: -3px; min-width: 13px; height: 13px; padding: 0 3px;
805
+ display: inline-flex; align-items: center; justify-content: center;
806
+ border-radius: 999px; background: var(--dsw-static-deepseek-500); color: #fff;
807
+ font-size: 9px; line-height: 1; font-weight: 600; pointer-events: none;
808
+ box-shadow: 0 0 0 1.5px var(--dsw-alias-bg-layer-1, var(--dsw-alias-bg-base));
809
+ }
810
+
811
+ /* ---- 0.5.0 launcher: the sidebar footer menu and the multi-select
812
+ "add split" dialog. Both mount through the shell overlay seat, so they
813
+ are never clipped by the sidebar column or the split overlay. ---- */
814
+ .dsv-launcher-menu {
815
+ position: fixed; z-index: 140; width: 200px; padding: 6px;
816
+ border: 1px solid var(--dsw-alias-border-l2); border-radius: 12px;
817
+ background: var(--dsw-alias-bg-layer-1, var(--dsw-alias-bg-base));
818
+ box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
819
+ color: var(--dsw-alias-label-primary);
820
+ font-family: var(--dsw-font-family, system-ui, sans-serif);
821
+ animation: dsv-launcher-in 0.12s ease-out;
822
+ }
823
+ .dsv-launcher-header {
824
+ padding: 4px 8px 6px; font-size: 11px; line-height: 15px;
825
+ color: var(--dsw-alias-label-tertiary);
826
+ white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
827
+ }
828
+ .dsv-launcher-item {
829
+ display: flex; align-items: center; gap: 8px; width: 100%; height: 32px; padding: 0 8px;
830
+ border: 0; border-radius: 8px; background: transparent; color: inherit;
831
+ font: inherit; font-size: 13px; text-align: left; cursor: pointer;
832
+ }
833
+ .dsv-launcher-item:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
834
+ .dsv-launcher-item:disabled { opacity: 0.42; cursor: default; }
835
+ .dsv-launcher-item.danger { color: #e5484d; }
836
+ .dsv-launcher-item.danger:hover:not(:disabled) { background: color-mix(in srgb, #e5484d 12%, transparent); }
837
+ .dsv-launcher-icon { flex: none; width: 18px; display: grid; place-items: center; font-size: 13px; line-height: 1; opacity: 0.85; }
838
+ .dsv-launcher-separator { height: 1px; margin: 5px 8px; background: var(--dsw-alias-border-l2); }
839
+ @keyframes dsv-launcher-in { from { opacity: 0; transform: translateY(4px); } }
840
+
841
+ .dsv-modal-backdrop {
842
+ position: fixed; inset: 0; z-index: 150;
843
+ display: flex; align-items: center; justify-content: center;
844
+ background: rgba(0, 0, 0, 0.32);
845
+ animation: dsv-fade-in 0.12s ease-out;
846
+ font-family: var(--dsw-font-family, system-ui, sans-serif);
847
+ }
848
+ .dsv-modal {
849
+ width: min(520px, calc(100vw - 32px)); max-height: min(620px, calc(100vh - 64px));
850
+ display: flex; flex-direction: column; overflow: hidden;
851
+ border: 1px solid var(--dsw-alias-border-l2); border-radius: 14px;
852
+ background: var(--dsw-alias-bg-layer-1, var(--dsw-alias-bg-base));
853
+ color: var(--dsw-alias-label-primary);
854
+ box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
855
+ }
856
+ .dsv-modal-head { flex: none; display: flex; align-items: center; gap: 10px; padding: 14px 16px 8px; }
857
+ .dsv-modal-title { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; }
858
+ .dsv-modal-close {
859
+ flex: none; width: 26px; height: 26px; display: grid; place-items: center;
860
+ border: 0; border-radius: 7px; background: transparent;
861
+ color: var(--dsw-alias-label-secondary); font: inherit; font-size: 16px; cursor: pointer;
862
+ }
863
+ .dsv-modal-close:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
864
+ .dsv-modal-hint { flex: none; padding: 0 16px 10px; font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }
865
+ .dsv-modal-search {
866
+ flex: none; margin: 0 16px 10px; height: 30px; padding: 0 10px;
867
+ border-radius: 9px; border: 1px solid var(--dsw-alias-border-l2);
868
+ background: transparent; color: var(--dsw-alias-label-primary);
869
+ font: inherit; font-size: 12px; outline: none;
870
+ }
871
+ .dsv-modal-search:focus { border-color: color-mix(in srgb, var(--dsw-static-deepseek-500) 45%, transparent); }
872
+ .dsv-modal-search::placeholder { color: var(--dsw-alias-label-caption); }
873
+ .dsv-modal-body {
874
+ flex: 1; min-height: 0; overflow-y: auto; padding: 0 10px 10px;
875
+ display: flex; flex-direction: column; gap: 2px;
876
+ }
877
+ .dsv-pick-row {
878
+ display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px;
879
+ border: 0; border-radius: 10px; background: transparent; color: inherit;
880
+ font: inherit; text-align: left; cursor: pointer;
881
+ }
882
+ .dsv-pick-row:hover { background: var(--dsw-alias-interactive-bg-hover); }
883
+ .dsv-pick-check {
884
+ flex: none; box-sizing: border-box;
885
+ width: 16px; height: 16px;
886
+ display: grid; place-items: center;
887
+ border: 1.5px solid var(--dsw-alias-border-l2); border-radius: 4px;
888
+ font-size: 11px; line-height: 1; color: #fff; background: transparent;
889
+ }
890
+ .dsv-pick-row[aria-checked="true"] .dsv-pick-check {
891
+ background: var(--dsw-static-deepseek-500); border-color: transparent;
892
+ }
893
+ .dsv-pick-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
894
+ .dsv-pick-title { font-size: 13px; line-height: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
895
+ .dsv-pick-sub { font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
896
+ .dsv-pick-tag {
897
+ flex: none; padding: 0 6px; border-radius: 999px; font-size: 10px; line-height: 16px;
898
+ color: var(--dsw-static-deepseek-500);
899
+ background: color-mix(in srgb, var(--dsw-static-deepseek-500) 12%, transparent);
900
+ }
901
+ .dsv-pick-empty { padding: 22px 12px; text-align: center; font-size: 12px; color: var(--dsw-alias-label-tertiary); }
902
+ .dsv-modal-foot {
903
+ flex: none; display: flex; align-items: center; gap: 8px;
904
+ padding: 10px 16px 14px; border-top: 1px solid var(--dsw-alias-border-l2);
905
+ }
906
+ .dsv-modal-count { flex: 1; min-width: 0; font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }
907
+ .dsv-modal-btn {
908
+ flex: none; height: 30px; padding: 0 14px; border-radius: 8px;
909
+ border: 1px solid var(--dsw-alias-border-l2); background: transparent;
910
+ color: var(--dsw-alias-label-primary); font: inherit; font-size: 12px; cursor: pointer;
911
+ }
912
+ .dsv-modal-btn:hover { background: var(--dsw-alias-interactive-bg-hover); }
913
+ .dsv-modal-btn.accent { background: var(--dsw-static-deepseek-500); border-color: transparent; color: #fff; }
914
+ .dsv-modal-btn.accent:hover { filter: brightness(1.05); background: var(--dsw-static-deepseek-500); }
915
+ @keyframes dsv-fade-in { from { opacity: 0; } }
916
+ @media (prefers-reduced-motion: reduce) {
917
+ .dsv-launcher-menu, .dsv-modal-backdrop { animation: none; }
918
+ }
764
919
  /* One title per pane: the pane header owns it. The stock header keeps its
765
920
  view tabs and action rows but not its breadcrumb; the slim header's own
766
921
  title span is removed in JSX. */
@@ -2553,6 +2708,93 @@ window.__ModuleLoader__.load({
2553
2708
 
2554
2709
  const treeStore = createTreeStore();
2555
2710
 
2711
+ // ---------------------------------------------------------------------
2712
+ // pending split + launcher state (0.5.0)
2713
+ //
2714
+ // "Add to split" on a session row is only meaningful once a split exists.
2715
+ // While the workspace is inactive the first pick is parked in this store
2716
+ // (the "pending split") and the SECOND pick starts the split; the footer
2717
+ // button shows the pending count so the parked pick is never invisible.
2718
+ // The launcher store drives the footer menu and the multi-select dialog;
2719
+ // both render through the always-mounted shell overlay seat, so the
2720
+ // sidebar's clipping/stacking can never cut them.
2721
+ // ---------------------------------------------------------------------
2722
+
2723
+ const pendingSplitStore = (() => {
2724
+ let ids = [];
2725
+ const listeners = new Set();
2726
+ const emit = () => {
2727
+ for (const listener of [...listeners]) {
2728
+ try { listener(); } catch {}
2729
+ }
2730
+ };
2731
+ return {
2732
+ getSnapshot: () => ids,
2733
+ subscribe(listener) {
2734
+ if (typeof listener !== "function") return () => {};
2735
+ listeners.add(listener);
2736
+ return () => { listeners.delete(listener); };
2737
+ },
2738
+ has: (id) => ids.indexOf(id) !== -1,
2739
+ /** @returns {boolean} true when the id was newly parked. */
2740
+ add(id) {
2741
+ if (!isValidSessionId(id) || ids.indexOf(id) !== -1) return false;
2742
+ ids = ids.concat([id]);
2743
+ emit();
2744
+ return true;
2745
+ },
2746
+ remove(id) {
2747
+ if (ids.indexOf(id) === -1) return false;
2748
+ ids = ids.filter((entry) => entry !== id);
2749
+ emit();
2750
+ return true;
2751
+ },
2752
+ clear() {
2753
+ if (ids.length === 0) return;
2754
+ ids = [];
2755
+ emit();
2756
+ },
2757
+ size: () => ids.length,
2758
+ ids: () => ids.slice(),
2759
+ };
2760
+ })();
2761
+
2762
+ /** Footer-menu / add-dialog request. `mode`: closed | menu | dialog. */
2763
+ let launcherState = { mode: "closed", rect: null, source: null };
2764
+ const launcherListeners = new Set();
2765
+ function setLauncherState(next) {
2766
+ const same = launcherState.mode === next.mode
2767
+ && launcherState.source === next.source
2768
+ && launcherState.rect === next.rect;
2769
+ if (same) return launcherState;
2770
+ launcherState = next;
2771
+ for (const listener of [...launcherListeners]) {
2772
+ try { listener(); } catch {}
2773
+ }
2774
+ return launcherState;
2775
+ }
2776
+ function useLauncherState() {
2777
+ return React.useSyncExternalStore(
2778
+ (listener) => { launcherListeners.add(listener); return () => { launcherListeners.delete(listener); }; },
2779
+ () => launcherState,
2780
+ () => launcherState,
2781
+ );
2782
+ }
2783
+ function closeLauncher() {
2784
+ setLauncherState({ mode: "closed", rect: null, source: null });
2785
+ }
2786
+ function openLauncherMenu(anchorEl) {
2787
+ let rect = null;
2788
+ try {
2789
+ rect = anchorEl !== null && anchorEl !== undefined && typeof anchorEl.getBoundingClientRect === "function"
2790
+ ? anchorEl.getBoundingClientRect() : null;
2791
+ } catch { rect = null; }
2792
+ setLauncherState({ mode: "menu", rect, source: "footer" });
2793
+ }
2794
+ function openAddSplitDialog(source) {
2795
+ setLauncherState({ mode: "dialog", rect: null, source: source === "footer" ? "footer" : "session" });
2796
+ }
2797
+
2556
2798
  let dragPayload = null; // { kind: 'session' | 'pane', id }
2557
2799
 
2558
2800
  // ---------------------------------------------------------------------
@@ -3987,6 +4229,9 @@ window.__ModuleLoader__.load({
3987
4229
  if (active && listeners.size > 0) attach();
3988
4230
  else if (!active) detach();
3989
4231
  },
4232
+ /** Force one bounded re-read (the add-split dialog opens while the
4233
+ workspace may be inactive, when the observer is detached). */
4234
+ refresh: () => { publish(); },
3990
4235
  subscribe: (listener) => {
3991
4236
  if (listener === undefined || typeof listener !== "function") return () => {};
3992
4237
  listeners.add(listener);
@@ -4904,11 +5149,16 @@ window.__ModuleLoader__.load({
4904
5149
  } catch {}
4905
5150
  }
4906
5151
 
4907
- function showPaneToast(message) {
5152
+ function showPaneToast(message, force) {
4908
5153
  const now = Date.now();
4909
- if (now - paneToastAt < 4000) return;
5154
+ if (force !== true && now - paneToastAt < 4000) return;
4910
5155
  paneToastAt = now;
4911
5156
  try {
5157
+ // One toast at a time: forced action feedback may replace an earlier
5158
+ // one before its 4.2s lifetime ends.
5159
+ for (const previous of document.querySelectorAll(".dsv-toast")) {
5160
+ try { previous.remove(); } catch {}
5161
+ }
4912
5162
  const el = document.createElement("div");
4913
5163
  el.className = "dsv-toast";
4914
5164
  el.setAttribute("role", "status");
@@ -9505,6 +9755,29 @@ window.__ModuleLoader__.load({
9505
9755
  reset() {
9506
9756
  return safeCall("reset()", resetWorkspace, { reset: false });
9507
9757
  },
9758
+ /** Hard reset: also wipes every plugin-owned localStorage/sessionStorage
9759
+ key and the pane runtime caches, so a split can always start again. */
9760
+ resetAll() {
9761
+ return safeCall("resetAll()", resetSplitEnvironment, { reset: false, cleared: 0 });
9762
+ },
9763
+ /** Add one session to the split (or park it in the pending split while
9764
+ the workspace is inactive). */
9765
+ addToSplit(sessionId) {
9766
+ return safeCall("addToSplit()", () => addSessionToSplit(sessionId), false);
9767
+ },
9768
+ /** Remove one session from the split / pending pick. Dropping to one
9769
+ pane exits split mode. */
9770
+ removeFromSplit(sessionId) {
9771
+ return safeCall("removeFromSplit()", () => removeSessionFromSplit(sessionId), false);
9772
+ },
9773
+ /** Sessions waiting for a second pick before the split starts. */
9774
+ pending() {
9775
+ return safeCall("pending()", () => pendingSplitStore.ids(), []);
9776
+ },
9777
+ /** Open the add-split dialog programmatically (footer menu equivalent). */
9778
+ openAddSplitDialog() {
9779
+ return safeCall("openAddSplitDialog()", () => { openAddSplitDialog("footer"); return true; }, false);
9780
+ },
9508
9781
  /** Clear crash counters/safe mode and re-activate the kept tree. */
9509
9782
  retry() {
9510
9783
  return safeCall("retry()", retryWorkspace, false);
@@ -10698,6 +10971,7 @@ window.__ModuleLoader__.load({
10698
10971
  return h(React.Fragment, null,
10699
10972
  h(WorkspaceBoundary, { key: "workspace-" + runtime.epoch }, h(WorkspaceApp, props)),
10700
10973
  h(PluginChrome, null),
10974
+ h(SplitLauncherLayer, null),
10701
10975
  );
10702
10976
  }
10703
10977
 
@@ -11515,6 +11789,608 @@ window.__ModuleLoader__.load({
11515
11789
  }, 150);
11516
11790
  }
11517
11791
 
11792
+ // ---------------------------------------------------------------------
11793
+ // split launcher + session membership (0.5.0)
11794
+ //
11795
+ // The sidebar footer button opens a small menu (add / exit / minimize /
11796
+ // reset) and the "add split" dialog multi-selects conversations. Both are
11797
+ // rendered from the always-mounted shell.overlay seat, so neither is
11798
+ // clipped by the sidebar column nor covered by the split overlay. The
11799
+ // session-row right-click menu contributes its two membership actions
11800
+ // through the host's contextMenus service, so the stock menu keeps owning
11801
+ // its presentation and the contribution disappears when this plugin
11802
+ // unloads.
11803
+ // ---------------------------------------------------------------------
11804
+
11805
+ function usePendingSplit() {
11806
+ return React.useSyncExternalStore(
11807
+ pendingSplitStore.subscribe,
11808
+ pendingSplitStore.getSnapshot,
11809
+ pendingSplitStore.getSnapshot,
11810
+ );
11811
+ }
11812
+
11813
+ function sameSessionIds(left, right) {
11814
+ if (left.length !== right.length) return false;
11815
+ for (let index = 0; index < left.length; index += 1) {
11816
+ if (left[index] !== right[index]) return false;
11817
+ }
11818
+ return true;
11819
+ }
11820
+
11821
+ /** Aspect ratio of the conversation column; only decides columns vs rows
11822
+ for a two-pane split (the same 1.2 fallback settleAuto uses). */
11823
+ function splitColumnAspect() {
11824
+ try {
11825
+ const bounds = measureColumnBounds();
11826
+ if (bounds !== null && bounds !== undefined && bounds.ok === true) {
11827
+ const width = window.innerWidth - bounds.left - bounds.right;
11828
+ const height = window.innerHeight - bounds.top - bounds.bottom;
11829
+ if (width > 0 && height > 0) return width / height;
11830
+ }
11831
+ } catch {}
11832
+ return 1.2;
11833
+ }
11834
+
11835
+ /** A deliberate split action overrides the soft guards (kill switch and
11836
+ crash-loop safe mode): the user just asked for a split now. */
11837
+ function prepareExplicitSplit() {
11838
+ try {
11839
+ if (runtimeState.enabled !== true) setEnabled(true);
11840
+ if (runtimeState.safeMode === true) retryWorkspace();
11841
+ } catch {}
11842
+ }
11843
+
11844
+ function unminimizeForSplit() {
11845
+ if (runtimeState.minimized !== true) return;
11846
+ try {
11847
+ setRuntime({ minimized: false });
11848
+ writeMinimized(false);
11849
+ } catch {}
11850
+ }
11851
+
11852
+ function openSessionInMainView(sessionId) {
11853
+ try {
11854
+ const workspace = pluginCtx !== null && pluginCtx !== undefined && typeof pluginCtx.get === "function"
11855
+ ? pluginCtx.get("uiWorkspace")
11856
+ : null;
11857
+ if (workspace !== null && workspace !== undefined && typeof workspace.openSession === "function") {
11858
+ workspace.openSession(sessionId);
11859
+ }
11860
+ } catch {}
11861
+ }
11862
+
11863
+ /** Build the split from an ordered session list. Zero/one selection leaves
11864
+ split mode entirely (a one-pane workspace is not a split) and shows the
11865
+ single conversation in the stock main view. */
11866
+ function buildSplitFromSessions(ids) {
11867
+ const ordered = [];
11868
+ for (const id of Array.isArray(ids) ? ids : []) {
11869
+ if (!isValidSessionId(id) || ordered.indexOf(id) !== -1) continue;
11870
+ ordered.push(id);
11871
+ }
11872
+ if (ordered.length < 2) {
11873
+ try { exitWorkspace(); } catch {}
11874
+ if (ordered.length === 1) openSessionInMainView(ordered[0]);
11875
+ return false;
11876
+ }
11877
+ pendingSplitStore.clear();
11878
+ prepareExplicitSplit();
11879
+ unminimizeForSplit();
11880
+ const root = buildArrangedRoot(ordered, autoLayoutMode(ordered.length, splitColumnAspect()));
11881
+ try { treeStore.replaceRoot(root); } catch {}
11882
+ return true;
11883
+ }
11884
+
11885
+ /** Add one conversation to the split. Inactive: park it in the pending
11886
+ split until a second pick exists. Active: append a pane immediately. */
11887
+ function addSessionToSplit(sessionId) {
11888
+ if (!isValidSessionId(sessionId)) return false;
11889
+ const leaves = treeStore.leafIds();
11890
+ if (leaves.indexOf(sessionId) !== -1) {
11891
+ try { treeStore.setFocus(sessionId); } catch {}
11892
+ return false;
11893
+ }
11894
+ if (leaves.length > 0) {
11895
+ pendingSplitStore.clear();
11896
+ prepareExplicitSplit();
11897
+ unminimizeForSplit();
11898
+ try { treeStore.addPane(sessionId); } catch {}
11899
+ return true;
11900
+ }
11901
+ pendingSplitStore.add(sessionId);
11902
+ if (pendingSplitStore.size() >= 2) {
11903
+ const ids = pendingSplitStore.ids();
11904
+ pendingSplitStore.clear();
11905
+ buildSplitFromSessions(ids);
11906
+ } else {
11907
+ showPaneToast(t("pendingAdded"), true);
11908
+ }
11909
+ return true;
11910
+ }
11911
+
11912
+ /** Remove one conversation from the split (or from the pending pick).
11913
+ Dropping to one pane exits split mode entirely. */
11914
+ function removeSessionFromSplit(sessionId) {
11915
+ if (!isValidSessionId(sessionId)) return false;
11916
+ if (pendingSplitStore.has(sessionId)) {
11917
+ pendingSplitStore.remove(sessionId);
11918
+ showPaneToast(t("splitLeft"), true);
11919
+ return true;
11920
+ }
11921
+ const leaves = treeStore.leafIds();
11922
+ if (leaves.indexOf(sessionId) === -1) return false;
11923
+ if (leaves.length <= 2) {
11924
+ pendingSplitStore.clear();
11925
+ try { exitWorkspace(); } catch {}
11926
+ showPaneToast(t("splitExited"), true);
11927
+ return true;
11928
+ }
11929
+ closePaneAnimated(sessionId);
11930
+ return true;
11931
+ }
11932
+
11933
+ /** Remove every transient node the plugin may have appended to the body. */
11934
+ function clearTransientSplitDom() {
11935
+ try {
11936
+ for (const selector of [".dsv-toast", ".dsv-drag-preview", ".dsv-drop-ghost", ".dsv-pane-invalid"]) {
11937
+ for (const element of document.querySelectorAll(selector)) {
11938
+ try { element.remove(); } catch {}
11939
+ }
11940
+ }
11941
+ } catch {}
11942
+ try {
11943
+ if (dragImageCanvas !== null && dragImageCanvas !== undefined) dragImageCanvas.remove();
11944
+ } catch {}
11945
+ dragImageCanvas = null;
11946
+ try { endDragPreview(); } catch {}
11947
+ try { document.body.classList.remove("dsv-layout-previewing"); } catch {}
11948
+ try { tocGripsRestore(); } catch {}
11949
+ }
11950
+
11951
+ /** Drop per-pane runtime caches after the reset's unmount had a frame to
11952
+ run its own lifetime cleanup. A broken teardown could otherwise leave a
11953
+ stale retain/editor guard behind and the next split would inherit it. */
11954
+ function clearPaneRuntimeCaches() {
11955
+ try { treeStore.reset(); } catch {}
11956
+ if (composerAnchorBridge !== null) {
11957
+ try { composerAnchorBridge.dispose(); } catch {}
11958
+ composerAnchorBridge = null;
11959
+ }
11960
+ for (const reference of paneSessionReferences.values()) {
11961
+ try { if (reference !== null && typeof reference.release === "function") reference.release(); } catch {}
11962
+ }
11963
+ paneSessionReferences.clear();
11964
+ for (const guard of paneEditorGuards.values()) {
11965
+ try { if (guard !== null && typeof guard.dispose === "function") guard.dispose(); } catch {}
11966
+ }
11967
+ paneEditorGuards.clear();
11968
+ for (const timer of paneDisposeChecks.values()) {
11969
+ try { window.clearTimeout(timer); } catch {}
11970
+ }
11971
+ paneDisposeChecks.clear();
11972
+ paneLiveRefs.clear();
11973
+ for (const resolver of sessionFaceResolvers.values()) {
11974
+ try { if (resolver !== null && typeof resolver.dispose === "function") resolver.dispose(); } catch {}
11975
+ }
11976
+ sessionFaceResolvers.clear();
11977
+ paneRetainFailures.clear();
11978
+ for (const unsubscribe of paneTypingUnsubs.values()) {
11979
+ try { unsubscribe(); } catch {}
11980
+ }
11981
+ paneTypingUnsubs.clear();
11982
+ chatScrollMemory.clear();
11983
+ lastSessionSummaries.clear();
11984
+ entryStoreCache.clear();
11985
+ clearEntryInjectCache();
11986
+ paneImageIntake.clear();
11987
+ paneKitWarned.clear();
11988
+ rootPendingBySession.clear();
11989
+ rootPendingListeners.clear();
11990
+ composerModeStore.clear();
11991
+ composerActionsBySession.clear();
11992
+ setActiveComposerPaneId(null);
11993
+ paneToastAt = 0;
11994
+ lastTypedSessionId = null;
11995
+ storageRemove("dsh.split-workspace.last-typed.v1");
11996
+ }
11997
+
11998
+ /** "Reset split": wipe every key this plugin owns (localStorage AND
11999
+ sessionStorage, current and older releases), the persisted tree, the
12000
+ crash guard, the kill switch, minimized/maximized UI state and all
12001
+ transient pane data — so a split can always be started again even after
12002
+ a cache-driven failure. */
12003
+ function resetSplitEnvironment() {
12004
+ const cleared = [];
12005
+ closeLauncher();
12006
+ pendingSplitStore.clear();
12007
+ try { window.clearTimeout(minimizeTimer); } catch {}
12008
+ try { window.clearTimeout(exitTimer); } catch {}
12009
+ minimizeTimer = 0;
12010
+ exitTimer = 0;
12011
+ closingPaneSessions.clear();
12012
+ dragPayload = null;
12013
+ externalDragSessionId = null;
12014
+ clearTransientSplitDom();
12015
+ // Layout, safe mode, health counters, geometry block and the retry epoch
12016
+ // (the epoch bump remounts the overlay boundary with clean state).
12017
+ try { resetWorkspace(); } catch {}
12018
+ clearSplitStorage(window.localStorage, cleared);
12019
+ clearSplitStorage(window.sessionStorage, cleared);
12020
+ // resetWorkspace() keeps a kill switch intact; this action is explicitly
12021
+ // "make the split work again", so drop the flag (an absent key means
12022
+ // enabled) and clear the runtime flag below.
12023
+ storageRemove(ENABLED_KEY);
12024
+ setRuntime({
12025
+ enabled: true,
12026
+ safeMode: false,
12027
+ active: false,
12028
+ minimized: false,
12029
+ geometryBlocked: false,
12030
+ maximized: null,
12031
+ chipDismissed: false,
12032
+ tipVisible: false,
12033
+ helpOpen: false,
12034
+ });
12035
+ const resetEpoch = runtimeState.epoch;
12036
+ try {
12037
+ window.setTimeout(() => {
12038
+ // A split started within the grace window owns the caches now.
12039
+ if (runtimeState.epoch !== resetEpoch) return;
12040
+ try {
12041
+ if (treeStore.leafIds().length !== 0) return;
12042
+ clearPaneRuntimeCaches();
12043
+ } catch {}
12044
+ }, 350);
12045
+ } catch { try { clearPaneRuntimeCaches(); } catch {} }
12046
+ showPaneToast(t("resetDone"), true);
12047
+ return { reset: true, cleared: cleared.length };
12048
+ }
12049
+
12050
+ const SPLIT_STORAGE_PREFIX = "dsh.split-workspace.";
12051
+ function clearSplitStorage(storage, cleared) {
12052
+ if (storage === null || storage === undefined) return;
12053
+ const keys = [];
12054
+ try {
12055
+ for (let index = 0; index < storage.length; index += 1) {
12056
+ const key = storage.key(index);
12057
+ if (typeof key === "string" && key.indexOf(SPLIT_STORAGE_PREFIX) === 0) keys.push(key);
12058
+ }
12059
+ } catch {}
12060
+ for (const key of keys) {
12061
+ try {
12062
+ storage.removeItem(key);
12063
+ cleared.push(key);
12064
+ } catch {}
12065
+ }
12066
+ }
12067
+
12068
+ /** Contribute 加入分屏 / 退出分屏 to the stock session context menu. The
12069
+ service is looked up lazily: a host without ui-context-menu simply does
12070
+ not get the rows (nothing else changes). */
12071
+ function installSplitSessionMenu() {
12072
+ const ctx = pluginCtx;
12073
+ if (ctx === null || ctx === undefined || typeof ctx.get !== "function") return () => {};
12074
+ let timer = 0;
12075
+ let tries = 0;
12076
+ let dispose = null;
12077
+ const attempt = () => {
12078
+ timer = 0;
12079
+ let menus = undefined;
12080
+ try { menus = ctx.get("contextMenus"); } catch {}
12081
+ if (menus !== undefined && menus !== null && typeof menus.register === "function") {
12082
+ try {
12083
+ dispose = menus.register({
12084
+ id: "split-workspace.session",
12085
+ target: "session",
12086
+ order: 350,
12087
+ observe: () => [treeStore, pendingSplitStore],
12088
+ resolve: (target) => {
12089
+ const id = target !== null && target !== undefined ? target.sessionId : undefined;
12090
+ if (!isValidSessionId(id)) return [];
12091
+ const inSplit = treeStore.leafIds().indexOf(id) !== -1;
12092
+ const pending = pendingSplitStore.has(id);
12093
+ return [
12094
+ {
12095
+ id: "add",
12096
+ label: t("menuAddToSplit"),
12097
+ disabled: inSplit || pending,
12098
+ run: () => { addSessionToSplit(id); },
12099
+ },
12100
+ {
12101
+ id: "remove",
12102
+ label: t("exitSplit"),
12103
+ disabled: !inSplit && !pending,
12104
+ run: () => { removeSessionFromSplit(id); },
12105
+ },
12106
+ ];
12107
+ },
12108
+ });
12109
+ } catch (error) {
12110
+ try { console.warn(LOG_PREFIX + " could not register the session menu contribution:", String(error).slice(0, 160)); } catch {}
12111
+ }
12112
+ return;
12113
+ }
12114
+ if (tries >= 60) return;
12115
+ tries += 1;
12116
+ timer = window.setTimeout(attempt, 250);
12117
+ };
12118
+ attempt();
12119
+ return () => {
12120
+ if (timer !== 0) { try { window.clearTimeout(timer); } catch {} }
12121
+ if (dispose !== null) { try { dispose(); } catch {} }
12122
+ };
12123
+ }
12124
+
12125
+ function SplitPickCheck({ checked }) {
12126
+ return h("span", {
12127
+ className: "dsv-pick-check",
12128
+ "aria-hidden": "true",
12129
+ }, checked ? "✓" : "");
12130
+ }
12131
+
12132
+ function SplitPickRow({ item, checked, onToggle }) {
12133
+ return h("button", {
12134
+ type: "button",
12135
+ role: "checkbox",
12136
+ "aria-checked": checked ? "true" : "false",
12137
+ className: "dsv-pick-row",
12138
+ onClick: onToggle,
12139
+ },
12140
+ h(SplitPickCheck, { checked }),
12141
+ h("span", { className: "dsv-pick-text" },
12142
+ h("span", { className: "dsv-pick-title" }, item.title),
12143
+ item.sub !== "" ? h("span", { className: "dsv-pick-sub" }, item.sub) : null,
12144
+ ),
12145
+ item.tag !== null && item.tag !== undefined ? h("span", { className: "dsv-pick-tag" }, t(item.tag)) : null,
12146
+ );
12147
+ }
12148
+
12149
+ /** Multi-select "添加分屏" dialog. Opened from the footer menu, so the
12150
+ current members stay selected and can be unchecked (the final selection
12151
+ rebuilds the split) or extended with more conversations. */
12152
+ function AddSplitDialog() {
12153
+ const sessions = useSessionsList();
12154
+ const tree = useTree();
12155
+ const treeLeaves = tree.root === null ? [] : leafOf(tree.root, []);
12156
+ const initialSelection = treeLeaves.length >= 2 ? treeLeaves : pendingSplitStore.ids();
12157
+ const [selected, setSelected] = React.useState(() => initialSelection.slice());
12158
+ const [query, setQuery] = React.useState("");
12159
+
12160
+ // The DOM-backed list source observes only while the split is active;
12161
+ // refresh on mount so a picker opened from the stock view is current.
12162
+ React.useEffect(() => {
12163
+ try {
12164
+ if (sessionsListSource !== undefined && sessionsListSource !== null
12165
+ && typeof sessionsListSource.refresh === "function") sessionsListSource.refresh();
12166
+ } catch {}
12167
+ }, []);
12168
+
12169
+ const pendingIds = pendingSplitStore.ids();
12170
+ const items = [];
12171
+ const seen = new Set();
12172
+ if (sessions !== null && sessions !== undefined && Array.isArray(sessions.ids)) {
12173
+ for (const id of sessions.ids) {
12174
+ const summary = sessions.byId ? sessions.byId[id] : undefined;
12175
+ if (summary === undefined || summary === null) continue;
12176
+ if (summary.parentId !== undefined) continue;
12177
+ if (summary.origin === "subagent" || summary.blank === true) continue;
12178
+ if (id.indexOf("session-") !== 0) continue;
12179
+ seen.add(id);
12180
+ items.push({ id, summary, title: summary.displayTitle || summary.title || id });
12181
+ }
12182
+ }
12183
+ // A pane session the list no longer carries (archived/hidden) must stay
12184
+ // visible, otherwise it could never be unchecked.
12185
+ for (const id of selected) {
12186
+ if (seen.has(id)) continue;
12187
+ seen.add(id);
12188
+ items.push({ id, summary: null, title: id });
12189
+ }
12190
+ const needle = query.trim().toLowerCase();
12191
+ const visible = items.filter((item) => needle === "" || item.title.toLowerCase().includes(needle));
12192
+ visible.sort((a, b) => (Number(b.summary && b.summary.updatedAt) || 0) - (Number(a.summary && a.summary.updatedAt) || 0));
12193
+
12194
+ const toggle = (id) => setSelected((previous) => (previous.indexOf(id) === -1
12195
+ ? previous.concat([id])
12196
+ : previous.filter((entry) => entry !== id)));
12197
+
12198
+ const confirm = () => {
12199
+ const ids = selected.slice();
12200
+ closeLauncher();
12201
+ if (ids.length >= 2) {
12202
+ prepareExplicitSplit();
12203
+ unminimizeForSplit();
12204
+ const leavesNow = treeStore.leafIds();
12205
+ const additionsOnly = leavesNow.length >= 2 && ids.length > leavesNow.length
12206
+ && leavesNow.every((id) => ids.indexOf(id) !== -1);
12207
+ if (additionsOnly) {
12208
+ for (const id of ids) {
12209
+ if (leavesNow.indexOf(id) === -1) {
12210
+ try { treeStore.addPane(id); } catch {}
12211
+ }
12212
+ }
12213
+ } else if (!sameSessionIds(ids, leavesNow)) {
12214
+ buildSplitFromSessions(ids);
12215
+ }
12216
+ pendingSplitStore.clear();
12217
+ return;
12218
+ }
12219
+ const wasActive = treeStore.leafIds().length >= 2;
12220
+ pendingSplitStore.clear();
12221
+ if (!wasActive) {
12222
+ // Not in split mode yet: one pick becomes the pending split (the
12223
+ // dialog is also a way to stage the first conversation).
12224
+ if (ids.length === 1) {
12225
+ pendingSplitStore.add(ids[0]);
12226
+ showPaneToast(t("pendingAdded"), true);
12227
+ }
12228
+ return;
12229
+ }
12230
+ try { exitWorkspace(); } catch {}
12231
+ if (ids.length === 1) openSessionInMainView(ids[0]);
12232
+ showPaneToast(t("splitExited"), true);
12233
+ };
12234
+
12235
+ return h("div", {
12236
+ className: "dsv-modal-backdrop",
12237
+ onPointerDown: (event) => {
12238
+ if (event.target === event.currentTarget) closeLauncher();
12239
+ },
12240
+ onKeyDown: (event) => {
12241
+ if (event.key !== "Escape") return;
12242
+ event.preventDefault();
12243
+ event.stopPropagation();
12244
+ closeLauncher();
12245
+ },
12246
+ },
12247
+ h("div", {
12248
+ className: "dsv-modal",
12249
+ role: "dialog",
12250
+ "aria-modal": "true",
12251
+ "aria-label": t("addSplitTitle"),
12252
+ },
12253
+ h("div", { className: "dsv-modal-head" },
12254
+ h("span", { className: "dsv-modal-title" }, t("addSplitTitle")),
12255
+ h("button", {
12256
+ type: "button",
12257
+ className: "dsv-modal-close",
12258
+ title: t("addSplitCancel"),
12259
+ "aria-label": t("addSplitCancel"),
12260
+ onClick: closeLauncher,
12261
+ }, "×"),
12262
+ ),
12263
+ h("div", { className: "dsv-modal-hint" }, t("addSplitHint")),
12264
+ h("input", {
12265
+ className: "dsv-modal-search",
12266
+ type: "search",
12267
+ autoFocus: true,
12268
+ placeholder: t("railSearch"),
12269
+ value: query,
12270
+ onChange: (event) => setQuery(event.target.value),
12271
+ }),
12272
+ h("div", { className: "dsv-modal-body" },
12273
+ visible.length === 0 ? h("div", { className: "dsv-pick-empty" }, t("addSplitEmpty")) : null,
12274
+ visible.map((item) => h(SplitPickRow, {
12275
+ key: item.id,
12276
+ item: {
12277
+ title: item.title,
12278
+ sub: item.summary !== null && item.summary.cwd !== undefined ? basenameOf(item.summary.cwd) : "",
12279
+ tag: treeLeaves.indexOf(item.id) !== -1
12280
+ ? "addSplitInSplit"
12281
+ : (pendingIds.indexOf(item.id) !== -1 ? "addSplitPending" : null),
12282
+ },
12283
+ checked: selected.indexOf(item.id) !== -1,
12284
+ onToggle: () => toggle(item.id),
12285
+ })),
12286
+ ),
12287
+ h("div", { className: "dsv-modal-foot" },
12288
+ h("span", { className: "dsv-modal-count" }, t("addSplitSelected", { n: selected.length })),
12289
+ h("button", { type: "button", className: "dsv-modal-btn", onClick: closeLauncher }, t("addSplitCancel")),
12290
+ h("button", { type: "button", className: "dsv-modal-btn accent", onClick: confirm }, t("addSplitConfirm")),
12291
+ ),
12292
+ ),
12293
+ );
12294
+ }
12295
+
12296
+ function SplitLauncherMenu({ request }) {
12297
+ const runtime = useRuntime();
12298
+ const tree = useTree();
12299
+ const pending = usePendingSplit();
12300
+ const ref = React.useRef(null);
12301
+ const [pos, setPos] = React.useState(null);
12302
+ const leaves = tree.root === null ? [] : leafOf(tree.root, []);
12303
+ const active = leaves.length >= 2;
12304
+
12305
+ React.useLayoutEffect(() => {
12306
+ const element = ref.current;
12307
+ if (element === null) return;
12308
+ const width = element.offsetWidth || 200;
12309
+ const height = element.offsetHeight || 210;
12310
+ const rect = request !== null && request !== undefined ? request.rect : null;
12311
+ let left = rect !== null && rect !== undefined ? rect.left : 12;
12312
+ left = Math.min(Math.max(8, left), Math.max(8, window.innerWidth - width - 8));
12313
+ let top;
12314
+ if (rect !== null && rect !== undefined) {
12315
+ top = rect.top - height - 6;
12316
+ if (top < 8) top = Math.min(window.innerHeight - height - 8, rect.bottom + 6);
12317
+ } else {
12318
+ top = window.innerHeight - height - 12;
12319
+ }
12320
+ setPos({ left, top });
12321
+ }, [request]);
12322
+
12323
+ React.useEffect(() => {
12324
+ const onPointerDown = (event) => {
12325
+ const target = event.target;
12326
+ if (target !== null && target !== undefined && typeof target.closest === "function") {
12327
+ try {
12328
+ if (target.closest(".dsv-launcher-menu") !== null) return;
12329
+ if (target.closest(".dsv-footer-btn") !== null) return;
12330
+ } catch {}
12331
+ }
12332
+ closeLauncher();
12333
+ };
12334
+ const onKeyDown = (event) => {
12335
+ if (event.key !== "Escape") return;
12336
+ event.preventDefault();
12337
+ event.stopPropagation();
12338
+ closeLauncher();
12339
+ };
12340
+ document.addEventListener("pointerdown", onPointerDown, true);
12341
+ document.addEventListener("keydown", onKeyDown, true);
12342
+ return () => {
12343
+ document.removeEventListener("pointerdown", onPointerDown, true);
12344
+ document.removeEventListener("keydown", onKeyDown, true);
12345
+ };
12346
+ }, []);
12347
+
12348
+ const row = (key, icon, label, onClick, options) => h("button", {
12349
+ key,
12350
+ type: "button",
12351
+ role: "menuitem",
12352
+ className: "dsv-launcher-item" + (options !== undefined && options.danger === true ? " danger" : ""),
12353
+ disabled: options !== undefined && options.disabled === true,
12354
+ onClick: options !== undefined && options.disabled === true ? undefined : onClick,
12355
+ },
12356
+ h("span", { className: "dsv-launcher-icon", "aria-hidden": "true" }, icon),
12357
+ h("span", null, label),
12358
+ );
12359
+
12360
+ return h("div", {
12361
+ ref,
12362
+ className: "dsv-launcher-menu",
12363
+ role: "menu",
12364
+ "aria-label": t("menuTitle"),
12365
+ style: pos === null ? { left: "-9999px", top: "-9999px" } : pos,
12366
+ },
12367
+ h("div", { className: "dsv-launcher-header" },
12368
+ pending.length > 0 ? t("pendingBadge", { n: pending.length }) : t("menuTitle")),
12369
+ row("add", "+", t("menuAddSplit"), () => { closeLauncher(); openAddSplitDialog(request.source); }),
12370
+ h("div", { key: "separator-top", className: "dsv-launcher-separator" }),
12371
+ row("exit", "✕", t("exitSplit"), () => { closeLauncher(); try { exitWorkspace(); } catch {} }, { disabled: !active }),
12372
+ row("minimize", "—", t("menuMinimizeSplit"), () => { closeLauncher(); try { minimizeWorkspace(); } catch {} }, {
12373
+ disabled: !active || runtime.minimized === true,
12374
+ }),
12375
+ h("div", { key: "separator-bottom", className: "dsv-launcher-separator" }),
12376
+ row("reset", "↺", t("menuResetSplit"), () => { closeLauncher(); resetSplitEnvironment(); }, { danger: true }),
12377
+ );
12378
+ }
12379
+
12380
+ /** Always-mounted launcher layer (inside the shell.overlay seat). */
12381
+ function SplitLauncherLayer() {
12382
+ const launcher = useLauncherState();
12383
+ // A split that becomes active through any other entry point (drag,
12384
+ // pane-header picker, external API) retires the pending pick, so the
12385
+ // badge can never promise a pending conversation that is now a pane.
12386
+ React.useEffect(() => treeStore.subscribe(() => {
12387
+ if (treeStore.isActive() && pendingSplitStore.size() > 0) pendingSplitStore.clear();
12388
+ }), []);
12389
+ if (launcher.mode === "menu") return h(SplitLauncherMenu, { request: launcher });
12390
+ if (launcher.mode === "dialog") return h(AddSplitDialog, null);
12391
+ return null;
12392
+ }
12393
+
11518
12394
  function restoreSplit() {
11519
12395
  try {
11520
12396
  const tree = treeStore.getSnapshot();
@@ -11540,35 +12416,32 @@ window.__ModuleLoader__.load({
11540
12416
  writeMinimized(false);
11541
12417
  }
11542
12418
 
11543
- /** Sidebar-footer entry point: start a split with the current session plus
11544
- the next listed session. Drag-to-split remains the primary gesture; this
11545
- makes the feature discoverable without a pane already open. */
11546
- function startSplitFromFooter() {
11547
- try {
11548
- if (treeStore.leafIds().length >= 2) {
11549
- restoreSplit();
11550
- return;
11551
- }
11552
- const list = sessionsListSource;
11553
- const snap = list !== undefined && list !== null && typeof list.getSnapshot === "function" ? list.getSnapshot() : null;
11554
- const ids = snap !== null && snap !== undefined
11555
- ? (Array.isArray(snap.ids) ? snap.ids : Object.keys(snap.byId || {}))
11556
- : [];
11557
- const current = currentSessionId();
11558
- const first = current !== undefined && current !== null ? current : ids[0];
11559
- const second = ids.find((id) => id !== first);
11560
- if (first !== undefined && first !== null) treeStore.addPane(first);
11561
- if (second !== undefined && second !== null) treeStore.addPane(second);
11562
- } catch {}
11563
- }
12419
+ /** Sidebar-footer entry point: opens the split menu (add / exit / minimize
12420
+ / reset). Adding a split from the menu makes the feature discoverable
12421
+ without a pane already open; drag-to-split stays the primary gesture. */
11564
12422
  function FooterSplitButton() {
12423
+ const launcher = useLauncherState();
12424
+ const pending = usePendingSplit();
12425
+ const open = launcher.mode !== "closed";
11565
12426
  return h("button", {
11566
12427
  type: "button",
11567
12428
  className: "dsv-footer-btn",
11568
- title: t("openSplit"),
11569
- "aria-label": t("openSplit"),
11570
- onClick: startSplitFromFooter,
11571
- }, h(SplitIconV, { size: 15 }));
12429
+ title: pending.length > 0 ? t("pendingBadge", { n: pending.length }) : t("menuTitle"),
12430
+ "aria-label": t("menuTitle"),
12431
+ "aria-haspopup": "menu",
12432
+ "aria-expanded": open ? "true" : "false",
12433
+ "data-open": launcher.mode === "menu" ? "true" : "false",
12434
+ onClick: (event) => {
12435
+ if (open) {
12436
+ closeLauncher();
12437
+ return;
12438
+ }
12439
+ openLauncherMenu(event.currentTarget);
12440
+ },
12441
+ },
12442
+ h(SplitIconV, { size: 15 }),
12443
+ pending.length > 0 ? h("span", { className: "dsv-footer-badge" }, String(pending.length)) : null,
12444
+ );
11572
12445
  }
11573
12446
 
11574
12447
  /** True while apply() has installed the plugin; guards double-apply (a
@@ -11649,6 +12522,12 @@ window.__ModuleLoader__.load({
11649
12522
  // conversation column starts the split.
11650
12523
  ctx.effect(registerDragBridge, "dsh-split-workspace: drag bridge");
11651
12524
 
12525
+ // Session-row context menu contributions (加入分屏 / 退出分屏). The host's
12526
+ // contextMenus service owns the popup; this plugin only contributes
12527
+ // actions, so the stock menu keeps its look and the rows disappear on
12528
+ // unload.
12529
+ ctx.effect(installSplitSessionMenu, "dsh-split-workspace: session menu");
12530
+
11652
12531
  // Right-sidebar repair: the split teardown could leave the sidebar-right
11653
12532
  // store open while its column was closed (the corner button then vanished
11654
12533
  // with no way back) or leave a stock control writing to a seat nobody
@@ -11676,6 +12555,9 @@ window.__ModuleLoader__.load({
11676
12555
 
11677
12556
  ctx.effect(
11678
12557
  () => () => {
12558
+ closeLauncher();
12559
+ pendingSplitStore.clear();
12560
+ try { document.querySelectorAll(".dsv-launcher-menu").forEach((element) => element.remove()); } catch {}
11679
12561
  sessionsService = undefined;
11680
12562
  sessionsListSource = undefined;
11681
12563
  if (domListSourceDispose !== null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-split-workspace",
3
- "version": "0.4.3",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "description": "Split-screen workspace for DeepSeek Harness (DSH) Desktop: unlimited native panes, side-by-side, stacked and 2×2 grid layouts, drag to rearrange.",
6
6
  "icon": "./icon.svg",