dsh-mindmap 0.18.3 → 0.18.6

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
@@ -38,6 +38,9 @@ All notable changes to this project are documented here. Release-specific notes
38
38
 
39
39
  ### Fixed
40
40
 
41
+ - 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.
42
+
43
+ - 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.
41
44
  - 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.
42
45
  - 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.
43
46
  - Fresh disk reads no longer lose to older tool snapshots. A later tool event takes over normally; overlapping reads, closing, session switches, and newer open intents invalidate stale requests.
package/README.md CHANGED
@@ -35,7 +35,7 @@ A DeepSeek Harness plugin that turns a plain Markdown file into a live mindmap.
35
35
  - **Copy current node text** — 复制当前节点文本内容 sits immediately above 复制节点路径 in the node context menu. It copies only the current node's complete text, preserving line breaks and excluding ancestors, paths, and descendants. The mindmap and chat draft remain unchanged.
36
36
  - **Copy node path** — the node context menu includes 复制节点路径, which copies the complete root-to-current path as one plain-text line, for example `Node 1--->Node 2--->Node 3--->Node 4`. It excludes descendants and never submits a message or replaces the chat draft. Clipboard failures keep the menu open and show the error.
37
37
  - **Node search and quick navigation** — search the current mindmap by text (⌘/Ctrl+F, or the 🔍 in the zoom bar), jump through matches with Enter / ↑ ↓ (wrap-around), and automatically reveal matches inside collapsed subtrees. Jumping keeps your zoom and only scrolls; search is view-only, so the markdown never changes.
38
- - **Safety** — when the host's live session file policy explicitly grants `danger-full-access`, ordinary creates and updates do not request an additional plugin confirmation. Otherwise, write approval defaults to “once per session/document”; the settings page also offers “every write” and “disable ordinary confirmations”, and the current workspace shows and can revoke the current-session grant. Renames, cleared content, and broad rewrites still require a separate confirmation in every mode. Disabling approval prompts alone is not file authorization: the host automatically rejects requests that still need confirmation, including high-risk writes under its full-access preset. Missing or unrecognized host policy APIs retain the configured confirmation policy. Trusted automation can explicitly set `requireApproval: false` to skip ordinary confirmations; high-risk writes remain gated. The client has **no write path** to the filesystem — every edit goes through the AI tools.
38
+ - **Safety** — when the host's live session file policy explicitly grants `danger-full-access`, all mindmap writes (create, update, rename, clearing content, and broad rewrites) skip this plugin's additional confirmation. This follows the effective file policy, including custom presets, not the approval-prompt setting; upstream approval decisions and path, collision, size, and revision checks still apply. Otherwise, write approval defaults to “once per session/document”; the settings page also offers “every write” and “disable ordinary confirmations”, and the current workspace shows and can revoke the current-session grant. Without full file access, renames, cleared content, and broad rewrites still require a separate confirmation, even with `approvalMode: off` or `requireApproval: false`. Disabling approval prompts alone is not file authorization: the host automatically rejects requests that still need confirmation. Missing, failing, or unrecognized host policy APIs retain the configured confirmation policy. Full-access calls do not create reusable document grants; returning to restricted permissions restores the configured confirmation behavior. The client has **no write path** to the filesystem — every edit goes through the AI tools.
39
39
 
40
40
  Inside Better Sidebar, the mindmap list uses the host's 14px body typography. Markdown files carry a compact M badge; folders and other files use 14px outline icons. Other file formats are display-only, without hover feedback, opening, dragging, or context menus; folders remain expandable. Tabs, actions, and hints use the host's 12px typography role. Standalone mode retains its original appearance, and mindmap node typography, zoom, and image export are unchanged.
41
41
 
package/README.zh-CN.md CHANGED
@@ -35,7 +35,7 @@
35
35
  - **复制当前节点文本内容**——节点右键菜单中位于「复制节点路径」正上方。只复制当前节点自身的完整文本,保留原有换行;不包含父节点、路径或子节点,不修改脑图或聊天草稿。
36
36
  - **复制节点路径**——节点右键菜单新增「复制节点路径」,把根节点到当前节点的完整路径复制为单行纯文本,例如 `节点1--->节点2--->节点3--->节点4`。不包含子节点,也不自动发送消息或覆盖聊天草稿;复制失败时保留菜单并提示原因。
37
37
  - **节点搜索与快速定位**——⌘/Ctrl+F(或缩放条上的 🔍)在当前脑图中搜索文字,Enter / ↑ ↓ 逐个跳转匹配节点(双向环绕),并自动展开被折叠分支中的搜索结果;跳转保留当前缩放、只滚动视图。搜索只改视图状态,绝不动 Markdown。
