dsh-mindmap 0.18.4 → 0.18.8

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/CHANGELOG.md +4 -0
  2. package/client.js +150 -19
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -38,6 +38,10 @@ All notable changes to this project are documented here. Release-specific notes
38
38
 
39
39
  ### Fixed
40
40
 
41
+ - Standalone panels now portal their fixed host to `document.body` instead of rendering inside the conversation header actions slot, preventing host header overflow from clipping the entire panel on DSH 0.2.2 (issue #5). Closing still keeps the workspace mounted with `display:none`; Better Sidebar tabs, layout-push behavior, resizing, and panel visuals remain unchanged.
42
+
43
+ - Focus synchronization no longer oscillates between two open mindmaps (issue #4). The AI-focus baseline is now event-driven — the document last created, opened, or updated by a tool result (read-only `mindmap_get` never moves it) — instead of the creation-order tail, which stayed pinned to the newer file so the comparison could never converge. Auto-sent `mindmap_open` messages are gated three ways: at most one per document per mount, a module-level per-session memory of sent display/focus pairs that survives tab remounts and dual windows, and a hard cap of 5 automatic opens per session that stops silently with a single notice (shown in both directory and mindmap views). Restored mount state (an out-of-sync display/focus pair established by the mount-time auto-open) is no longer a trigger, so a remounted tab or a reloaded page never sends a spontaneous message, and cwd arrival after a remount only changes the message's relative-path text instead of re-arming the effect. The sync effect now depends on values (displayed document, AI focus, visibility, session) rather than snapshot object identity, so remounts and unrelated tool results no longer re-fire it. Regression tests cover the two-document idle scenario (at most one message, then convergence), remount memory survival, and the hard-cap silent stop with a one-time notice.
44
+
41
45
  - Extend the full-file-access compatibility fix to root renames, clearing content, and broad rewrites: when the host's live `sandboxPolicy.resolve({ session })` explicitly returns `danger-full-access`, these operations no longer request an extra plugin approval that the full-access preset would automatically reject. This supersedes the high-risk exception in the earlier ordinary-write fix below. Non-full-access policies still gate high-risk writes, and disabling approval prompts alone grants no file access. Upstream approval decisions, path containment, collision checks, size limits, revision conflicts, and session-grant isolation are preserved; guidance, settings help, and security documentation now describe the same boundary.
42
46
  - Ordinary create/update calls no longer request an extra plugin confirmation when the host's live per-session `sandboxPolicy.resolve({ session })` explicitly returns `danger-full-access`. DSH's full-access preset also disables approval prompts, which rejects an extra `ask` as “the user rejected tool” even without a manual rejection. Full-access calls do not create reusable document grants, the workspace reports the effective confirmation mode, and effective-mode changes invalidate that session's prior grants and pending approval results without affecting other sessions. Switching back to a restricted policy restores the configured confirmation behavior. Renames, cleared content, broad rewrites, and upstream denials/asks/cancellations remain gated; missing, failing, or unknown policy APIs retain the previous confirmation policy. No session permission or host configuration is changed.
43
47
  - Read draft text and attachment state from the host's `useInput` snapshot, including edits made while a file request is pending. Unknown state preserves input; old action-face getters remain supported. Inline references and attachment-only drafts block automatic submission too.
package/client.js CHANGED
@@ -2,11 +2,11 @@
2
2
  //
3
3
  // 职责:
4
4
  // - 「思维脑图」按钮:挂 conversation.session.header.actions(list 槽,追加式),
5
- // 点击切换右侧悬浮脑图面板的开/合;面板宿主层(fixed)与按钮同槽位渲染,
6
- // 会话能力(useSession/sessionId/inputActions)经 props 直给面板组件。
7
- // - 脑图面板:014 起注册在 shell.overlay(list 槽、root scope、点击穿透层),
8
- // 右缘贴边全高悬浮、左缘拖拽调宽(280~80% 视口,localStorage 持久化);
9
- // details 槽已归还官方(原生「工具详情」栏恢复,003 的顶替方案退役)。
5
+ // 点击切换右侧悬浮脑图面板的开/合;会话能力(useSession/sessionId/inputActions)
6
+ // 经 props 直给面板组件。
7
+ // - 独立脑图面板:通过 react-dom portal 挂到 document.body,避开头部祖先的
8
+ // overflow 裁剪;右缘贴边全高悬浮、左缘拖拽调宽(280~80% 视口,
9
+ // localStorage 持久化)。details 槽已归还官方(003 的顶替方案退役)。
10
10
  // - 实时数据通路:消费会话快照里 mindmap_* 工具的 ToolResultNode,重放出各文档
11
11
  // 的最新内容并渲染(002/003:无自定义事件通道,工具调用本身就是事件流)。
12
12
  // 023 双代:useChat → ChatSnapshot.legacy.nodes(dsh 0.1.2-rc.1+)优先,
@@ -25,6 +25,7 @@ window.__ModuleLoader__.load({
25
25
  var exports = module.exports;
26
26
  let react_jsx_runtime = require("react/jsx-runtime");
27
27
  let react = require("react");
28
+ let react_dom = require("react-dom");
28
29
 
29
30
  const inject = ["slots"];
30
31
 
@@ -868,13 +869,22 @@ window.__ModuleLoader__.load({
868
869
  * content 文本块——host 的工具结果 JSON 就写在其中)。Code 等工具的结果
869
870
  * 还可能把真实的 mindmap ToolResultNode 放在 subCalls 中,因此这里按事件
870
871
  * 顺序递归重放整棵调用树。
871
- * 返回文档集及最近一次 create/open 意图,用于驱动面板自动切换目标。
872
+ * 返回文档集及最近一次 create/open 意图,用于驱动面板自动切换目标;
873
+ * latestActivePath(issue #4)= 最后一次 create/open/update 的文档,
874
+ * 作焦点同步的事件驱动比较基准——order 只反映首次出现顺序,不可比。
872
875
  */
876
+ // issue #4 焦点同步的事件驱动基准:这些 op 的成功结果代表 AI「最后正在
877
+ // 打开/编辑」的文档。get 是纯读(模型常仅为回答问题而读),不算焦点,
878
+ // 否则读一下另一颗脑图就会把面板的同步基准拽走。
879
+ const ACTIVE_OPS = new Set(["create", "open", "update"]);
880
+
873
881
  function reduceDocuments(nodes, cache) {
874
882
  const byPath = Object.create(null);
875
883
  let order = [];
876
884
  let latestOpeningPath = null;
877
885
  let latestOpeningEventKey = null;
886
+ // 最后一次 create/open/update 成功事件的文档路径(事件驱动焦点)。
887
+ let latestActivePath = null;
878
888
  // 016 错误捕获(S2 成因):isError / ok!==true 的 mindmap_* 结果不进
879
889
  // 文档集(语义不变),但记录为错误信号——errorByPath(可归因路径的
880
890
  // 最近错误)+ latestError(最近一次 mindmap 错误,含无路径归因的)。
@@ -923,6 +933,9 @@ window.__ModuleLoader__.load({
923
933
  latestOpeningPath = parsed.path;
924
934
  latestOpeningEventKey = eventKey;
925
935
  }
936
+ // issue #4:update(含 renameRoot 的新路径)同样移动
937
+ // 事件焦点——AI 编辑过谁,焦点就在谁。
938
+ if (ACTIVE_OPS.has(op)) latestActivePath = parsed.path;
926
939
  if (renamedFrom && renamedDocument && renamedFrom !== parsed.path) {
927
940
  delete byPath[renamedFrom];
928
941
  order = order.filter((p) => p !== renamedFrom);
@@ -974,7 +987,7 @@ window.__ModuleLoader__.load({
974
987
  for (const [nodeIndex, node] of (Array.isArray(nodes) ? nodes : []).entries()) {
975
988
  replayNode(node, String(nodeIndex), 0);
976
989
  }
977
- return { order, byPath, latestOpeningPath, latestOpeningEventKey, errorByPath, latestError };
990
+ return { order, byPath, latestOpeningPath, latestOpeningEventKey, latestActivePath, errorByPath, latestError };
978
991
  }
979
992
 
980
993
  /**
@@ -1021,6 +1034,7 @@ window.__ModuleLoader__.load({
1021
1034
  byPath,
1022
1035
  latestOpeningPath: snapshot?.latestOpeningPath ?? null,
1023
1036
  latestOpeningEventKey: snapshot?.latestOpeningEventKey ?? null,
1037
+ latestActivePath: snapshot?.latestActivePath ?? null,
1024
1038
  errorByPath: snapshot?.errorByPath ?? {},
1025
1039
  latestError: snapshot?.latestError ?? null,
1026
1040
  };
@@ -3675,12 +3689,20 @@ window.__ModuleLoader__.load({
3675
3689
  const [exporting, setExporting] = react.useState(false);
3676
3690
  const [exportError, setExportError] = react.useState("");
3677
3691
  const [filledHint, setFilledHint] = react.useState("");
3692
+ // issue #4:焦点同步超上限静默的一次性提示。独立于 filledHint——后者
3693
+ // 只渲染在目录视图,而触发上限时用户正盯着脑图,永远看不见。
3694
+ const [focusNotice, setFocusNotice] = react.useState("");
3678
3695
  // 032 复制全文:copying = 写剪贴板进行中;copiedOk = 成功短反馈
3679
3696
  //(按钮文案短暂变「已复制 ✓」约 2s;失败复用 exportError 展示位)。
3680
3697
  const [copying, setCopying] = react.useState(false);
3681
3698
  const [copiedOk, setCopiedOk] = react.useState(false);
3682
3699
  // fsTree:nodes = {path → 节点}, expanded = {path → true}, loading = {path → true}。
3683
3700
  const [fsTree, setFsTree] = react.useState({ nodes: {}, expanded: {}, loading: {}, cwd: null, error: null });
3701
+ // issue #4:cwd 只影响消息文本(相对/绝对路径),不改变「要不要发」。
3702
+ // 用 ref 在发送时刻读最新值,避免 cwd 到达(重挂载后目录树异步加载完)
3703
+ // 本身成为焦点同步 effect 的触发源。
3704
+ const fsTreeRef = react.useRef(fsTree);
3705
+ fsTreeRef.current = fsTree;
3684
3706
  // 会话切换时递增,使旧请求的异步回包不能写入新会话的目录树。
3685
3707
  const treeGenerationRef = react.useRef(0);
3686
3708
  // 013 右键菜单:{x, y, kind: "root"|"dir", rel};null = 关闭。
@@ -3748,11 +3770,21 @@ window.__ModuleLoader__.load({
3748
3770
  ? matchDocError(merged, doc.path, localErrorBaseRef.current)
3749
3771
  : null;
3750
3772
 
3751
- // 013「所见即所编」焦点同步:AI 焦点 = 快照里最新工具结果的文档路径;
3773
+ // 013「所见即所编」焦点同步:AI 焦点 = 最后一次 create/open/update 成功
3774
+ // 事件的文档(事件驱动)。issue #4:order 只反映文档首次出现(创建)的
3775
+ // 顺序,第二份脑图出现后 order 末位永远钉在较新文件上,显示旧文档时
3776
+ // 比较永不相等——自发消息循环的根因;改成事件驱动后,模型打开/编辑了
3777
+ // 用户正在看的文档,比较即可达「相等」从而收敛。
3752
3778
  // 脑图视图激活且其文档 ≠ 焦点时,仅在草稿为空时自动发送,让 AI
3753
3779
  // 跟上用户眼睛看的那颗脑图,又不覆盖用户正在编辑的消息。
3754
- const focusPath = docs.order.length > 0 ? docs.order[docs.order.length - 1] : null;
3780
+ const focusPath = docs.latestActivePath
3781
+ ?? (docs.order.length > 0 ? docs.order[docs.order.length - 1] : null);
3755
3782
  const focusSentRef = react.useRef(null);
3783
+ // issue #4 回路断点:auto-open 在挂载时确立的初始「显示 vs AI 焦点」
3784
+ // 组合(focusMountSkipRef)是存量状态,不是新变化——重挂载(BS 卸载
3785
+ // 不可见 Tab、二开窗口、页面重载)不得为它自发消息。真实变化(人类
3786
+ // 切换显示 / AI 工具事件改焦点)产生的是别的组合,照常触发。
3787
+ const focusMountSkipRef = react.useRef(null);
3756
3788
  // 所有这些状态都属于会话,不得让 A 会话的在途打开/目录结果遗留到 B。
3757
3789
  // 这个 effect 必须先于自动打开 effect 声明:React 会按声明顺序运行同一轮
3758
3790
  // effect,否则清理会把刚自动选中的脑图又切回「目录」。
@@ -3768,8 +3800,10 @@ window.__ModuleLoader__.load({
3768
3800
  setTreeMenu(null);
3769
3801
  setTabMenu(null);
3770
3802
  setFilledHint("");
3803
+ setFocusNotice("");
3771
3804
  localErrorBaseRef.current = null;
3772
3805
  focusSentRef.current = null;
3806
+ focusMountSkipRef.current = null;
3773
3807
  seen.current = null;
3774
3808
  prevIdsRef.current = { path: null, ids: null };
3775
3809
  return () => { documentReadRef.current += 1; };
@@ -3779,6 +3813,7 @@ window.__ModuleLoader__.load({
3779
3813
  // 无论面板/Tab 当前是否可见,都拉起并切到这次意图对应的文档;首次挂载的
3780
3814
  // 历史快照也照常显示最近一次打开的脑图,避免出现「AI 说已打开但面板没了」。
3781
3815
  react.useEffect(() => {
3816
+ const firstSight = seen.current === null; // 挂载/会话切换的恢复轮
3782
3817
  const targetPath = autoOpenTarget(merged, seen.current);
3783
3818
  seen.current = openingEventKeys(merged);
3784
3819
  if (targetPath) {
@@ -3790,21 +3825,49 @@ window.__ModuleLoader__.load({
3790
3825
  setHiddenPath(null);
3791
3826
  setCurrentPath(targetPath);
3792
3827
  setView("mindmap");
3828
+ // issue #4:只在恢复轮记下初始「显示 vs AI 焦点」组合,供焦点
3829
+ // 同步豁免——重挂载/切会话恢复的存量失配不是新变化;之后的
3830
+ // auto-open 都是真实新事件,不再刷新豁免(那会误吞真实失配)。
3831
+ if (firstSight) {
3832
+ focusMountSkipRef.current = { active: targetPath, focus: docs.latestActivePath ?? null };
3833
+ }
3793
3834
  }
3794
3835
  }, [merged, sessionId]);
3795
3836
 
3837
+ // issue #4 防振荡:effect 只由真实变化触发(显示文档 active / AI 焦点
3838
+ // focusPath / 可见性 / 会话),依赖全部是值——不再挂 docs 对象身份
3839
+ // (每个工具事件都换引用,等于任何事件都重跑)与 fsTree.cwd(重挂载
3840
+ // 后目录树异步到达)。防重三层:① 每次挂载对同一文档至多 1 条
3841
+ // (focusSentRef);② 同一「显示文档 vs AI 焦点」组合跨重挂载不重发
3842
+ // (focusGuard 模块级记忆,BS 卸载不可见 Tab / 双窗口都清不掉它);
3843
+ // ③ 每会话自动发送总量硬上限,超限静默停止并一次性提示。
3796
3844
  react.useEffect(() => {
3797
3845
  if (!visible) return; // 面板/Tab 不可见时不自动发消息
3798
3846
  if (!sessionId) return;
3799
3847
  if (!active || active === TREE_TAB) return;
3800
3848
  if (!docs.byPath[active]) return; // 本地占位:它的 open 请求已在途
3801
3849
  if (focusPath === active) return;
3802
- if (focusSentRef.current === active) return; // 已发过,等 AI 结果追平
3803
- const rel = fsTree.cwd ? relPathWithin(fsTree.cwd, active, stemOf(active)) : active;
3850
+ // 挂载恢复的存量失配(显示与焦点都等于 auto-open 记下的初始组合)
3851
+ // 不是新变化:重挂载/页面重载不得为它自发消息。
3852
+ if (focusMountSkipRef.current
3853
+ && focusMountSkipRef.current.active === active
3854
+ && focusMountSkipRef.current.focus === focusPath) return;
3855
+ if (focusSentRef.current === active) return; // 本次挂载已发过,等 AI 结果追平
3856
+ if (!focusGuard.maySend(sessionId, active, focusPath)) {
3857
+ // 组合已发过或已超会话上限:静默停止;超限只提示一次
3858
+ //(notified 标记在模块级 store 里,跨重挂载不重复提示)。
3859
+ if (focusGuard.shouldNotify(sessionId)) {
3860
+ focusGuard.markNotified(sessionId);
3861
+ setFocusNotice("自动焦点同步已达本会话上限,已静默停止;需要打开脑图请在聊天里直接说");
3862
+ }
3863
+ return;
3864
+ }
3865
+ const rel = fsTreeRef.current.cwd ? relPathWithin(fsTreeRef.current.cwd, active, stemOf(active)) : active;
3804
3866
  if (submitChatCommand(`用 mindmap_open 打开 ${rel}`)) {
3805
3867
  focusSentRef.current = active;
3868
+ focusGuard.record(sessionId, active, focusPath);
3806
3869
  }
3807
- }, [active, focusPath, fsTree.cwd, docs, visible]);
3870
+ }, [sessionId, visible, active, focusPath]);
3808
3871
 
3809
3872
  async function onExport() {
3810
3873
  if (!tree || !doc || exporting) return;
@@ -4356,7 +4419,11 @@ window.__ModuleLoader__.load({
4356
4419
  // 038 脑图区主体模式(目录 / 加载中 / 解析失败 / 画布):判定抽成纯函数,两个 variant
4357
4420
  // 共用同一份分派,不再各写一遍三元链;解析失败有独立分支,不再静默走目录。
4358
4421
  // 四态常量见 render.js 的 BODY_MODE(mindmapBodyMode 返回值与其同源)。
4359
- const bodyMode = mindmapBodyMode(active, TREE_TAB, doc, tree, parseError);
4422
+ const bodyMode = mindmapBodyMode(active, TREE_TAB, doc, tree, parseError);
4423
+ // issue #4:焦点同步超上限的一次性提示,两种视图、目录/脑图都可见。
4424
+ const focusNoticeView = focusNotice
4425
+ ? (0, react_jsx_runtime.jsx)("p", { style: S.emptyHint, children: focusNotice })
4426
+ : null;
4360
4427
  const parseErrorView = bodyMode === BODY_MODE.error
4361
4428
  ? (0, react_jsx_runtime.jsxs)("div", { style: S.loadingWrap, children: [
4362
4429
  (0, react_jsx_runtime.jsx)("span", { style: S.loadingFailMark, children: "⚠" }),
@@ -4424,6 +4491,7 @@ window.__ModuleLoader__.load({
4424
4491
  ] }),
4425
4492
  // 016:脑图视图走 MindmapCanvas(自带滚动 + 居中 + 右上角缩放控制条),
4426
4493
  // 不再套 S.body(避免嵌套滚动容器与双重 padding);目录/加载/空态保持原样。
4494
+ focusNoticeView,
4427
4495
  bodyMode === BODY_MODE.canvas
4428
4496
  ? (0, react_jsx_runtime.jsx)(MindmapCanvas, { node: tree, theme, fitKey: doc && doc.path, reveal, inputActions, readInputState })
4429
4497
  : (0, react_jsx_runtime.jsx)("div", { style: S.body, children: bodyMode === BODY_MODE.tree
@@ -4512,11 +4580,12 @@ window.__ModuleLoader__.load({
4512
4580
  }, shown) : null,
4513
4581
  ] }),
4514
4582
  ];
4515
- return (0, react_jsx_runtime.jsxs)("div", { style: { display: "flex", flexDirection: "column", flex: "1 1 auto", minHeight: 0 }, children: [
4516
- (0, react_jsx_runtime.jsx)("div", { style: wsHeaderStyle, children: wsHeaderChildren }),
4517
- // 016:脑图视图走 MindmapCanvas(自带滚动 + 居中 + 右上角缩放控制条),
4518
- // 不再套 S.body(避免嵌套滚动容器与双重 padding);目录/加载/空态保持原样。
4519
- active === TREE_TAB || (doc && doc.op === "local") || !tree
4583
+ return (0, react_jsx_runtime.jsxs)("div", { style: { display: "flex", flexDirection: "column", flex: "1 1 auto", minHeight: 0 }, children: [
4584
+ (0, react_jsx_runtime.jsx)("div", { style: wsHeaderStyle, children: wsHeaderChildren }),
4585
+ // 016:脑图视图走 MindmapCanvas(自带滚动 + 居中 + 右上角缩放控制条),
4586
+ // 不再套 S.body(避免嵌套滚动容器与双重 padding);目录/加载/空态保持原样。
4587
+ focusNoticeView,
4588
+ active === TREE_TAB || (doc && doc.op === "local") || !tree
4520
4589
  ? (0, react_jsx_runtime.jsx)("div", { style: S.body, children: active === TREE_TAB
4521
4590
  ? renderTree()
4522
4591
  : (doc && doc.op === "local")
@@ -4545,6 +4614,7 @@ window.__ModuleLoader__.load({
4545
4614
 
4546
4615
  /**
4547
4616
  * 独立 fixed 壳(026 拆分):仅 Better Sidebar 未安装或服务不可用时使用。
4617
+ * 通过 portal 挂到 document.body,避免被头部槽位祖先的 overflow 裁剪。
4548
4618
  * 管理壳特有几何——右缘贴边悬浮、左缘拖拽调宽(localStorage 持久化)、
4549
4619
  * 头部高度对齐聊天区、layout-push CSS 变量(--dsh-mindmap-width)。
4550
4620
  * 壳内始终挂载 MindmapWorkspace(visible=open):收起时 display:none 隐藏,
@@ -4708,10 +4778,11 @@ window.__ModuleLoader__.load({
4708
4778
  headerHeight,
4709
4779
  variant: "standalone",
4710
4780
  });
4711
- return (0, react_jsx_runtime.jsx)("div", { style: open ? S.panelHost : { display: "none" }, children: (0, react_jsx_runtime.jsxs)("div", { ref: panelRootRef, style: open ? { ...S.overlayRoot, width: panelWidth } : { display: "none" }, children: [
4781
+ const host = (0, react_jsx_runtime.jsx)("div", { style: open ? S.panelHost : { display: "none" }, children: (0, react_jsx_runtime.jsxs)("div", { ref: panelRootRef, style: open ? { ...S.overlayRoot, width: panelWidth } : { display: "none" }, children: [
4712
4782
  open ? (0, react_jsx_runtime.jsx)("div", { style: S.overlayHandle, onMouseDown: startResize }) : null,
4713
4783
  workspace,
4714
4784
  ] }) });
4785
+ return react_dom.createPortal(host, document.body);
4715
4786
  }
4716
4787
 
4717
4788
  /**
@@ -5014,6 +5085,62 @@ window.__ModuleLoader__.load({
5014
5085
  })();
5015
5086
  //#endregion
5016
5087
 
5088
+ //#region issue #4 焦点同步防振荡记忆
5089
+ // 焦点同步的防重与硬上限必须活过组件重挂载:BS 会卸载不可见的 Tab、
5090
+ // 同会话可能开两个窗口,每个面板实例各持一份组件 state(focusSentRef)
5091
+ // 会互相纠正,产生「打开 A→打开 B→打开 A」的自发消息振荡(issue #4)。
5092
+ // 因此防重记忆放模块级、按 sessionId 隔离:
5093
+ // - pairs:已自动发送过的「显示文档 \0 AI 焦点」组合——同一组合不重发
5094
+ // (防重按事件组合,不按单一 path;焦点真变了才算新事件);
5095
+ // - total:本会话自动发送总量,达到 FOCUS_SYNC_SESSION_CAP 后静默停止,
5096
+ // 由面板一次性提示(notified 标记,跨挂载不重复提示)。
5097
+ // 会话数超限时淘汰最旧条目,防长驻页面无限增长;clear() 供测试隔离。
5098
+ const FOCUS_SYNC_SESSION_CAP = 5;
5099
+ const FOCUS_SYNC_MAX_SESSIONS = 16;
5100
+ const focusGuard = (() => {
5101
+ const sessions = new Map();
5102
+ const pairKey = (activePath, focusPath) => `${activePath}\u0000${focusPath}`;
5103
+ function stateOf(sessionId) {
5104
+ let state = sessions.get(sessionId);
5105
+ if (!state) {
5106
+ state = { pairs: new Set(), total: 0, notified: false };
5107
+ sessions.set(sessionId, state);
5108
+ if (sessions.size > FOCUS_SYNC_MAX_SESSIONS) {
5109
+ sessions.delete(sessions.keys().next().value);
5110
+ }
5111
+ }
5112
+ return state;
5113
+ }
5114
+ return {
5115
+ // 该「显示文档 vs AI 焦点」组合是否还允许自动发送。
5116
+ maySend(sessionId, activePath, focusPath) {
5117
+ const state = sessions.get(sessionId);
5118
+ if (!state) return true;
5119
+ if (state.total >= FOCUS_SYNC_SESSION_CAP) return false;
5120
+ return !state.pairs.has(pairKey(activePath, focusPath));
5121
+ },
5122
+ // 记一次已发送(成对记忆 + 总量计数)。
5123
+ record(sessionId, activePath, focusPath) {
5124
+ const state = stateOf(sessionId);
5125
+ state.pairs.add(pairKey(activePath, focusPath));
5126
+ state.total += 1;
5127
+ },
5128
+ // 是否需要向用户提示一次「已超上限静默停止」。
5129
+ shouldNotify(sessionId) {
5130
+ const state = sessions.get(sessionId);
5131
+ return Boolean(state && state.total >= FOCUS_SYNC_SESSION_CAP && !state.notified);
5132
+ },
5133
+ markNotified(sessionId) {
5134
+ const state = sessions.get(sessionId);
5135
+ if (state) state.notified = true;
5136
+ },
5137
+ clear() {
5138
+ sessions.clear();
5139
+ },
5140
+ };
5141
+ })();
5142
+ //#endregion
5143
+
5017
5144
  /**
5018
5145
  * settings describe 应答的双代信封解析(023):dsh ≤0.1.1 的远端把
5019
5146
  * 描述符聚合在 result.value.namespaces[];0.1.2-rc.1 起直接返回描述符
@@ -5404,9 +5531,13 @@ window.__ModuleLoader__.load({
5404
5531
  // 026 better-sidebar 共存:服务总线 + 会话数据桥 + Tab 壳(供测试)。
5405
5532
  sidebarBus,
5406
5533
  sessionStore,
5534
+ // issue #4 焦点同步防振荡:跨重挂载的成对防重 + 会话总量硬上限(供测试)。
5535
+ focusGuard,
5536
+ FOCUS_SYNC_SESSION_CAP,
5407
5537
  MindmapSidebarTab,
5408
5538
  // 027 内嵌头部视觉对齐:壳无关工作区组件 + 样式表(供测试验证 variant 分支)。
5409
5539
  MindmapWorkspace,
5540
+ MindmapDetailsPanel,
5410
5541
  S,
5411
5542
  // 029 会话清理组件测试:MindmapSlot 直接调用(供测试验证 store 清理)。
5412
5543
  MindmapSlot,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mindmap",
3
- "version": "0.18.4",
3
+ "version": "0.18.8",
4
4
  "description": "Mindmap plugin for DeepSeek Harness: a plain markdown file in the working directory IS the mindmap; the chat edits it step by step and the right-side panel follows live.",
5
5
  "repository": {
6
6
  "type": "git",