38
- - **安全**——宿主对当前会话明确授予 `danger-full-access`(完全文件权限)时,普通新建和更新不额外请求插件确认。其他情况下,写入确认默认采用“本会话一次”,也可切换为“每次确认”或“关闭普通确认”;当前脑图工作区会显示并可撤销本会话授权。重命名、清空和大范围重写在所有模式下仍需单独确认。仅关闭审批弹窗不等于授予文件权限:宿主会自动拒绝仍需确认的请求,包括完全权限预设下的高风险写入。宿主策略接口缺失或返回未知值时,沿用配置的确认策略。受信自动化可显式设置 `requireApproval: false` 关闭普通确认,但高风险写入仍需确认。客户端**没有任何写文件通道**,一切编辑都经 AI 工具。
38
+ - **安全**——宿主对当前会话明确授予 `danger-full-access`(完全文件权限)时,新建、更新、重命名、清空和大范围重写均不额外请求插件确认。判断依据是宿主实时解析的文件权限(包括自定义预设),不是审批弹窗开关;宿主其他审批决定与路径、重名、大小、版本冲突检查仍保留。其他情况下,写入确认默认采用“本会话一次”,也可切换为“每次确认”或“关闭普通确认”;当前脑图工作区会显示并可撤销本会话授权。非完全权限时,重命名、清空和大范围重写仍需单独确认,`approvalMode: off` 或 `requireApproval: false` 只能关闭普通确认。仅关闭审批弹窗不等于授予文件权限:宿主会自动拒绝仍需确认的请求。宿主策略接口缺失、解析失败或返回未知值时,沿用配置的确认策略。完全权限下不积累可复用的文档授权,切回受限权限后恢复配置的确认策略。客户端**没有任何写文件通道**,一切编辑都经 AI 工具。
39
39
 
40
40
  内嵌 Better Sidebar 时,脑图列表采用宿主的 14px 正文字体。Markdown 文件显示紧凑的 M 徽标,文件夹与其他文件使用 14px 线框图标;其他格式文件仅展示,没有悬停反馈、打开、拖拽或右键菜单,文件夹仍可展开。标签、操作按钮和提示采用宿主的 12px 字体角色。独立模式保留原有外观;脑图节点的基础字体层级和图片导出保持不变。
41
41
 
package/client.js CHANGED
@@ -868,13 +868,22 @@ window.__ModuleLoader__.load({
868
868
  * content 文本块——host 的工具结果 JSON 就写在其中)。Code 等工具的结果
869
869
  * 还可能把真实的 mindmap ToolResultNode 放在 subCalls 中,因此这里按事件
870
870
  * 顺序递归重放整棵调用树。
871
- * 返回文档集及最近一次 create/open 意图,用于驱动面板自动切换目标。
871
+ * 返回文档集及最近一次 create/open 意图,用于驱动面板自动切换目标;
872
+ * latestActivePath(issue #4)= 最后一次 create/open/update 的文档,
873
+ * 作焦点同步的事件驱动比较基准——order 只反映首次出现顺序,不可比。
872
874
  */
875
+ // issue #4 焦点同步的事件驱动基准:这些 op 的成功结果代表 AI「最后正在
876
+ // 打开/编辑」的文档。get 是纯读(模型常仅为回答问题而读),不算焦点,
877
+ // 否则读一下另一颗脑图就会把面板的同步基准拽走。
878
+ const ACTIVE_OPS = new Set(["create", "open", "update"]);
879
+
873
880
  function reduceDocuments(nodes, cache) {
874
881
  const byPath = Object.create(null);
875
882
  let order = [];
876
883
  let latestOpeningPath = null;
877
884
  let latestOpeningEventKey = null;
885
+ // 最后一次 create/open/update 成功事件的文档路径(事件驱动焦点)。
886
+ let latestActivePath = null;
878
887
  // 016 错误捕获(S2 成因):isError / ok!==true 的 mindmap_* 结果不进
879
888
  // 文档集(语义不变),但记录为错误信号——errorByPath(可归因路径的
880
889
  // 最近错误)+ latestError(最近一次 mindmap 错误,含无路径归因的)。
@@ -923,6 +932,9 @@ window.__ModuleLoader__.load({
923
932
  latestOpeningPath = parsed.path;
924
933
  latestOpeningEventKey = eventKey;
925
934
  }
935
+ // issue #4:update(含 renameRoot 的新路径)同样移动
936
+ // 事件焦点——AI 编辑过谁,焦点就在谁。
937
+ if (ACTIVE_OPS.has(op)) latestActivePath = parsed.path;
926
938
  if (renamedFrom && renamedDocument && renamedFrom !== parsed.path) {
927
939
  delete byPath[renamedFrom];
928
940
  order = order.filter((p) => p !== renamedFrom);
@@ -974,7 +986,7 @@ window.__ModuleLoader__.load({
974
986
  for (const [nodeIndex, node] of (Array.isArray(nodes) ? nodes : []).entries()) {
975
987
  replayNode(node, String(nodeIndex), 0);
976
988
  }
977
- return { order, byPath, latestOpeningPath, latestOpeningEventKey, errorByPath, latestError };
989
+ return { order, byPath, latestOpeningPath, latestOpeningEventKey, latestActivePath, errorByPath, latestError };
978
990
  }
979
991
 
980
992
  /**
@@ -1021,6 +1033,7 @@ window.__ModuleLoader__.load({
1021
1033
  byPath,
1022
1034
  latestOpeningPath: snapshot?.latestOpeningPath ?? null,
1023
1035
  latestOpeningEventKey: snapshot?.latestOpeningEventKey ?? null,
1036
+ latestActivePath: snapshot?.latestActivePath ?? null,
1024
1037
  errorByPath: snapshot?.errorByPath ?? {},
1025
1038
  latestError: snapshot?.latestError ?? null,
1026
1039
  };
@@ -1980,8 +1993,8 @@ window.__ModuleLoader__.load({
1980
1993
  onChange: (v) => setField({ approvalMode: v }),
1981
1994
  }),
1982
1995
  ] }),
1983
- (0, react_jsx_runtime.jsx)("p", { style: S.settingsHint, children: value.approvalMode === "session" ? "本会话首次写入当前脑图后,后续普通更新无需重复确认。切换文件或会话会重新确认。" : value.approvalMode === "off" ? "普通更新不再弹窗;重命名、删除和大范围重写仍需确认。" : "每次写入都会弹窗确认。" }),
1984
- (0, react_jsx_runtime.jsx)("p", { style: S.settingsHint, children: "DSH 明确授予完全文件权限时,普通新建和更新不额外确认;重命名、清空和大范围重写仍需确认。仅关闭审批弹窗不等于授予文件权限。" }),
1996
+ (0, react_jsx_runtime.jsx)("p", { style: S.settingsHint, children: value.approvalMode === "session" ? "非完全权限时,本会话首次写入当前脑图后,后续普通更新无需重复确认。切换文件或会话会重新确认。" : value.approvalMode === "off" ? "非完全权限时,普通更新不再弹窗;重命名、清空和大范围重写仍需确认。" : "非完全权限时,每次写入都会弹窗确认。" }),
1997
+ (0, react_jsx_runtime.jsx)("p", { style: S.settingsHint, children: "DSH 明确授予完全文件权限时,新建、更新、重命名、清空和大范围重写均不额外请求插件确认;路径、重名和版本冲突检查仍保留。仅关闭审批弹窗不等于授予文件权限,也不会绕过宿主的其他审批决定。" }),
1985
1998
  value.approvalMode === "session" ? (0, react_jsx_runtime.jsx)("p", { style: S.settingsHint, children: "授权状态显示在当前脑图工作区;可在那里撤销当前会话的普通写入授权。" }) : null,
1986
1999
  ] }),
1987
2000
  saving ? (0, react_jsx_runtime.jsx)("p", { style: S.settingsHint, children: "保存中…" }) : null,
@@ -3675,12 +3688,20 @@ window.__ModuleLoader__.load({
3675
3688
  const [exporting, setExporting] = react.useState(false);
3676
3689
  const [exportError, setExportError] = react.useState("");
3677
3690
  const [filledHint, setFilledHint] = react.useState("");
3691
+ // issue #4:焦点同步超上限静默的一次性提示。独立于 filledHint——后者
3692
+ // 只渲染在目录视图,而触发上限时用户正盯着脑图,永远看不见。
3693
+ const [focusNotice, setFocusNotice] = react.useState("");
3678
3694
  // 032 复制全文:copying = 写剪贴板进行中;copiedOk = 成功短反馈
3679
3695
  //(按钮文案短暂变「已复制 ✓」约 2s;失败复用 exportError 展示位)。
3680
3696
  const [copying, setCopying] = react.useState(false);
3681
3697
  const [copiedOk, setCopiedOk] = react.useState(false);
3682
3698
  // fsTree:nodes = {path → 节点}, expanded = {path → true}, loading = {path → true}。
3683
3699
  const [fsTree, setFsTree] = react.useState({ nodes: {}, expanded: {}, loading: {}, cwd: null, error: null });
3700
+ // issue #4:cwd 只影响消息文本(相对/绝对路径),不改变「要不要发」。
3701
+ // 用 ref 在发送时刻读最新值,避免 cwd 到达(重挂载后目录树异步加载完)
3702
+ // 本身成为焦点同步 effect 的触发源。
3703
+ const fsTreeRef = react.useRef(fsTree);
3704
+ fsTreeRef.current = fsTree;
3684
3705
  // 会话切换时递增,使旧请求的异步回包不能写入新会话的目录树。
3685
3706
  const treeGenerationRef = react.useRef(0);
3686
3707
  // 013 右键菜单:{x, y, kind: "root"|"dir", rel};null = 关闭。
@@ -3748,11 +3769,21 @@ window.__ModuleLoader__.load({
3748
3769
  ? matchDocError(merged, doc.path, localErrorBaseRef.current)
3749
3770
  : null;
3750
3771
 
3751
- // 013「所见即所编」焦点同步:AI 焦点 = 快照里最新工具结果的文档路径;
3772
+ // 013「所见即所编」焦点同步:AI 焦点 = 最后一次 create/open/update 成功
3773
+ // 事件的文档(事件驱动)。issue #4:order 只反映文档首次出现(创建)的
3774
+ // 顺序,第二份脑图出现后 order 末位永远钉在较新文件上,显示旧文档时
3775
+ // 比较永不相等——自发消息循环的根因;改成事件驱动后,模型打开/编辑了
3776
+ // 用户正在看的文档,比较即可达「相等」从而收敛。
3752
3777
  // 脑图视图激活且其文档 ≠ 焦点时,仅在草稿为空时自动发送,让 AI
3753
3778
  // 跟上用户眼睛看的那颗脑图,又不覆盖用户正在编辑的消息。
3754
- const focusPath = docs.order.length > 0 ? docs.order[docs.order.length - 1] : null;
3779
+ const focusPath = docs.latestActivePath
3780
+ ?? (docs.order.length > 0 ? docs.order[docs.order.length - 1] : null);
3755
3781
  const focusSentRef = react.useRef(null);
3782
+ // issue #4 回路断点:auto-open 在挂载时确立的初始「显示 vs AI 焦点」
3783
+ // 组合(focusMountSkipRef)是存量状态,不是新变化——重挂载(BS 卸载
3784
+ // 不可见 Tab、二开窗口、页面重载)不得为它自发消息。真实变化(人类
3785
+ // 切换显示 / AI 工具事件改焦点)产生的是别的组合,照常触发。
3786
+ const focusMountSkipRef = react.useRef(null);
3756
3787
  // 所有这些状态都属于会话,不得让 A 会话的在途打开/目录结果遗留到 B。
3757
3788
  // 这个 effect 必须先于自动打开 effect 声明:React 会按声明顺序运行同一轮
3758
3789
  // effect,否则清理会把刚自动选中的脑图又切回「目录」。
@@ -3768,8 +3799,10 @@ window.__ModuleLoader__.load({
3768
3799
  setTreeMenu(null);
3769
3800
  setTabMenu(null);
3770
3801
  setFilledHint("");
3802
+ setFocusNotice("");
3771
3803
  localErrorBaseRef.current = null;
3772
3804
  focusSentRef.current = null;
3805
+ focusMountSkipRef.current = null;
3773
3806
  seen.current = null;
3774
3807
  prevIdsRef.current = { path: null, ids: null };
3775
3808
  return () => { documentReadRef.current += 1; };
@@ -3779,6 +3812,7 @@ window.__ModuleLoader__.load({
3779
3812
  // 无论面板/Tab 当前是否可见,都拉起并切到这次意图对应的文档;首次挂载的
3780
3813
  // 历史快照也照常显示最近一次打开的脑图,避免出现「AI 说已打开但面板没了」。
3781
3814
  react.useEffect(() => {
3815
+ const firstSight = seen.current === null; // 挂载/会话切换的恢复轮
3782
3816
  const targetPath = autoOpenTarget(merged, seen.current);
3783
3817
  seen.current = openingEventKeys(merged);
3784
3818
  if (targetPath) {
@@ -3790,21 +3824,49 @@ window.__ModuleLoader__.load({
3790
3824
  setHiddenPath(null);
3791
3825
  setCurrentPath(targetPath);
3792
3826
  setView("mindmap");
3827
+ // issue #4:只在恢复轮记下初始「显示 vs AI 焦点」组合,供焦点
3828
+ // 同步豁免——重挂载/切会话恢复的存量失配不是新变化;之后的
3829
+ // auto-open 都是真实新事件,不再刷新豁免(那会误吞真实失配)。
3830
+ if (firstSight) {
3831
+ focusMountSkipRef.current = { active: targetPath, focus: docs.latestActivePath ?? null };
3832
+ }
3793
3833
  }
3794
3834
  }, [merged, sessionId]);
3795
3835
 
3836
+ // issue #4 防振荡:effect 只由真实变化触发(显示文档 active / AI 焦点
3837
+ // focusPath / 可见性 / 会话),依赖全部是值——不再挂 docs 对象身份
3838
+ // (每个工具事件都换引用,等于任何事件都重跑)与 fsTree.cwd(重挂载
3839
+ // 后目录树异步到达)。防重三层:① 每次挂载对同一文档至多 1 条
3840
+ // (focusSentRef);② 同一「显示文档 vs AI 焦点」组合跨重挂载不重发
3841
+ // (focusGuard 模块级记忆,BS 卸载不可见 Tab / 双窗口都清不掉它);
3842
+ // ③ 每会话自动发送总量硬上限,超限静默停止并一次性提示。
3796
3843
  react.useEffect(() => {
3797
3844
  if (!visible) return; // 面板/Tab 不可见时不自动发消息
3798
3845
  if (!sessionId) return;
3799
3846
  if (!active || active === TREE_TAB) return;
3800
3847
  if (!docs.byPath[active]) return; // 本地占位:它的 open 请求已在途
3801
3848
  if (focusPath === active) return;
3802
- if (focusSentRef.current === active) return; // 已发过,等 AI 结果追平
3803
- const rel = fsTree.cwd ? relPathWithin(fsTree.cwd, active, stemOf(active)) : active;
3849
+ // 挂载恢复的存量失配(显示与焦点都等于 auto-open 记下的初始组合)
3850
+ // 不是新变化:重挂载/页面重载不得为它自发消息。
3851
+ if (focusMountSkipRef.current
3852
+ && focusMountSkipRef.current.active === active
3853
+ && focusMountSkipRef.current.focus === focusPath) return;
3854
+ if (focusSentRef.current === active) return; // 本次挂载已发过,等 AI 结果追平
3855
+ if (!focusGuard.maySend(sessionId, active, focusPath)) {
3856
+ // 组合已发过或已超会话上限:静默停止;超限只提示一次
3857
+ //(notified 标记在模块级 store 里,跨重挂载不重复提示)。
3858
+ if (focusGuard.shouldNotify(sessionId)) {
3859
+ focusGuard.markNotified(sessionId);
3860
+ setFocusNotice("自动焦点同步已达本会话上限,已静默停止;需要打开脑图请在聊天里直接说");
3861
+ }
3862
+ return;
3863
+ }
3864
+ const rel = fsTreeRef.current.cwd ? relPathWithin(fsTreeRef.current.cwd, active, stemOf(active)) : active;
3804
3865
  if (submitChatCommand(`用 mindmap_open 打开 ${rel}`)) {
3805
3866
  focusSentRef.current = active;
3867
+ focusGuard.record(sessionId, active, focusPath);
3806
3868
  }
3807
- }, [active, focusPath, fsTree.cwd, docs, visible]);
3869
+ }, [sessionId, visible, active, focusPath]);
3808
3870
 
3809
3871
  async function onExport() {
3810
3872
  if (!tree || !doc || exporting) return;
@@ -4356,7 +4418,11 @@ window.__ModuleLoader__.load({
4356
4418
  // 038 脑图区主体模式(目录 / 加载中 / 解析失败 / 画布):判定抽成纯函数,两个 variant
4357
4419
  // 共用同一份分派,不再各写一遍三元链;解析失败有独立分支,不再静默走目录。
4358
4420
  // 四态常量见 render.js 的 BODY_MODE(mindmapBodyMode 返回值与其同源)。
4359
- const bodyMode = mindmapBodyMode(active, TREE_TAB, doc, tree, parseError);
4421
+ const bodyMode = mindmapBodyMode(active, TREE_TAB, doc, tree, parseError);
4422
+ // issue #4:焦点同步超上限的一次性提示,两种视图、目录/脑图都可见。
4423
+ const focusNoticeView = focusNotice
4424
+ ? (0, react_jsx_runtime.jsx)("p", { style: S.emptyHint, children: focusNotice })
4425
+ : null;
4360
4426
  const parseErrorView = bodyMode === BODY_MODE.error
4361
4427
  ? (0, react_jsx_runtime.jsxs)("div", { style: S.loadingWrap, children: [
4362
4428
  (0, react_jsx_runtime.jsx)("span", { style: S.loadingFailMark, children: "⚠" }),
@@ -4424,6 +4490,7 @@ window.__ModuleLoader__.load({
4424
4490
  ] }),
4425
4491
  // 016:脑图视图走 MindmapCanvas(自带滚动 + 居中 + 右上角缩放控制条),
4426
4492
  // 不再套 S.body(避免嵌套滚动容器与双重 padding);目录/加载/空态保持原样。
4493
+ focusNoticeView,
4427
4494
  bodyMode === BODY_MODE.canvas
4428
4495
  ? (0, react_jsx_runtime.jsx)(MindmapCanvas, { node: tree, theme, fitKey: doc && doc.path, reveal, inputActions, readInputState })
4429
4496
  : (0, react_jsx_runtime.jsx)("div", { style: S.body, children: bodyMode === BODY_MODE.tree
@@ -4512,11 +4579,12 @@ window.__ModuleLoader__.load({
4512
4579
  }, shown) : null,
4513
4580
  ] }),
4514
4581
  ];
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
4582
+ return (0, react_jsx_runtime.jsxs)("div", { style: { display: "flex", flexDirection: "column", flex: "1 1 auto", minHeight: 0 }, children: [
4583
+ (0, react_jsx_runtime.jsx)("div", { style: wsHeaderStyle, children: wsHeaderChildren }),
4584
+ // 016:脑图视图走 MindmapCanvas(自带滚动 + 居中 + 右上角缩放控制条),
4585
+ // 不再套 S.body(避免嵌套滚动容器与双重 padding);目录/加载/空态保持原样。
4586
+ focusNoticeView,
4587
+ active === TREE_TAB || (doc && doc.op === "local") || !tree
4520
4588
  ? (0, react_jsx_runtime.jsx)("div", { style: S.body, children: active === TREE_TAB
4521
4589
  ? renderTree()
4522
4590
  : (doc && doc.op === "local")
@@ -5014,6 +5082,62 @@ window.__ModuleLoader__.load({
5014
5082
  })();
5015
5083
  //#endregion
5016
5084
 
5085
+ //#region issue #4 焦点同步防振荡记忆
5086
+ // 焦点同步的防重与硬上限必须活过组件重挂载:BS 会卸载不可见的 Tab、
5087
+ // 同会话可能开两个窗口,每个面板实例各持一份组件 state(focusSentRef)
5088
+ // 会互相纠正,产生「打开 A→打开 B→打开 A」的自发消息振荡(issue #4)。
5089
+ // 因此防重记忆放模块级、按 sessionId 隔离:
5090
+ // - pairs:已自动发送过的「显示文档 \0 AI 焦点」组合——同一组合不重发
5091
+ // (防重按事件组合,不按单一 path;焦点真变了才算新事件);
5092
+ // - total:本会话自动发送总量,达到 FOCUS_SYNC_SESSION_CAP 后静默停止,
5093
+ // 由面板一次性提示(notified 标记,跨挂载不重复提示)。
5094
+ // 会话数超限时淘汰最旧条目,防长驻页面无限增长;clear() 供测试隔离。
5095
+ const FOCUS_SYNC_SESSION_CAP = 5;
5096
+ const FOCUS_SYNC_MAX_SESSIONS = 16;
5097
+ const focusGuard = (() => {
5098
+ const sessions = new Map();
5099
+ const pairKey = (activePath, focusPath) => `${activePath}\u0000${focusPath}`;
5100
+ function stateOf(sessionId) {
5101
+ let state = sessions.get(sessionId);
5102
+ if (!state) {
5103
+ state = { pairs: new Set(), total: 0, notified: false };
5104
+ sessions.set(sessionId, state);
5105
+ if (sessions.size > FOCUS_SYNC_MAX_SESSIONS) {
5106
+ sessions.delete(sessions.keys().next().value);
5107
+ }
5108
+ }
5109
+ return state;
5110
+ }
5111
+ return {
5112
+ // 该「显示文档 vs AI 焦点」组合是否还允许自动发送。
5113
+ maySend(sessionId, activePath, focusPath) {
5114
+ const state = sessions.get(sessionId);
5115
+ if (!state) return true;
5116
+ if (state.total >= FOCUS_SYNC_SESSION_CAP) return false;
5117
+ return !state.pairs.has(pairKey(activePath, focusPath));
5118
+ },
5119
+ // 记一次已发送(成对记忆 + 总量计数)。
5120
+ record(sessionId, activePath, focusPath) {
5121
+ const state = stateOf(sessionId);
5122
+ state.pairs.add(pairKey(activePath, focusPath));
5123
+ state.total += 1;
5124
+ },
5125
+ // 是否需要向用户提示一次「已超上限静默停止」。
5126
+ shouldNotify(sessionId) {
5127
+ const state = sessions.get(sessionId);
5128
+ return Boolean(state && state.total >= FOCUS_SYNC_SESSION_CAP && !state.notified);
5129
+ },
5130
+ markNotified(sessionId) {
5131
+ const state = sessions.get(sessionId);
5132
+ if (state) state.notified = true;
5133
+ },
5134
+ clear() {
5135
+ sessions.clear();
5136
+ },
5137
+ };
5138
+ })();
5139
+ //#endregion
5140
+
5017
5141
  /**
5018
5142
  * settings describe 应答的双代信封解析(023):dsh ≤0.1.1 的远端把
5019
5143
  * 描述符聚合在 result.value.namespaces[];0.1.2-rc.1 起直接返回描述符
@@ -5404,6 +5528,9 @@ window.__ModuleLoader__.load({
5404
5528
  // 026 better-sidebar 共存:服务总线 + 会话数据桥 + Tab 壳(供测试)。
5405
5529
  sidebarBus,
5406
5530
  sessionStore,
5531
+ // issue #4 焦点同步防振荡:跨重挂载的成对防重 + 会话总量硬上限(供测试)。
5532
+ focusGuard,
5533
+ FOCUS_SYNC_SESSION_CAP,
5407
5534
  MindmapSidebarTab,
5408
5535
  // 027 内嵌头部视觉对齐:壳无关工作区组件 + 样式表(供测试验证 variant 分支)。
5409
5536
  MindmapWorkspace,
package/index.js CHANGED
@@ -14,8 +14,8 @@
14
14
  // 供模型续编辑,client 用同一份重放面板(工具结果即实时通道,002 第二节)。
15
15
  // - requireApproval 配置(决策 6):默认 true;approvalMode 默认按「当前会话 + 当前文件」
16
16
  // 首次确认,后续普通更新复用授权;per-operation 可恢复每次确认,off 关闭普通确认。
17
- // 宿主明确授予 danger-full-access 时普通写入不额外确认,不缓存成文档授权。
18
- // 重命名、清空和大范围重写始终重新确认,关闭普通确认也不能跳过。
17
+ // 宿主明确授予 danger-full-access 时所有脑图写入不额外确认,不缓存成文档授权。
18
+ // 非完全权限下,重命名、清空和大范围重写始终重新确认,关闭普通确认也不能跳过。
19
19
  // 015 起经 settings namespace 可运行时切换。
20
20
  // - 依赖:仅 @deepseek-ai/schemastery(settings schema;发布包正常解析,
21
21
  // link 开发需先 npm i)。工具参数 schema 仍手写 JSON Schema(003 偏差 1)。
@@ -131,8 +131,8 @@ function configValue(value) {
131
131
  }
132
132
 
133
133
  export const Config = Schema.object({
134
- requireApproval: Schema.boolean().default(true).description('Legacy switch: false skips ordinary confirmations only, and is lifted when the settings panel picks an explicit approval mode. Rename, clearing content, and broad rewrites always require approval.').extra('volatile', true),
135
- approvalMode: Schema.union([...APPROVAL_MODES, 'once-per-document', 'always']).default('session').description('Confirm every ordinary write, once per document in the current session, or disable ordinary confirmations. Explicit host danger-full-access skips ordinary confirmations. High-risk writes always require approval.').extra('volatile', true),
134
+ requireApproval: Schema.boolean().default(true).description('Legacy switch: false skips ordinary confirmations only, and is lifted when the settings panel picks an explicit approval mode. Rename, clearing content, and broad rewrites require approval unless the host explicitly grants danger-full-access.').extra('volatile', true),
135
+ approvalMode: Schema.union([...APPROVAL_MODES, 'once-per-document', 'always']).default('session').description('Confirm every ordinary write, once per document in the current session, or disable ordinary confirmations. Explicit host danger-full-access skips all plugin write confirmations, including rename, clearing content, and broad rewrites. Otherwise high-risk writes always require approval.').extra('volatile', true),
136
136
  defaultPanelWidth: Schema.number().default(42).description('Default floating-panel width as a percentage of the viewport (clamped 20-80 on the client).').extra('volatile', true),
137
137
  lineStyle: Schema.union(['curve', 'elbow']).default('elbow').description('Connector line style between nodes: curve (bezier) or elbow (orthogonal).').extra('volatile', true),
138
138
  cardStyle: Schema.union(['rounded', 'square']).default('rounded').description('Node card corner style.').extra('volatile', true),
@@ -185,7 +185,7 @@ Behavior rules:
185
185
  - Update step by step: whenever the request involves several parts, call mindmap_update as soon as each part is ready — several small updates beat one giant update at the end. The panel plays a growth animation on newly added/changed nodes, so step-by-step updates make the tree visibly grow while you work. Do not call mindmap_update twice in a row with identical content.
186
186
  - Never delete the whole document or restructure it without an explicit user request. Make the smallest change that answers the request.
187
187
  - When the user steps away or pauses (e.g. "我去买咖啡"), stop all mindmap edits immediately and wait — never continue autonomously.
188
- - Ordinary writes follow the host's live file policy: explicit \`danger-full-access\` skips the plugin's ordinary confirmations; otherwise native write approval defaults to once per document in the current session. \`per-operation\` asks for each ordinary write; \`off\` skips ordinary confirmations. Rename, clearing content, and broad rewrites still require confirmation in every mode. The current mindmap workspace shows and can revoke the current-session grants. If approval prompts are disabled, that is not permission to bypass a required confirmation; report the failure without claiming that the user personally clicked Reject. Never treat a rejected or failed write as approved.
188
+ - Writes follow the host's live file policy: explicit \`danger-full-access\` skips all of this plugin's write confirmations, including rename, clearing content, and broad rewrites. This does not bypass upstream approval decisions or path, collision, size, and revision checks. Without full file access, native write approval defaults to once per document in the current session; \`per-operation\` asks for each ordinary write and \`off\` skips ordinary confirmations, but rename, clearing content, and broad rewrites still require confirmation. The current mindmap workspace shows and can revoke the current-session grants. If approval prompts are disabled, that alone is not file permission and does not bypass a required confirmation; report the failure without claiming that the user personally clicked Reject. Never treat a rejected or failed write as approved.
189
189
  - Never run any git command for these files. The user commits themselves.
190
190
  - Mindmap files stay inside the session working directory.`
191
191
 
@@ -734,12 +734,14 @@ export function apply(ctx, config = {}) {
734
734
  // 完全权限预设同时关闭审批弹窗(never):额外返回 ask 会被宿主自动拒绝。
735
735
  // 只认公共 sandboxPolicy 对当前 session 的实时解析;never 本身不是授权。
736
736
  // 能力缺失、解析失败、未知模式或无会话时保留旧策略,不读部署默认值猜权限。
737
- const ordinaryApprovalModeOf = (session) => {
737
+ const approvalPolicyOf = (session) => {
738
738
  let mode = readApprovalMode()
739
+ let fullAccess = false
739
740
  if (session && typeof session === 'object') {
740
741
  try {
741
742
  const policy = ctx.get?.('sandboxPolicy')?.resolve?.({ session })
742
- if (policy?.mode === 'danger-full-access') mode = 'off'
743
+ fullAccess = policy?.mode === 'danger-full-access'
744
+ if (fullAccess) mode = 'off'
743
745
  } catch { /* 旧宿主或策略不可用时不新增免确认权限。 */ }
744
746
  const previous = effectiveApprovalModes.get(session)
745
747
  if (previous !== undefined && previous !== mode) {
@@ -748,7 +750,8 @@ export function apply(ctx, config = {}) {
748
750
  }
749
751
  effectiveApprovalModes.set(session, mode)
750
752
  }
751
- return mode
753
+ // 配置的 off 只免普通确认;宿主完全文件权限才免除高风险确认,不能混为一谈。
754
+ return { mode, fullAccess }
752
755
  }
753
756
  const stateOf = (session) => {
754
757
  if (!session || typeof session !== 'object') return null
@@ -760,7 +763,7 @@ export function apply(ctx, config = {}) {
760
763
  return state
761
764
  }
762
765
  const approvalStatusOf = (session) => {
763
- const mode = ordinaryApprovalModeOf(session)
766
+ const { mode } = approvalPolicyOf(session)
764
767
  const state = session && typeof session === 'object' ? approvedTargets.get(session) : null
765
768
  return { mode, grantedDocuments: state?.paths.size ?? 0 }
766
769
  }
@@ -846,9 +849,12 @@ export function apply(ctx, config = {}) {
846
849
  const args = exec.arguments ?? {}
847
850
  const session = sessionOf(exec)
848
851
  const target = await targetOf(exec)
852
+ const { mode, fullAccess } = approvalPolicyOf(session)
853
+ // 完全权限涵盖所有脑图写入;不请求宿主无法展示的额外确认,也不缓存授权。
854
+ // 只跳过本插件的确认,execute 中的路径、重名、大小与 revision 校验照常执行。
855
+ if (fullAccess) return decision
849
856
  const rename = exec.name === 'mindmap_update' && typeof args.renameRoot === 'string' && args.renameRoot.trim()
850
857
  const deleteDocument = exec.name === 'mindmap_update' && typeof args.content === 'string' && args.content.trim() === ''
851
- const mode = ordinaryApprovalModeOf(session)
852
858
  const broadRewrite = await needsRewriteApproval(exec, target, args.content)
853
859
  const highRisk = Boolean(rename || deleteDocument || broadRewrite)
854
860
  if (mode === 'off' && !highRisk) return decision
@@ -866,7 +872,7 @@ export function apply(ctx, config = {}) {
866
872
  const bytes = typeof args.content === 'string' ? byteLength(args.content) : 0
867
873
  return {
868
874
  kind: 'ask',
869
- reason: `${rename ? 'Rename and write' : deleteDocument ? 'Delete mindmap content' : broadRewrite ? 'Broad rewrite' : 'Write'} mindmap ${JSON.stringify(String(args.path ?? '?'))} (${bytes} bytes${renameNote}). ${highRisk ? 'This operation always requires confirmation.' : mode === 'per-operation' ? 'Confirm this write.' : 'Confirm once for this document in the current session.'}`,
875
+ reason: `${rename ? 'Rename and write' : deleteDocument ? 'Delete mindmap content' : broadRewrite ? 'Broad rewrite' : 'Write'} mindmap ${JSON.stringify(String(args.path ?? '?'))} (${bytes} bytes${renameNote}). ${highRisk ? 'Without host full file access, this operation requires confirmation.' : mode === 'per-operation' ? 'Confirm this write.' : 'Confirm once for this document in the current session.'}`,
870
876
  }
871
877
  })
872
878
 
@@ -878,7 +884,7 @@ export function apply(ctx, config = {}) {
878
884
  if (!pending) return
879
885
  pendingApprovals.delete(exec)
880
886
  if (result?.isError !== false || exec.signal?.aborted) return
881
- if (ordinaryApprovalModeOf(pending.session) !== 'session') return
887
+ if (approvalPolicyOf(pending.session).mode !== 'session') return
882
888
  // 撤销或策略切换之后,尚未结束的旧调用不能重新恢复授权。
883
889
  if (approvedTargets.get(pending.session) !== pending.state || pending.state.generation !== pending.generation) return
884
890
  // 审批后被抢注、实际写到了 -2 的情形:授权记真实路径,不记用户没见过的那条。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mindmap",
3
- "version": "0.18.3",
3
+ "version": "0.18.6",
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",