dsh-mindmap 0.11.0 → 0.12.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.
package/CHANGELOG.md CHANGED
@@ -6,8 +6,17 @@ All notable changes to this project are documented here. Release-specific notes
6
6
 
7
7
  ### Added
8
8
 
9
- - Better Sidebar native tab coexistence: when `dsh-better-sidebar` is installed, the mindmap registers as a single-instance tab (`dsh-mindmap:mindmap`) inside Better Sidebar instead of rendering its own floating panel. The in-tab toolbar is a single compact row (mindmap list, current mindmap, export button on the same line), labeled 脑图列表; the header 思维脑图 button opens or focuses the tab. When Better Sidebar is absent, the standalone floating panel with drag-resizable width and layout-push CSS remains unchanged (labeled 目录). `dsh-better-sidebar` is declared as an optional peer dependency — no duplicate instance is bundled. The mode switch is fully reversible via a `sidebarBus`-driven reversible effect: if Better Sidebar is unloaded mid-session, the standalone panel and layout-push CSS are restored automatically. A session-scoped data bridge (`sessionStore`) passes header-slot-captured `nodes`/`inputActions` to the tab component, with cleanup on session switch and component unmount.
10
- - Collapsible subtrees: every node with children shows a small toggle on its connector. Collapsing hides the subtree and reports how many nodes are hidden, which keeps large maps navigable. The state is view-only — the markdown file is untouched and image export still covers the full subtree. Collapsed nodes reset when the document changes, and stale ids are pruned after the AI rewrites the tree.
9
+ - Read-only document opening now renders a clicked Markdown file before asking the AI to take over editing. `mindmap_create` accepts an optional relative directory, and read/write results carry a SHA-256 revision so stale `mindmap_update` calls can be rejected instead of overwriting newer edits.
10
+ - Standalone panel width now remains usable on narrow viewports by clamping the initial, saved, resized, and settings-derived widths together.
11
+ - Write approval now supports `per-operation`, `session` (default), and `off` for ordinary writes. Session mode reuses a successful approval per document, while renames, empty-content deletions, and broad rewrites stay gated; the settings page exposes the policy and the current mindmap workspace shows and revokes the current-session grant.
12
+
13
+ ### Fixed
14
+
15
+ - Fixed a session-initialization race where an AI `mindmap_create` could expand the right-side tab but leave the workspace on the directory list. Session cleanup now runs before automatic document selection, and the opening-event cursor is reset when switching sessions.
16
+ - The broad-rewrite ratio check now applies only to documents of 4 KB or more, so rewriting a few-hundred-byte mindmap end to end no longer escalates to a fresh high-risk confirmation and the session grant stays usable. Renames, cleared content, and removed blocks above 16 KB remain gated.
17
+ - Choosing an explicit confirmation frequency in the settings page now lifts the legacy `requireApproval: false` switch. That switch takes precedence over `approvalMode` in the engine, so the previous behaviour saved the choice and then reverted it to `off`.
18
+
19
+ ## [0.11.0] - 2026-09-11
11
20
 
12
21
  ### Fixed
13
22
 
@@ -15,11 +24,33 @@ All notable changes to this project are documented here. Release-specific notes
15
24
  - Runtime verification on dsh 0.1.5-rc.1 with `dsh-better-sidebar` v0.18.1 confirms the plugin loads and renders in sidebar Tab mode: the MindmapSidebarTab registers, the mindmap settings panel (line style, card style, color theme, default width, growth animation), the directory tree tab, and the header 思维脑图 button all render and function correctly. A known timing issue causes the first directory-tree fetch to report "session has no working directory" on session switch (sessionStore write races the first fetch); clicking 刷新 restores it.
16
25
  - Sidebar auto-expand: clicking the header 思维脑图 button (or an AI `mindmap_create`/`open` auto-open) now automatically expands the Better Sidebar panel in addition to focusing the mindmap tab. Previously the tab activated but the panel stayed collapsed, requiring a manual "展开侧边栏" click. Root cause: `dsh-better-sidebar`'s `openTab(seed, scope)` only auto-expands the panel for "content-type" opens where the seed carries a `path` or `url` field (`service.ts:707`); a pure type-only open (`{ type: "dsh-mindmap:mindmap" }`) never expands. Fix: a new `openMindmapTab(svc, scope)` helper attaches an inert `url: "dsh-mindmap://mindmap"` to the seed, making it a content-type open. All three `openTab` call sites (header button click, MindmapSlot auto-open fallback, MindmapSidebarTab onAutoOpen) go through the helper. The `url` is not overwritten onto an already-existing tab (focus path), so there are no side effects; older BS versions without this logic degrade gracefully to the previous behavior (tab activates without panel expansion).
17
26
 
27
+ ## [0.10.1] - 2026-09-10
28
+
29
+ ### Added
30
+
31
+ - Better Sidebar native tab coexistence: when `dsh-better-sidebar` is installed, the mindmap registers as a single-instance tab (`dsh-mindmap:mindmap`) inside Better Sidebar instead of rendering its own floating panel. The in-tab toolbar is a single compact row (mindmap list, current mindmap, export button on the same line), labeled 脑图列表; the header 思维脑图 button opens or focuses the tab. When Better Sidebar is absent, the standalone floating panel with drag-resizable width and layout-push CSS remains unchanged (labeled 目录). `dsh-better-sidebar` is declared as an optional peer dependency — no duplicate instance is bundled. The mode switch is fully reversible via a `sidebarBus`-driven reversible effect: if Better Sidebar is unloaded mid-session, the standalone panel and layout-push CSS are restored automatically. A session-scoped data bridge (`sessionStore`) passes header-slot-captured `nodes`/`inputActions` to the tab component, with cleanup on session switch and component unmount.
32
+
33
+ ### Fixed
34
+
18
35
  - 内嵌 M 徽标增大至 16px、字母加粗,改为透明底与跟随文件名主题色的描边,改善换肤后的辨识度。
19
36
  - 内嵌模式的 Markdown 文件恢复为紧凑 M 徽标;其他格式文件仅展示,禁用悬停反馈、打开、拖拽与右键操作,文件夹仍可展开。
20
37
  - 内嵌 Better Sidebar 的列表与标签采用宿主字体角色(正文 14px、界面 12px),目录改用 14px 线框图标,修复字号继承偏大及标签字号混杂;独立模式和脑图节点排版不变。
38
+
39
+ ## [0.10.0] - 2026-09-09
40
+
41
+ ### Added
42
+
43
+ - Collapsible subtrees: every node with children shows a small toggle on its connector. Collapsing hides the subtree and reports how many nodes are hidden, which keeps large maps navigable. The state is view-only — the markdown file is untouched and image export still covers the full subtree. Collapsed nodes reset when the document changes, and stale ids are pruned after the AI rewrites the tree.
44
+
45
+ ### Fixed
46
+
21
47
  - 画布拖拽不再吞掉折叠开关等控件的点击。
22
48
  - 目录打开/焦点同步:宿主草稿 API 不可读时不再静默放弃;有非空草稿时指令转入剪贴板。
49
+
50
+ ## [0.9.0] - 2026-09-09
51
+
52
+ ### Fixed
53
+
23
54
  - Settings now wait for a late-arriving client connection instead of permanently capturing its initial absence. The client also supports direct settings descriptors and the current positional update API, while retaining the legacy envelopes.
24
55
  - Canvas dragging remains available horizontally and vertically when the map fits inside the viewport. Native scrolling is used first; bounded offset compensation continues the drag at an edge, and Fit or node focus returns the map to center.
25
56
  - Mindmap file access now fails closed when the session working directory is unavailable. Reads are limited during streaming rather than trusting a pre-read size check, and updates use a same-directory temporary file plus atomic replacement to avoid partial writes.
@@ -143,4 +174,4 @@ First release of dsh-mindmap: a plain Markdown file in the session working direc
143
174
 
144
175
  - Manual edits to a `.md` outside the AI tools are only picked up on the next AI `mindmap_*` touch of that file.
145
176
  - The panel is unavailable in a blank (no-session) state, since it lives in a session-scoped slot.
146
- - ~~Running two layout-push plugins (e.g. dsh-better-sidebar) with both panels open at once is a known boundary: both target `#root` and the later-injected rule wins.~~ Resolved in `[Unreleased]`: when Better Sidebar is installed, the mindmap registers as a native tab inside it and no longer writes its own layout-push CSS.
177
+ - ~~Running two layout-push plugins (e.g. dsh-better-sidebar) with both panels open at once is a known boundary: both target `#root` and the later-injected rule wins.~~ Resolved in `[0.10.1]`: when Better Sidebar is installed, the mindmap registers as a native tab inside it and no longer writes its own layout-push CSS.
package/README.md CHANGED
@@ -17,16 +17,16 @@ A DeepSeek Harness plugin that turns a plain Markdown file into a live mindmap.
17
17
 
18
18
  - **Four tools** (`mindmap_create` / `mindmap_open` / `mindmap_get` / `mindmap_update`) — plain Markdown files in the session working directory; the root node title is the filename and stays in sync both ways (`renameRoot` renames the file, collisions are rejected).
19
19
  - **Live panel with zero extra channels** — the panel consumes the session snapshot (`mindmap_*` tool results), so every AI edit re-renders immediately.
20
- - **Reliable open, recoverable loading state** — AI create/open results always expand the panel (a structural-fingerprint selector drives snapshot recomputation even when the host reuses the nodes array reference); after clicking a `.md` in the tree, the loading state recovers three ways: case-only path mismatches auto-merge (case-insensitive filesystems), tool errors show inline, and a ~30s watchdog switches to a timeout state — both failure states offer a one-click retry that re-sends the open request.
20
+ - **Reliable open, recoverable loading state** — AI create/open results always expand the panel (a structural-fingerprint selector drives snapshot recomputation even when the host reuses the nodes array reference); clicking a `.md` first reads it through the local read-only route, while AI fallback loading still recovers from case-only path mismatches, inline tool errors, and a ~30s watchdog timeout with one-click retry.
21
21
  - **Floating right panel or native sidebar tab** — when `dsh-better-sidebar` is installed, the mindmap registers as a native single-instance tab (`dsh-mindmap:mindmap`) inside Better Sidebar, with a compact one-row toolbar (mindmap list, current mindmap, and export on the same line); the header 思维脑图 button opens or focuses that tab. When Better Sidebar is absent, the panel falls back to a standalone floating right panel toggled by the 思维脑图 button — drag-resizable (280px ~ 80% viewport), persisted, and pushing the chat left (layout-push) so the two never overlap. AI create/open/view intents always open or focus the panel/tab and switch to the target document, including when it is currently closed or the same document is opened again. The mode switch is fully reversible: if Better Sidebar is unloaded mid-session, the standalone panel and layout-push CSS are restored automatically.
22
- - **Directory tree tab** — a persistent tree of the session working directory (served by a plugin-owned read-only route), lazy-loaded per directory; right-click to create a mindmap (at the root or inside a directory); left-click a `.md` to open it instantly and hand it to the AI for editing. Labeled 目录 in standalone mode and 脑图列表 in sidebar mode.
22
+ - **Directory tree tab** — a persistent tree of the session working directory (served by plugin-owned read-only routes), lazy-loaded per directory; right-click to create a mindmap at the root or inside a directory; left-click a `.md` renders it through the read-only route first, then hands it to the AI for editing when the draft is empty. Labeled 目录 in standalone mode and 脑图列表 in sidebar mode.
23
23
  - **Single-mindmap mode** — two tabs only: the tree/list tab and 脑图 (the current mindmap); opening another `.md` replaces the previous one.
24
24
  - **"What you see is what the AI edits"** — when the visible mindmap differs from the AI's working document, the panel automatically asks the AI to open it, keeping the chat focus in sync.
25
25
  - **MarkGrove-style mapping** — heading hierarchy, nested lists (empty items become placeholder nodes), code blocks as leaf nodes, paragraphs promoted to their own nodes (019 block concept), stable structural IDs, and orthogonal connector lines between nodes.
26
26
  - **Centered canvas with zoom and pan** — the mindmap opens centered in the canvas (scrollable without edge clipping when larger); a floating zoom bar at the canvas top-right (zoom out / percent / zoom in / fit) applies auto fit-to-view on open (small maps stay at 100%), steps through 25%–300% with a stable view center, and keeps re-fitting as the AI edits — until you zoom manually. Click any node to zoom in on it and its whole subtree, with the node pinned at the left-center of the canvas. The canvas also pans by drag: the **middle button** anywhere (even over a node), the **left button on blank canvas** (the Mac trackpad「click and drag」path), or **Space + left button** when the drag must start on a card. Panning works in both directions even when content does not overflow; content follows the pointer 1:1, blank space shows a grab hand, and a 4px threshold separates drag from click — so clicking blank space still clears the selection and clicking a node still focuses it, while a real drag never wipes the selection ring.
27
27
  - **Collapsible subtrees** — every node with children carries a small toggle on its connector: collapsing hides the whole subtree and reports how many nodes are hidden, so large maps stay navigable. It is view state only — the markdown file is untouched, image export still covers the full subtree, and switching documents expands everything again.
28
28
  - **PNG export** — one click on 导出图片 exports the current mindmap.
29
- - **Safety** — `mindmap_create` / `mindmap_update` require native approval by default. Automation can explicitly opt out with `requireApproval: false`; the client has **no write path** to the filesystem — every edit goes through the AI tools.
29
+ - **Safety** — write approval defaults to “once per session/document”: after the first confirmation, ordinary `mindmap_update` calls for that document in the same session do not interrupt the flow. The settings page also offers “every write” and “disable ordinary confirmations”. Renames, deletes, and broad rewrites still require a separate confirmation; the current workspace shows and can revoke the current-session grant. 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.
30
30
 
31
31
  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.
32
32
 
@@ -37,7 +37,7 @@ The embedded M badge uses a transparent background and inherits the filename's t
37
37
  | Component | Baseline |
38
38
  | --- | --- |
39
39
  | Node.js | 20.11 or newer |
40
- | DeepSeek Harness | tested against `0.1.1-rc.2` and `0.1.2-rc.1` |
40
+ | DeepSeek Harness | tested against `0.1.1-rc.2`, `0.1.2-rc.1`, and `0.1.5-rc.1` |
41
41
 
42
42
  ## Installation
43
43
 
@@ -57,10 +57,10 @@ dsh plugin --profile <profile> add <pkg>#v<version>
57
57
 
58
58
  | Tool | Description |
59
59
  | --- | --- |
60
- | `mindmap_create(name)` | Create `<name>.md` in the session working directory and show it in the panel (fails if it exists). |
60
+ | `mindmap_create(name, directory?)` | Create `<name>.md` in the session working directory or an optional relative directory and show it in the panel (fails if it exists). |
61
61
  | `mindmap_open(path)` | Open an existing `.md` as a mindmap in the panel. |
62
- | `mindmap_get(path)` | Read the current Markdown content of a mindmap document. |
63
- | `mindmap_update(path, content, renameRoot?)` | Write the full updated Markdown; optionally rename the root node (renames the file, collisions rejected). |
62
+ | `mindmap_get(path)` | Read the current Markdown content and revision of a mindmap document. |
63
+ | `mindmap_update(path, content, renameRoot?, expectedRevision?)` | Write the full Markdown; pass the read revision to reject stale writes; optionally rename the root node (renames the file, collisions rejected). |
64
64
 
65
65
  ## Development
66
66
 
package/README.zh-CN.md CHANGED
@@ -17,16 +17,16 @@
17
17
 
18
18
  - **四个工具**(`mindmap_create` / `mindmap_open` / `mindmap_get` / `mindmap_update`)——会话工作目录里的普通 `.md` 文件;根节点标题 = 文件名,双向同步(`renameRoot` 触发文件重命名,撞名报错不覆盖)。
19
19
  - **零通道实时面板**——面板直接消费会话快照里的 `mindmap_*` 工具结果,AI 每改一步面板即渲染一次。
20
- - **打开必达 + 加载态可恢复**——AI create/open 结果落地,面板必展开(节点结构指纹驱动快照重算,不受宿主数组引用稳定性影响);点目录树 `.md` 后的加载态有三条恢复路径:路径仅大小写不一致时自动匹配(大小写不敏感文件系统)、工具报错即时显示错误信息、约 30 秒无结果转超时提示——错误/超时态均带「重试」一键重发打开指令。
20
+ - **打开必达 + 加载态可恢复**——AI create/open 结果落地,面板必展开(节点结构指纹驱动快照重算,不受宿主数组引用稳定性影响);点目录树 `.md` 会先走本地只读路由直接显示,AI fallback 加载态仍支持大小写路径自动匹配、工具错误提示、约 30 秒超时和一键重试。
21
21
  - **原生侧栏 Tab 或右侧悬浮面板**——安装了 `dsh-better-sidebar` 时,脑图注册为 Better Sidebar 内的原生单实例 Tab(`dsh-mindmap:mindmap`),工具栏只有一行(脑图列表、当前脑图、导出图片在同一行);头部「思维脑图」按钮打开或聚焦该 Tab。未安装时回退为独立的右侧悬浮面板——会话头部按钮开合,宽度可拖(280px ~ 80% 视口)并持久化,打开时**聊天区向左让位**(布局推挤,互不遮挡)。AI 创建、打开或查看脑图时自动展开或聚焦面板/Tab 并切换到目标文档,即使当前收起或重复打开同一文档也能接续跟随。模式切换完全可逆:Better Sidebar 运行中卸载后,独立面板与布局推挤 CSS 自动恢复。
22
- - **常驻目录树 tab**——工作目录结构懒加载树(插件自建只读路由);空白处/目录右键新建脑图;左键点 `.md` 秒开 tab 并自动交给 AI 打开,随后直接对话继续编辑。独立面板模式标签为「目录」,侧栏模式标签为「脑图列表」。
22
+ - **常驻目录树 tab**——工作目录结构懒加载树(插件自建只读路由);空白处/目录右键新建脑图;左键点 `.md` 先通过只读路由直接显示,再在草稿为空时交给 AI 对话编辑。独立面板模式标签为「目录」,侧栏模式标签为「脑图列表」。
23
23
  - **单脑图模式**——面板只有树/列表和「脑图」两个 tab,打开新脑图替换旧的那颗。
24
24
  - **「所见即所编」焦点同步**——可见脑图与 AI 工作文档不一致时,面板自动让 AI 打开它,聊天焦点始终跟随你的眼睛。
25
25
  - **MarkGrove 同款映射与连线**——标题层级挂树、列表缩进(空项 = 占位节点)、代码块叶节点、段落升格为独立节点(019 块概念)、稳定结构 ID、节点间直角折线。
26
26
  - **画布居中、缩放与平移**——脑图打开后居中呈现(超出画布时可滚动、无边缘裁剪);画布右上角浮动缩放条(缩小 / 比例 / 放大 / 适配),打开时自动适配合适比例(小图保持 100%),25%–300% 逐级缩放且视图中心不跳变,AI 编辑后持续自动再适配,直到你手动缩放。点击任意节点即可聚焦:节点滚到画布左侧居中,视图放大到它和整棵子树完整可见(上限 100%)。画布还能拖着走:**中键**随处拖(含节点上)、**空白处左键拖**(Mac 触控板「点按并拖移」)、或 **Space + 左键拖**(必须从节点上起手时);无论内容是否溢出都可横纵双向拖动,内容跟手 1:1,空白处呈抓手光标,4px 阈值把拖与点分开——点空白仍取消选中、点节点仍聚焦,真拖不会误清选中圈。
27
27
  - **子树折叠**——有子节点的节点在连线起点上带一个小开关:折叠后隐藏整棵子树并提示隐藏了多少节点,超大脑图也能逐层看。折叠只是视图状态,不改 markdown 文件,导出图片仍是完整子树;切换文档自动全部展开。
28
28
  - **PNG 导出**——面板右上角「导出图片」一键导出当前脑图。
29
- - **安全**——`mindmap_create`/`mindmap_update` 默认进入原生审批;可通过 `requireApproval: false` 为自动化场景明确关闭。客户端**没有任何写文件通道**,一切编辑都经 AI 工具。
29
+ - **安全**——写入确认默认采用“本会话一次”:同一会话内同一脑图首次写入确认后,后续普通 `mindmap_update` 不再重复弹窗;也可切换为“每次确认”或“关闭普通确认”。重命名、删除和大范围重写仍需单独确认;当前脑图工作区会显示并可撤销本会话授权。受信自动化可显式设置 `requireApproval: false` 关闭普通确认,但高风险写入仍需确认。客户端**没有任何写文件通道**,一切编辑都经 AI 工具。
30
30
 
31
31
  内嵌 Better Sidebar 时,脑图列表采用宿主的 14px 正文字体。Markdown 文件显示紧凑的 M 徽标,文件夹与其他文件使用 14px 线框图标;其他格式文件仅展示,没有悬停反馈、打开、拖拽或右键菜单,文件夹仍可展开。标签、操作按钮和提示采用宿主的 12px 字体角色。独立模式保留原有外观;脑图节点的字体层级、缩放和图片导出保持不变。
32
32
 
@@ -37,7 +37,7 @@
37
37
  | 组件 | 基线 |
38
38
  | --- | --- |
39
39
  | Node.js | 20.11 及以上 |
40
- | DeepSeek Harness | 实测于 `0.1.1-rc.2` 与 `0.1.2-rc.1` |
40
+ | DeepSeek Harness | 实测于 `0.1.1-rc.2`、`0.1.2-rc.1` 与 `0.1.5-rc.1` |
41
41
 
42
42
  ## 安装
43
43
 
@@ -57,10 +57,10 @@ dsh plugin --profile <profile> add <pkg>#v<version>
57
57
 
58
58
  | 工具 | 说明 |
59
59
  | --- | --- |
60
- | `mindmap_create(name)` | 在工作目录创建 `<name>.md` 并显示到面板(已存在则报错)。 |
60
+ | `mindmap_create(name, directory?)` | 在工作目录或指定相对目录创建 `<name>.md` 并显示到面板(已存在则报错)。 |
61
61
  | `mindmap_open(path)` | 把已有 `.md` 作为脑图打开到面板。 |
62
- | `mindmap_get(path)` | 读取脑图文档的当前 Markdown 内容。 |
63
- | `mindmap_update(path, content, renameRoot?)` | 写入完整的新 Markdown;可选重命名根节点(重命名文件,撞名拒绝)。 |
62
+ | `mindmap_get(path)` | 读取脑图文档的当前 Markdown 内容和 revision。 |
63
+ | `mindmap_update(path, content, renameRoot?, expectedRevision?)` | 写入完整的新 Markdown;带上读取时的 revision 可避免覆盖并发修改;可选重命名根节点(重命名文件,撞名拒绝)。 |
64
64
 
65
65
  ## 开发
66
66
 
package/client.js CHANGED
@@ -1442,7 +1442,7 @@ window.__ModuleLoader__.load({
1442
1442
  // 027 内嵌头部(sidebar 模式):BS 外层已有 Tab 头部,内嵌只保留一行
1443
1443
  // 紧凑工具栏——脑图列表标签 + 当前脑图标签 + 导出按钮(行尾)。
1444
1444
  // 上下内距比 standalone 的 header(12px 14px 0)更紧凑,行间距更小。
1445
- sbToolbar: { display: "flex", alignItems: "center", gap: "6px", padding: "6px 10px", boxSizing: "border-box", borderBottom: "1px solid var(--dsw-alias-border-l2)", flex: "none", minWidth: 0 },
1445
+ sbToolbar: { display: "flex", alignItems: "center", gap: "6px", padding: "6px 10px 7px", boxSizing: "border-box", borderBottom: "1px solid var(--dsw-alias-border-l2)", flex: "none", minWidth: 0 },
1446
1446
  // 紧凑标签:比 standalone 的 tab(3px 12px)更小,贴合单行工具栏。
1447
1447
  sbTab: { border: "none", background: "none", cursor: "pointer", padding: "2px 8px", lineHeight: "20px", borderRadius: "6px", font: "inherit", fontSize: "12px", color: "var(--dsw-alias-label-secondary)", whiteSpace: "nowrap", maxWidth: "120px", overflow: "hidden", textOverflow: "ellipsis", transition: "background 0.08s ease, color 0.08s ease" },
1448
1448
  sbTabActive: { background: "var(--dsw-alias-bg-layer-3)", color: "var(--dsw-alias-label-primary)" },
@@ -1502,7 +1502,7 @@ window.__ModuleLoader__.load({
1502
1502
  /**
1503
1503
  * 015 设置面板(settings.section 页面,root scope):读写 host 的
1504
1504
  * settings namespace "mindmap"。节点主题三件套(线/卡片/颜色)+ 面板宽度;
1505
- * requireApproval 按作者要求隐藏(功能保留,经 config/API 仍可设)。
1505
+ * 写入确认策略在这里可见;当前会话的授权状态由脑图工作区显示。
1506
1506
  */
1507
1507
  function SettingsPanel(props) {
1508
1508
  const { mindmapFace } = props;
@@ -1519,6 +1519,7 @@ window.__ModuleLoader__.load({
1519
1519
  if (!alive) return;
1520
1520
  if (v === null) setError("设置服务不可用:settings namespace 未注册或 connection 缺失");
1521
1521
  setValue({
1522
+ approvalMode: v && v.requireApproval === false ? "off" : v && ["per-operation", "session", "off"].includes(v.approvalMode) ? v.approvalMode : "session",
1522
1523
  lineStyle: v && v.lineStyle === "curve" ? "curve" : "elbow",
1523
1524
  cardStyle: v && v.cardStyle === "square" ? "square" : "rounded",
1524
1525
  colorTheme: v && COLOR_THEMES[v.colorTheme] ? v.colorTheme : "ocean",
@@ -1544,8 +1545,10 @@ window.__ModuleLoader__.load({
1544
1545
  await mindmapFace.updateSettings(patch);
1545
1546
  settingsBus.bump(); // 通知脑图面板重读主题(面板常驻,open 不变)
1546
1547
  setNotice("已保存");
1548
+ return true;
1547
1549
  } catch (err) {
1548
1550
  setError(String(err?.message ?? err));
1551
+ return false;
1549
1552
  } finally {
1550
1553
  setSaving(false);
1551
1554
  }
@@ -1569,7 +1572,6 @@ window.__ModuleLoader__.load({
1569
1572
  const commitWidth = () => {
1570
1573
  save({ defaultPanelWidth: value.defaultPanelWidth });
1571
1574
  };
1572
-
1573
1575
  return (0, react_jsx_runtime.jsxs)("div", { style: S.settingsWrap, children: [
1574
1576
  (0, react_jsx_runtime.jsx)("p", { style: S.settingsGroupTitle, children: "节点主题" }),
1575
1577
  (0, react_jsx_runtime.jsxs)("div", { style: S.settingsGroup, children: [
@@ -1643,6 +1645,24 @@ window.__ModuleLoader__.load({
1643
1645
  ] }),
1644
1646
  (0, react_jsx_runtime.jsx)("p", { style: S.settingsHint, children: "开启后,脑图每次更新的新增/变化节点会逐个渐显长出(总时长不超过 2 秒);关闭则整棵树立刻完整显示。" }),
1645
1647
  ] }),
1648
+ (0, react_jsx_runtime.jsx)("p", { style: S.settingsGroupTitle, children: "写入确认" }),
1649
+ (0, react_jsx_runtime.jsxs)("div", { style: S.settingsGroup, children: [
1650
+ (0, react_jsx_runtime.jsxs)("div", { style: S.settingsRow, children: [
1651
+ (0, react_jsx_runtime.jsx)("span", { style: S.settingsLabel, children: "确认频率" }),
1652
+ (0, react_jsx_runtime.jsx)(Segmented, {
1653
+ options: [
1654
+ { value: "per-operation", label: "每次确认" },
1655
+ { value: "session", label: "本会话一次" },
1656
+ { value: "off", label: "关闭普通确认" },
1657
+ ],
1658
+ value: value.approvalMode,
1659
+ disabled: saving,
1660
+ onChange: (v) => setField({ approvalMode: v }),
1661
+ }),
1662
+ ] }),
1663
+ (0, react_jsx_runtime.jsx)("p", { style: S.settingsHint, children: value.approvalMode === "session" ? "本会话首次写入当前脑图后,后续普通更新无需重复确认。切换文件或会话会重新确认。" : value.approvalMode === "off" ? "普通更新不再弹窗;重命名、删除和大范围重写仍需确认。" : "每次写入都会弹窗确认。" }),
1664
+ value.approvalMode === "session" ? (0, react_jsx_runtime.jsx)("p", { style: S.settingsHint, children: "授权状态显示在当前脑图工作区;可在那里撤销当前会话的普通写入授权。" }) : null,
1665
+ ] }),
1646
1666
  saving ? (0, react_jsx_runtime.jsx)("p", { style: S.settingsHint, children: "保存中…" }) : null,
1647
1667
  notice ? (0, react_jsx_runtime.jsx)("p", { style: S.settingsNotice, children: notice }) : null,
1648
1668
  error ? (0, react_jsx_runtime.jsx)("p", { style: S.settingsError, children: error }) : null,
@@ -2692,6 +2712,7 @@ window.__ModuleLoader__.load({
2692
2712
  // settings——面板常驻不卸载,光靠 visible 变化会漏掉「开着面板改设置」。
2693
2713
  const settingsStamp = react.useSyncExternalStore(settingsBus.subscribe, settingsBus.get);
2694
2714
  const [theme, setTheme] = react.useState({ lineStyle: "elbow", cardStyle: "rounded", colorTheme: "ocean", growthAnimation: true });
2715
+ const [approvalState, setApprovalState] = react.useState(null);
2695
2716
  react.useEffect(() => {
2696
2717
  if (!visible) return;
2697
2718
  if (!mindmapFace || typeof mindmapFace.readSettings !== "function") return;
@@ -2708,6 +2729,26 @@ window.__ModuleLoader__.load({
2708
2729
  // 读设置失败:保持当前主题
2709
2730
  });
2710
2731
  }, [visible, settingsStamp, mindmapFace]);
2732
+ react.useEffect(() => {
2733
+ let alive = true;
2734
+ setApprovalState(null);
2735
+ if (!visible || !sessionId || !mindmapFace || typeof mindmapFace.readApprovalStatus !== "function") return () => { alive = false; };
2736
+ mindmapFace.readApprovalStatus(sessionId).then((value) => {
2737
+ if (alive) setApprovalState(value);
2738
+ }).catch(() => {
2739
+ if (alive) setApprovalState(null);
2740
+ });
2741
+ return () => { alive = false; };
2742
+ }, [visible, sessionId, mindmapFace, settingsStamp, nodesVersion]);
2743
+ async function revokeApproval() {
2744
+ if (!sessionId || !mindmapFace || typeof mindmapFace.revokeApproval !== "function") return;
2745
+ try {
2746
+ const value = await mindmapFace.revokeApproval(sessionId);
2747
+ setApprovalState(value);
2748
+ } catch {
2749
+ // 撤销失败不改变当前状态,避免给出虚假的成功提示。
2750
+ }
2751
+ }
2711
2752
 
2712
2753
  // 013 目录树 tab:常驻第一个 tab(TREE_TAB 哨兵,永不与绝对路径撞名)。
2713
2754
  const TREE_TAB = "__tree__";
@@ -2784,27 +2825,15 @@ window.__ModuleLoader__.load({
2784
2825
  ? matchDocError(merged, doc.path, localErrorBaseRef.current)
2785
2826
  : null;
2786
2827
 
2787
- // AI 自动打开:create/open 代表用户明确的「创建 / 打开 / 查看」意图。
2788
- // 无论面板/Tab 当前是否可见,都拉起并切到这次意图对应的文档;首次挂载的
2789
- // 历史快照也照常显示最近一次打开的脑图,避免出现「AI 说已打开但面板没了」。
2790
- const seen = react.useRef(null);
2791
- react.useEffect(() => {
2792
- const targetPath = autoOpenTarget(merged, seen.current);
2793
- seen.current = openingEventKeys(merged);
2794
- if (targetPath) {
2795
- onAutoOpen();
2796
- setHiddenPath(null);
2797
- setCurrentPath(targetPath);
2798
- setView("mindmap");
2799
- }
2800
- }, [merged]);
2801
-
2802
2828
  // 013「所见即所编」焦点同步:AI 焦点 = 快照里最新工具结果的文档路径;
2803
2829
  // 脑图视图激活且其文档 ≠ 焦点时,仅在草稿为空时自动发送,让 AI
2804
2830
  // 跟上用户眼睛看的那颗脑图,又不覆盖用户正在编辑的消息。
2805
2831
  const focusPath = docs.order.length > 0 ? docs.order[docs.order.length - 1] : null;
2806
2832
  const focusSentRef = react.useRef(null);
2807
2833
  // 所有这些状态都属于会话,不得让 A 会话的在途打开/目录结果遗留到 B。
2834
+ // 这个 effect 必须先于自动打开 effect 声明:React 会按声明顺序运行同一轮
2835
+ // effect,否则清理会把刚自动选中的脑图又切回「目录」。
2836
+ const seen = react.useRef(null);
2808
2837
  react.useEffect(() => {
2809
2838
  setLocalDocs({});
2810
2839
  setCurrentPath(null);
@@ -2816,8 +2845,24 @@ window.__ModuleLoader__.load({
2816
2845
  setFilledHint("");
2817
2846
  localErrorBaseRef.current = null;
2818
2847
  focusSentRef.current = null;
2848
+ seen.current = null;
2819
2849
  prevIdsRef.current = { path: null, ids: null };
2820
2850
  }, [sessionId]);
2851
+
2852
+ // AI 自动打开:create/open 代表用户明确的「创建 / 打开 / 查看」意图。
2853
+ // 无论面板/Tab 当前是否可见,都拉起并切到这次意图对应的文档;首次挂载的
2854
+ // 历史快照也照常显示最近一次打开的脑图,避免出现「AI 说已打开但面板没了」。
2855
+ react.useEffect(() => {
2856
+ const targetPath = autoOpenTarget(merged, seen.current);
2857
+ seen.current = openingEventKeys(merged);
2858
+ if (targetPath) {
2859
+ onAutoOpen();
2860
+ setHiddenPath(null);
2861
+ setCurrentPath(targetPath);
2862
+ setView("mindmap");
2863
+ }
2864
+ }, [merged, sessionId]);
2865
+
2821
2866
  react.useEffect(() => {
2822
2867
  if (!visible) return; // 面板/Tab 不可见时不自动发消息
2823
2868
  if (!sessionId) return;
@@ -2893,26 +2938,14 @@ window.__ModuleLoader__.load({
2893
2938
  });
2894
2939
  }
2895
2940
 
2896
- // 左键点 .md(013 作者定稿):① tab 秒建(本地占位,不显示内容,body
2897
- // 显示加载动效);② 同时填「用 mindmap_open 打开 <rel>」并 submit 让 AI
2898
- // 就位——AI 工具结果到达后同 path 覆盖占位,节点才渲染;随后用户接着
2899
- // 说即可继续编辑(002 数据流不变:内容只来自 AI 工具结果)。
2900
- function openMindmap(entry) {
2941
+ // 左键点 .md:先通过只读 document 路由显示文件,再在草稿为空时提交
2942
+ // mindmap_open 让 AI 接管编辑;已有草稿永不被覆盖。
2943
+ async function openMindmap(entry) {
2901
2944
  const text = `用 mindmap_open 打开 ${relPathWithin(fsTree.cwd, entry.path, entry.name)}`;
2902
- // 有未发送草稿:不建占位、不抢输入框,改把指令交给用户自己发。
2903
- if (draftBlocked()) {
2904
- if (typeof navigator !== "undefined" && navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
2905
- navigator.clipboard.writeText(text).catch(() => {});
2906
- setFilledHint("检测到未发送的草稿,已保留;打开指令已复制到剪贴板,粘贴发送即可");
2907
- } else {
2908
- setFilledHint(`检测到未发送的草稿,已保留。请手动发送:${text}`);
2909
- }
2910
- return;
2911
- }
2912
2945
  // 016:记录点击时刻的错误基线(errorByPath 与 latestError 的全部
2913
2946
  // 事件键)——只有其后新出现的错误才归因本次打开,旧错误不打扰。
2914
2947
  localErrorBaseRef.current = errorEventKeys(merged);
2915
- // ① 本地占位:脑图 tab 立即切过去、内容为空(op:"local" 触发加载态);
2948
+ // ① 本地占位:脑图 tab 立即切过去,随后由只读路由填充内容;
2916
2949
  // 新打开的脑图替换旧的那颗(单脑图模式)。
2917
2950
  setHiddenPath(null);
2918
2951
  setCurrentPath(entry.path);
@@ -2928,19 +2961,34 @@ window.__ModuleLoader__.load({
2928
2961
  renamedFrom: null,
2929
2962
  },
2930
2963
  }));
2931
- // ② AI 就位:填指令并直接提交(失败降级剪贴板)。
2932
- if (submitChatCommand(text)) {
2933
- // 标记已发,避免焦点同步 effect 对同一路径重复发送。
2964
+ try {
2965
+ if (!mindmapFace || typeof mindmapFace.readDocument !== "function") throw new Error("只读文档能力不可用");
2966
+ const loaded = await mindmapFace.readDocument(sessionId, relPathWithin(fsTree.cwd, entry.path, entry.name));
2967
+ setLocalDocs((prev) => {
2968
+ const current = prev[entry.path];
2969
+ if (!current || current.op !== "local") return prev;
2970
+ return { ...prev, [entry.path]: { ...current, op: "local-read", content: String(loaded.content ?? ""), revision: loaded.revision ?? null } };
2971
+ });
2972
+ setFilledHint(`已直接打开「${entry.name}」;需要 AI 编辑时可继续发送打开指令`);
2973
+ } catch (error) {
2974
+ setLocalDocs((prev) => {
2975
+ const current = prev[entry.path];
2976
+ if (!current || current.op !== "local") return prev;
2977
+ return { ...prev, [entry.path]: { ...current, error: String(error?.message ?? error) } };
2978
+ });
2979
+ setFilledHint("直接读取失败,可重试或让 AI 打开该文件");
2980
+ }
2981
+ // ② 草稿为空时再让 AI 接管焦点;已有草稿绝不覆盖。
2982
+ if (!draftBlocked() && submitChatCommand(text)) {
2934
2983
  focusSentRef.current = entry.path;
2935
- setFilledHint(`已让 AI 打开「${entry.name}」,在聊天里继续说就能继续编辑`);
2936
2984
  return;
2937
2985
  }
2938
- if (typeof navigator !== "undefined" && navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
2939
- navigator.clipboard.writeText(text).catch(() => {});
2940
- setFilledHint("已复制指令到剪贴板,请粘贴到聊天输入框");
2941
- return;
2986
+ if (draftBlocked()) {
2987
+ if (typeof navigator !== "undefined" && navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
2988
+ navigator.clipboard.writeText(text).catch(() => {});
2989
+ setFilledHint("检测到未发送的草稿,文件已打开;打开指令已复制到剪贴板");
2990
+ } else setFilledHint(`文件已打开,请手动发送:${text}`);
2942
2991
  }
2943
- setFilledHint(text);
2944
2992
  }
2945
2993
 
2946
2994
  /** 016 加载态恢复:错误/超时后重试——重发打开指令并重启看门狗。 */
@@ -3194,9 +3242,12 @@ window.__ModuleLoader__.load({
3194
3242
  function renderLoading() {
3195
3243
  // 016 三态流转:加载中 →(错误 | 超时)——错误优先于超时;失败态
3196
3244
  // 提供「重试」一键重发打开指令(openMindmap 同款通路 + 降级链)。
3197
- const failed = Boolean(docError) || openTimedOut;
3245
+ const localReadError = doc && doc.op === "local" && doc.error ? doc.error : null;
3246
+ const failed = Boolean(docError || localReadError) || openTimedOut;
3198
3247
  const message = docError
3199
3248
  ? `AI 打开失败:${docError.message}`
3249
+ : localReadError
3250
+ ? `读取失败:${localReadError}`
3200
3251
  : openTimedOut
3201
3252
  ? "等待 AI 打开超时(约 30 秒无结果)"
3202
3253
  : "AI 正在打开脑图…";
@@ -3311,6 +3362,12 @@ window.__ModuleLoader__.load({
3311
3362
  const exportErrorSpan = exportError
3312
3363
  ? (0, react_jsx_runtime.jsx)("span", { style: { color: "var(--dsw-alias-label-error)", fontSize: "12px" }, children: exportError })
3313
3364
  : null;
3365
+ const approvalControls = approvalState && approvalState.mode === "session"
3366
+ ? (0, react_jsx_runtime.jsxs)("span", { style: { display: "inline-flex", alignItems: "center", gap: "6px", color: "var(--dsw-alias-label-tertiary)", fontSize: "12px" }, children: [
3367
+ (0, react_jsx_runtime.jsx)("span", { title: "授权按当前会话与脑图文件隔离", children: approvalState.grantedDocuments > 0 ? "本会话已允许写入" : "本会话尚未授权" }),
3368
+ (0, react_jsx_runtime.jsx)("button", { type: "button", style: S.action, disabled: approvalState.grantedDocuments === 0, onClick: revokeApproval, children: "撤销授权" }),
3369
+ ] })
3370
+ : null;
3314
3371
 
3315
3372
  // 027 目录/列表标签文案:sidebar 模式叫「脑图列表」,standalone 模式叫「目录」。
3316
3373
  const treeTabLabel = variant === "sidebar" ? "脑图列表" : "目录";
@@ -3363,6 +3420,7 @@ window.__ModuleLoader__.load({
3363
3420
  }, shown) : null,
3364
3421
  // 导出按钮 + 错误推到行尾。
3365
3422
  (0, react_jsx_runtime.jsx)("span", { style: S.spacer }),
3423
+ approvalControls,
3366
3424
  exportErrorSpan,
3367
3425
  exportBtn,
3368
3426
  ] }),
@@ -3398,6 +3456,7 @@ window.__ModuleLoader__.load({
3398
3456
  const wsHeaderChildren = [
3399
3457
  (0, react_jsx_runtime.jsxs)("div", { style: S.headerTop, children: [
3400
3458
  (0, react_jsx_runtime.jsx)("span", { style: S.spacer }),
3459
+ approvalControls,
3401
3460
  exportBtn,
3402
3461
  exportErrorSpan,
3403
3462
  // 关闭按钮:仅独立 fixed 壳提供 onClose(BS Tab 自带关闭)。
@@ -3500,17 +3559,21 @@ window.__ModuleLoader__.load({
3500
3559
  const [panelWidth, setPanelWidth] = react.useState(() => {
3501
3560
  try {
3502
3561
  const saved = Number(localStorage.getItem(WIDTH_KEY));
3503
- if (Number.isFinite(saved) && saved >= 280) return Math.min(saved, Math.round(window.innerWidth * 0.8));
3562
+ const max = Math.round(window.innerWidth * 0.8);
3563
+ const min = Math.min(280, max);
3564
+ if (Number.isFinite(saved)) return Math.min(max, Math.max(min, saved));
3504
3565
  } catch {
3505
3566
  // localStorage 不可用:走默认
3506
3567
  }
3507
- return Math.round(window.innerWidth * 0.42);
3568
+ const max = Math.round(window.innerWidth * 0.8);
3569
+ return Math.min(max, Math.max(Math.min(280, max), Math.round(window.innerWidth * 0.42)));
3508
3570
  });
3509
3571
  react.useEffect(() => {
3510
3572
  const clamp = () => {
3511
3573
  setPanelWidth((prev) => {
3512
3574
  const max = Math.round(window.innerWidth * 0.8);
3513
- return prev > max ? max : prev;
3575
+ const min = Math.min(280, max);
3576
+ return Math.min(max, Math.max(min, prev));
3514
3577
  });
3515
3578
  };
3516
3579
  clamp();
@@ -3529,7 +3592,9 @@ window.__ModuleLoader__.load({
3529
3592
  if (!mindmapFace || typeof mindmapFace.readSettings !== "function") return;
3530
3593
  mindmapFace.readSettings().then((v) => {
3531
3594
  const pct = v && typeof v.defaultPanelWidth === "number" ? Math.min(80, Math.max(20, v.defaultPanelWidth)) : 42;
3532
- const px = Math.round(window.innerWidth * pct / 100);
3595
+ const max = Math.round(window.innerWidth * 0.8);
3596
+ const min = Math.min(280, max);
3597
+ const px = Math.min(max, Math.max(min, Math.round(window.innerWidth * pct / 100)));
3533
3598
  setPanelWidth((prev) => (Math.abs(prev - px) < 2 ? prev : px));
3534
3599
  }).catch(() => {
3535
3600
  // 读设置失败:保持 42% 默认
@@ -3543,7 +3608,8 @@ window.__ModuleLoader__.load({
3543
3608
  const onMove = (ev) => {
3544
3609
  if (!dragStateRef.current) return;
3545
3610
  const max = Math.round(window.innerWidth * 0.8);
3546
- const next = Math.min(max, Math.max(280, dragStateRef.current.startWidth + (dragStateRef.current.startX - ev.clientX)));
3611
+ const min = Math.min(280, max);
3612
+ const next = Math.min(max, Math.max(min, dragStateRef.current.startWidth + (dragStateRef.current.startX - ev.clientX)));
3547
3613
  dragStateRef.current.latestWidth = next;
3548
3614
  setPanelWidth(next);
3549
3615
  };
@@ -4097,6 +4163,45 @@ window.__ModuleLoader__.load({
4097
4163
  }
4098
4164
  return parsed.value;
4099
4165
  };
4166
+ // Read-only fast path for directory clicks. Rendering a document must not
4167
+ // wait for a model turn just to fetch bytes; the empty-draft path may still
4168
+ // ask the AI to take over editing after the document is visible.
4169
+ face.readDocument = async (sessionId, path) => {
4170
+ const response = await fetch("/mindmap/api/document", {
4171
+ method: "POST",
4172
+ headers: { "content-type": "application/json" },
4173
+ body: JSON.stringify({ sessionId, path }),
4174
+ });
4175
+ const parsed = await response.json().catch(() => null);
4176
+ if (!response.ok || parsed === null || parsed.ok !== true || !parsed.value) {
4177
+ throw new Error(parsed?.error?.message ?? `HTTP ${response.status}`);
4178
+ }
4179
+ return parsed.value;
4180
+ };
4181
+ face.readApprovalStatus = async (sessionId) => {
4182
+ const response = await fetch("/mindmap/api/approval", {
4183
+ method: "POST",
4184
+ headers: { "content-type": "application/json" },
4185
+ body: JSON.stringify({ sessionId, action: "status" }),
4186
+ });
4187
+ const parsed = await response.json().catch(() => null);
4188
+ if (!response.ok || parsed === null || parsed.ok !== true || !parsed.value) {
4189
+ throw new Error(parsed?.error?.message ?? `HTTP ${response.status}`);
4190
+ }
4191
+ return parsed.value;
4192
+ };
4193
+ face.revokeApproval = async (sessionId) => {
4194
+ const response = await fetch("/mindmap/api/approval", {
4195
+ method: "POST",
4196
+ headers: { "content-type": "application/json" },
4197
+ body: JSON.stringify({ sessionId, action: "revoke" }),
4198
+ });
4199
+ const parsed = await response.json().catch(() => null);
4200
+ if (!response.ok || parsed === null || parsed.ok !== true || !parsed.value) {
4201
+ throw new Error(parsed?.error?.message ?? `HTTP ${response.status}`);
4202
+ }
4203
+ return parsed.value;
4204
+ };
4100
4205
 
4101
4206
  // 015 设置面板:connection/remote 在客户端插件启动后才可能就绪,不能在
4102
4207
  // apply 时捕获一次 undefined;每次读写前重新查取,服务晚到也能恢复。
@@ -4143,10 +4248,16 @@ window.__ModuleLoader__.load({
4143
4248
  if (!api) {
4144
4249
  throw new Error("settings service unavailable");
4145
4250
  }
4251
+ // 引擎侧 legacy 开关 requireApproval:false 等价于「关闭普通确认」,优先级
4252
+ // 高于 approvalMode。面板显式选择「每次确认」或「本会话一次」时同时解除
4253
+ // 它,否则该选择会被 host config 里的开关静默覆盖(保存后弹回 off)。
4254
+ const payload = patch && typeof patch === "object" && patch.approvalMode && patch.approvalMode !== "off"
4255
+ ? { ...patch, requireApproval: true }
4256
+ : patch;
4146
4257
  if (api.kind === "remote" || api.settings.update.length !== 1) {
4147
- await api.settings.update("mindmap", patch, undefined);
4258
+ await api.settings.update("mindmap", payload, undefined);
4148
4259
  } else {
4149
- await api.settings.update({ ns: "mindmap", patch });
4260
+ await api.settings.update({ ns: "mindmap", patch: payload });
4150
4261
  }
4151
4262
  };
4152
4263
 
package/index.js CHANGED
@@ -9,13 +9,14 @@
9
9
  // - 四工具都带 path/name 参数(决策 3:多脑图并存,作用于指定那颗)。
10
10
  // - 结果 JSON {ok, op, path, rootTitle, content, renamedFrom?}:content 全文
11
11
  // 供模型续编辑,client 用同一份重放面板(工具结果即实时通道,002 第二节)。
12
- // - requireApproval 配置(决策 6):默认 true;仅明确关闭时 mindmap_create 与
13
- // mindmap_update 可免原生 ask(tools/pre-execute,照 dsh-grafana 的钩子模式)。
14
- // 015 起经 settings namespace 可在设置面板运行时切换(见 SETTINGS_NAMESPACE/Config)。
12
+ // - requireApproval 配置(决策 6):默认 true;approvalMode 默认按「当前会话 + 当前文件」
13
+ // 首次确认,后续普通更新复用授权;per-operation 可恢复每次确认,off 关闭普通确认。
14
+ // 重命名、清空和大范围重写始终重新确认,关闭普通确认也不能跳过。
15
+ // 015 起经 settings namespace 可运行时切换。
15
16
  // - 依赖:仅 @deepseek-ai/schemastery(settings schema;发布包正常解析,
16
17
  // link 开发需先 npm i)。工具参数 schema 仍手写 JSON Schema(003 偏差 1)。
17
18
  import { access, open, opendir, realpath, rename, stat, unlink, writeFile } from 'node:fs/promises'
18
- import { randomUUID } from 'node:crypto'
19
+ import { createHash, randomUUID } from 'node:crypto'
19
20
  import { dirname, isAbsolute, join, relative, resolve as resolvePath, sep } from 'node:path'
20
21
  import Schema from '@deepseek-ai/schemastery'
21
22
 
@@ -23,11 +24,23 @@ export const name = 'mindmap'
23
24
  export const inject = ['tools', 'systemPrompt', 'webServer', 'sessions']
24
25
 
25
26
  // 015 设置面板:settings namespace(dsh-grafana 同款模式)。
26
- // requireApproval 在 pre-execute 时读当前值(运行时切换即时生效);
27
+ // requireApproval / approvalMode 在 pre-execute 时读当前值(运行时切换即时生效);
27
28
  // defaultPanelWidth 供客户端面板取默认宽度(20-80 钳制由客户端执行)。
28
29
  export const SETTINGS_NAMESPACE = 'mindmap'
30
+ const APPROVAL_MODES = ['per-operation', 'session', 'off']
31
+
32
+ /** Normalize the public three-mode policy while accepting the previous names. */
33
+ function normalizeApprovalMode(value, requireApproval = true) {
34
+ if (requireApproval === false) return 'off'
35
+ if (value === 'per-operation' || value === 'always') return 'per-operation'
36
+ if (value === 'off') return 'off'
37
+ if (value === 'session' || value === 'once-per-document') return 'session'
38
+ return 'session'
39
+ }
40
+
29
41
  export const Config = Schema.object({
30
- requireApproval: Schema.boolean().default(true).description('Require native DSH approval for every mindmap_create and mindmap_update (including renameRoot). Enabled by default and hidden from the settings panel; still honored at runtime.'),
42
+ 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.'),
43
+ 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. High-risk writes always require approval.'),
31
44
  defaultPanelWidth: Schema.number().default(42).description('Default floating-panel width as a percentage of the viewport (clamped 20-80 on the client).'),
32
45
  lineStyle: Schema.union(['curve', 'elbow']).default('elbow').description('Connector line style between nodes: curve (bezier) or elbow (orthogonal).'),
33
46
  cardStyle: Schema.union(['rounded', 'square']).default('rounded').description('Node card corner style.'),
@@ -41,25 +54,30 @@ const MAX_NAME_CHARS = 80
41
54
  const TOOL_TIMEOUT_MS = 15_000
42
55
  const MAX_TREE_ENTRIES = 500
43
56
  const MAX_BODY_BYTES = 1 << 20
57
+ const BROAD_REWRITE_MIN_BYTES = 16 * 1024
58
+ // 比例判定只对足够大的文档生效:几百字节的脑图整体改写不算「大范围重写」,
59
+ // 否则小文档的每次更新都会被升级成高风险确认,会话授权形同虚设。
60
+ const BROAD_REWRITE_RATIO_MIN_BYTES = 4 * 1024
44
61
 
45
62
  const GUIDANCE = `## Mindmap editing (dsh-mindmap)
46
63
 
47
64
  A mindmap is a plain markdown file in the session working directory. The right-side panel renders it live; the filename (without .md) is the root node title. These files are ordinary documents: the user reviews and commits them with git themselves.
48
65
 
49
66
  Tools:
50
- - mindmap_create(name): create <name>.md in the working directory (fails if it exists) and show it in the panel.
67
+ - mindmap_create(name, directory?): create <name>.md in the working directory or the selected relative directory (fails if it exists) and show it in the panel.
51
68
  - mindmap_open(path): open an existing .md as a mindmap in the panel.
52
69
  - mindmap_get(path): read the current markdown content.
53
- - mindmap_update(path, content, renameRoot?): write the FULL updated markdown. renameRoot renames the file to match a new root title (fails on name collision); use it only when the user asks to rename the root node.
70
+ - mindmap_update(path, content, renameRoot?, expectedRevision?): write the FULL updated markdown. Pass the revision returned by mindmap_get/open when editing; a mismatch stops the write instead of overwriting newer changes. renameRoot renames the file to match a new root title (fails on name collision); use it only when the user asks to rename the root node.
54
71
 
55
- Markdown mapping (the panel's parser): headings nest by level (H1 are root children, H2 under the previous H1, ...); list items are child nodes nested by 2-space indentation; a list item with no text after the marker renders as a placeholder node (both "-" and "- " work; no trailing space is required) — use placeholders for planned-but-unwritten nodes; a fenced code block becomes a leaf node titled "[lang] first line"; plain paragraphs become the note text of the nearest heading.
72
+ Markdown mapping (the panel's parser): headings nest by level (H1 are root children, H2 under the previous H1, ...); list items are child nodes nested by 2-space indentation; a list item with no text after the marker renders as a placeholder node (both "-" and "- " work; no trailing space is required) — use placeholders for planned-but-unwritten nodes; a fenced code block becomes a leaf node titled "[lang] first line"; plain paragraphs become their own text/Markdown block nodes under the nearest heading.
56
73
 
57
74
  Behavior rules:
58
75
  - When the user asks to create a mindmap, call mindmap_create. When the user asks to open, view, show, or switch to an existing mindmap, call mindmap_open (do not use mindmap_get alone). Both operations bring that document to the visible mindmap panel automatically.
59
- - Always mindmap_get before editing, then send the complete updated document to mindmap_update. Every call must carry the FULL document, never a fragment.
76
+ - Always mindmap_get before editing, then send the complete updated document and the returned revision as expectedRevision to mindmap_update. If the tool reports a revision conflict, stop and ask the user whether to reload or merge; never overwrite newer text silently. Every call must carry the FULL document, never a fragment.
60
77
  - 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.
61
78
  - Never delete the whole document or restructure it without an explicit user request. Make the smallest change that answers the request.
62
79
  - When the user steps away or pauses (e.g. "我去买咖啡"), stop all mindmap edits immediately and wait — never continue autonomously.
80
+ - Native write approval defaults to once per document in the current session, so step-by-step updates stay fluid after the first confirmation. \`per-operation\` asks every time; \`off\` skips ordinary confirmations. A new document, a new session, or renameRoot requires a fresh confirmation. The current mindmap workspace shows and can revoke the current-session grants. Never treat a rejected or failed write as approved.
63
81
  - Never run any git command for these files. The user commits themselves.
64
82
  - Mindmap files stay inside the session working directory.`
65
83
 
@@ -290,6 +308,25 @@ function byteLength(value) {
290
308
  return new TextEncoder().encode(value).byteLength
291
309
  }
292
310
 
311
+ /** Stable document revision shared by read and write tool results. */
312
+ function revisionOfContent(value) {
313
+ return createHash('sha256').update(String(value ?? ''), 'utf8').digest('hex')
314
+ }
315
+
316
+ /** 保守比较公共首尾之间被替换的旧文本;纯增量插入不算重写。 */
317
+ function isBroadRewrite(before, after) {
318
+ if (!before || before === after) return false
319
+ let prefix = 0
320
+ const limit = Math.min(before.length, after.length)
321
+ while (prefix < limit && before[prefix] === after[prefix]) prefix += 1
322
+ let suffix = 0
323
+ while (suffix < limit - prefix && before[before.length - 1 - suffix] === after[after.length - 1 - suffix]) suffix += 1
324
+ const beforeBytes = byteLength(before)
325
+ const removedBytes = byteLength(before.slice(prefix, before.length - suffix))
326
+ if (removedBytes >= BROAD_REWRITE_MIN_BYTES) return true
327
+ return beforeBytes >= BROAD_REWRITE_RATIO_MIN_BYTES && removedBytes / beforeBytes >= 0.5
328
+ }
329
+
293
330
  /**
294
331
  * mindmap_open / mindmap_get 共用的有界读取。句柄打开后持续分块读取,文件在
295
332
  * 初检后增长也不会绕过上限;非常规文件直接拒绝。
@@ -357,6 +394,7 @@ export function apply(ctx, config = {}) {
357
394
  // 透传(带 schema 同款默认值),用户设置层仍可在设置面板覆盖。
358
395
  const entryConfig = {
359
396
  requireApproval: config.requireApproval !== false,
397
+ approvalMode: normalizeApprovalMode(config.approvalMode, config.requireApproval !== false),
360
398
  defaultPanelWidth: typeof config.defaultPanelWidth === 'number' ? config.defaultPanelWidth : 42,
361
399
  lineStyle: config.lineStyle === 'curve' ? 'curve' : 'elbow',
362
400
  cardStyle: config.cardStyle === 'square' ? 'square' : 'rounded',
@@ -379,37 +417,139 @@ export function apply(ctx, config = {}) {
379
417
 
380
418
  ctx.systemPrompt.section({ name: 'tool:mindmap', order: 106, text: GUIDANCE })
381
419
 
382
- // 后悔药开关(决策 6):钩子常驻注册,运行时读 activeConfig().requireApproval
383
- // ——设置面板切换立即生效;仅明确关闭时直接放行。
384
- // 022:create 同为写路径,一并纳入审批(CONTRIBUTING:所有写路径安全敏感)。
420
+ // 写入授权按 session + canonical document path 缓存;只在 tools/result 确认
421
+ // 成功后写入,拒绝、失败或取消都不会消耗授权。WeakMap 随 session 生命周期
422
+ // 自然释放,不把授权带到别的会话。
423
+ let approvedTargets = new WeakMap()
424
+ const pendingApprovals = new WeakMap()
425
+ let lastMode
426
+ const readApprovalMode = () => {
427
+ const value = activeConfig()
428
+ const mode = normalizeApprovalMode(value.approvalMode, value.requireApproval)
429
+ if (mode !== lastMode) {
430
+ approvedTargets = new WeakMap()
431
+ lastMode = mode
432
+ }
433
+ return mode
434
+ }
435
+ const stateOf = (session) => {
436
+ if (!session || typeof session !== 'object') return null
437
+ let state = approvedTargets.get(session)
438
+ if (!state) {
439
+ state = { paths: new Set(), generation: 0 }
440
+ approvedTargets.set(session, state)
441
+ }
442
+ return state
443
+ }
444
+ const approvalStatusOf = (session) => {
445
+ const state = session && typeof session === 'object' ? approvedTargets.get(session) : null
446
+ return { mode: readApprovalMode(), grantedDocuments: state?.paths.size ?? 0 }
447
+ }
448
+ const revokeApproval = (session) => {
449
+ if (!session || typeof session !== 'object') return approvalStatusOf(session)
450
+ const state = stateOf(session)
451
+ state.paths.clear()
452
+ state.generation += 1
453
+ return approvalStatusOf(session)
454
+ }
455
+ const sessionOf = (exec) => {
456
+ const direct = exec?.agent?.session
457
+ if (direct) return direct
458
+ const id = exec?.agent?.id
459
+ return id && ctx.sessions?.get ? ctx.sessions.get(id) ?? null : null
460
+ }
461
+ const targetOf = async (exec) => {
462
+ const args = exec.arguments ?? {}
463
+ const cwd = sessionCwd(exec, ctx.sessions)
464
+ let raw
465
+ if (exec.name === 'mindmap_create') {
466
+ try {
467
+ const stem = sanitizeStem(args.name)
468
+ const directory = typeof args.directory === 'string' && args.directory.trim() ? args.directory.trim() : ''
469
+ raw = join(directory, `${stem}.md`)
470
+ } catch {
471
+ // Let the tool return its normal argument error; approval lookup must
472
+ // never turn malformed input into a hook-level exception.
473
+ raw = typeof args.name === 'string' ? args.name.trim() : '?'
474
+ }
475
+ } else {
476
+ raw = typeof args.path === 'string' ? args.path.trim() : ''
477
+ }
478
+ if (cwd && raw) {
479
+ try { return await resolveMindmapPath(cwd, raw) } catch { /* 工具本身负责报告参数错误 */ }
480
+ }
481
+ return `${exec.name}:${raw || '?'}`
482
+ }
483
+
484
+ const needsRewriteApproval = async (exec, target, content) => {
485
+ if (exec.name !== 'mindmap_update' || typeof content !== 'string') return false
486
+ // 缺少会话工作目录或参数尚未解析时,交给工具本身报告参数错误;不要让
487
+ // 审批钩子把普通的兼容关闭误判成高风险写入。
488
+ if (!isAbsolute(target)) return false
489
+ if (byteLength(content) > MAX_CONTENT_BYTES) return true
490
+ try {
491
+ const before = await readMindmap(target)
492
+ return isBroadRewrite(before, content)
493
+ } catch (error) {
494
+ if (error?.code === 'ENOENT') return false
495
+ // 无法判断风险时不复用授权;具体读取错误仍由工具报告。
496
+ return true
497
+ }
498
+ }
499
+
500
+ // 022:create 同为写路径,一并纳入审批;高风险 renameRoot 不复用普通授权。
385
501
  ctx.on('tools/pre-execute', async (exec, next) => {
386
502
  const decision = await next()
387
503
  if (decision.kind !== 'allow') return decision
388
- if (!activeConfig().requireApproval) return decision
504
+ if (exec.name !== 'mindmap_create' && exec.name !== 'mindmap_update') return decision
505
+ const args = exec.arguments ?? {}
506
+ const session = sessionOf(exec)
507
+ const target = await targetOf(exec)
508
+ const rename = exec.name === 'mindmap_update' && typeof args.renameRoot === 'string' && args.renameRoot.trim()
509
+ const deleteDocument = exec.name === 'mindmap_update' && typeof args.content === 'string' && args.content.trim() === ''
510
+ const mode = readApprovalMode()
511
+ const broadRewrite = await needsRewriteApproval(exec, target, args.content)
512
+ const highRisk = Boolean(rename || deleteDocument || broadRewrite)
513
+ const state = stateOf(session)
514
+ if (mode === 'off' && !highRisk) return decision
515
+ if (mode === 'session' && !highRisk && state?.paths.has(target)) return decision
516
+ if (mode === 'session' && !highRisk && state) pendingApprovals.set(exec, { session, target, state, generation: state.generation })
389
517
  if (exec.name === 'mindmap_create') {
390
- const args = exec.arguments ?? {}
391
518
  return {
392
519
  kind: 'ask',
393
- reason: `Create mindmap ${JSON.stringify(String(args.name ?? '?'))}. dsh-mindmap is configured with requireApproval.`,
520
+ reason: `Create mindmap ${JSON.stringify(String(args.name ?? '?'))} at ${JSON.stringify(target)}. ${mode === 'per-operation' ? 'Confirm this write.' : 'Confirm once for this document in the current session.'}`,
394
521
  }
395
522
  }
396
- if (exec.name !== 'mindmap_update') return decision
397
- const args = exec.arguments ?? {}
398
- const renameNote = typeof args.renameRoot === 'string' && args.renameRoot ? `, rename root to "${args.renameRoot}"` : ''
523
+ const renameNote = rename ? `, rename root to "${args.renameRoot}"` : ''
399
524
  const bytes = typeof args.content === 'string' ? byteLength(args.content) : 0
400
525
  return {
401
526
  kind: 'ask',
402
- reason: `Write mindmap ${JSON.stringify(String(args.path ?? '?'))} (${bytes} bytes${renameNote}). dsh-mindmap is configured with requireApproval.`,
527
+ 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.'}`,
403
528
  }
404
529
  })
405
530
 
531
+ // Mark the document only after the authoritative result is successful. The
532
+ // listener sees the same frozen execution object as pre-execute, so rejected,
533
+ // cancelled, and failed writes never grant future writes.
534
+ ctx.on('tools/result', (exec, result) => {
535
+ const pending = pendingApprovals.get(exec)
536
+ if (!pending) return
537
+ pendingApprovals.delete(exec)
538
+ if (result?.isError !== false || exec.signal?.aborted) return
539
+ if (readApprovalMode() !== 'session') return
540
+ // 撤销或策略切换之后,尚未结束的旧调用不能重新恢复授权。
541
+ if (approvedTargets.get(pending.session) !== pending.state || pending.state.generation !== pending.generation) return
542
+ pending.state.paths.add(pending.target)
543
+ })
544
+
406
545
  ctx.tools.register(defineTool({
407
546
  name: 'mindmap_create',
408
- description: 'Create a new mindmap markdown file <name>.md in the session working directory and show it in the mindmap panel. Fails if the file already exists. The filename becomes the root node title.',
547
+ description: 'Create a new mindmap markdown file <name>.md in the session working directory or an optional relative directory and show it in the mindmap panel. Fails if the file already exists. The filename becomes the root node title.',
409
548
  parameters: {
410
549
  type: 'object',
411
550
  properties: {
412
551
  name: { type: 'string', description: 'Mindmap document name (without .md). Becomes the filename and the root node title.' },
552
+ directory: { type: 'string', description: 'Optional directory relative to the session working directory. Use this when creating from a directory tree.' },
413
553
  },
414
554
  required: ['name'],
415
555
  },
@@ -419,7 +559,8 @@ export function apply(ctx, config = {}) {
419
559
  const cwd = sessionCwd(exec, ctx.sessions)
420
560
  if (!cwd) throw new Error('The session has no working directory; cannot create a mindmap.')
421
561
  const stem = sanitizeStem(args?.name)
422
- const path = await resolveMindmapPath(cwd, `${stem}.md`)
562
+ const directory = typeof args?.directory === 'string' && args.directory.trim() ? args.directory.trim() : ''
563
+ const path = await resolveMindmapPath(cwd, join(directory, `${stem}.md`))
423
564
  // wx = 不存在才创建:原子拒绝已存在(含并发竞态)与同名目录,无 TOCTOU 窗口。
424
565
  try {
425
566
  await writeFile(path, '', { encoding: 'utf8', flag: 'wx' })
@@ -429,7 +570,7 @@ export function apply(ctx, config = {}) {
429
570
  }
430
571
  throw error
431
572
  }
432
- return buildResult('create', path, { content: '', created: true })
573
+ return buildResult('create', path, { content: '', created: true, revision: revisionOfContent('') })
433
574
  },
434
575
  }))
435
576
 
@@ -448,7 +589,7 @@ export function apply(ctx, config = {}) {
448
589
  async execute(args, exec) {
449
590
  const path = await resolveMindmapPath(sessionCwd(exec, ctx.sessions), args?.path)
450
591
  const content = await readMindmap(path)
451
- return buildResult('open', path, { content })
592
+ return buildResult('open', path, { content, revision: revisionOfContent(content) })
452
593
  },
453
594
  }))
454
595
 
@@ -467,7 +608,7 @@ export function apply(ctx, config = {}) {
467
608
  async execute(args, exec) {
468
609
  const path = await resolveMindmapPath(sessionCwd(exec, ctx.sessions), args?.path)
469
610
  const content = await readMindmap(path)
470
- return buildResult('get', path, { content })
611
+ return buildResult('get', path, { content, revision: revisionOfContent(content) })
471
612
  },
472
613
  }))
473
614
 
@@ -480,6 +621,7 @@ export function apply(ctx, config = {}) {
480
621
  path: { type: 'string', description: 'Path to the .md file, relative to the session working directory or absolute.' },
481
622
  content: { type: 'string', description: 'The complete new markdown content of the document.' },
482
623
  renameRoot: { type: 'string', description: 'Optional new root title: renames the file to <renameRoot>.md. Only when the user asks to rename the root node.' },
624
+ expectedRevision: { type: 'string', description: 'Optional revision returned by mindmap_get or mindmap_open. The write is rejected if the file changed since that read.' },
483
625
  },
484
626
  required: ['path'],
485
627
  },
@@ -496,6 +638,14 @@ export function apply(ctx, config = {}) {
496
638
  throw new Error(`mindmap content exceeds the ${MAX_CONTENT_BYTES}-byte limit.`)
497
639
  }
498
640
  if (!(await pathExists(path))) throw new Error(`Mindmap not found: ${JSON.stringify(path)}. Create it with mindmap_create first.`)
641
+ const expectedRevision = typeof args?.expectedRevision === 'string' && args.expectedRevision ? args.expectedRevision : null
642
+ if (expectedRevision) {
643
+ const currentContent = await readMindmap(path)
644
+ const currentRevision = revisionOfContent(currentContent)
645
+ if (currentRevision !== expectedRevision) {
646
+ throw new Error(`Mindmap changed since it was read (expected ${expectedRevision}, found ${currentRevision}). Reload it before writing.`)
647
+ }
648
+ }
499
649
 
500
650
  let finalPath = path
501
651
  let renamedFrom
@@ -517,7 +667,7 @@ export function apply(ctx, config = {}) {
517
667
  }
518
668
  if (hasContent) await writeMindmap(finalPath, args.content)
519
669
  const content = hasContent ? args.content : await readMindmap(finalPath)
520
- return buildResult('update', finalPath, { content, ...(renamedFrom ? { renamedFrom } : {}) })
670
+ return buildResult('update', finalPath, { content, revision: revisionOfContent(content), ...(renamedFrom ? { renamedFrom } : {}) })
521
671
  },
522
672
  }))
523
673
 
@@ -539,7 +689,7 @@ export function apply(ctx, config = {}) {
539
689
  }
540
690
  try {
541
691
  const method = new URL(req.url ?? '/', 'http://dsh.internal').pathname.slice('/mindmap/api/'.length)
542
- if (method !== 'tree') {
692
+ if (method !== 'tree' && method !== 'document' && method !== 'approval') {
543
693
  sendJson(res, 404, { ok: false, error: { code: 'not-found', message: `unknown mindmap API method ${JSON.stringify(method)}` } })
544
694
  return
545
695
  }
@@ -549,11 +699,27 @@ export function apply(ctx, config = {}) {
549
699
  sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: 'missing or invalid "sessionId"' } })
550
700
  return
551
701
  }
702
+ if (method === 'approval') {
703
+ const session = ctx.sessions?.get?.(sessionId)
704
+ if (!session) {
705
+ sendJson(res, 400, { ok: false, error: { code: 'unknown-session', message: 'unknown session' } })
706
+ return
707
+ }
708
+ const value = payload.action === 'revoke' ? revokeApproval(session) : approvalStatusOf(session)
709
+ sendJson(res, 200, { ok: true, value })
710
+ return
711
+ }
552
712
  const cwd = sessionCwdOf(ctx.sessions, sessionId)
553
713
  if (!cwd) {
554
714
  sendJson(res, 400, { ok: false, error: { code: 'no-cwd', message: 'session has no working directory' } })
555
715
  return
556
716
  }
717
+ if (method === 'document') {
718
+ const path = await resolveMindmapPath(cwd, payload.path)
719
+ const content = await readMindmap(path)
720
+ sendJson(res, 200, { ok: true, value: { path, content, revision: revisionOfContent(content) } })
721
+ return
722
+ }
557
723
  const dir = await resolveTreePath(cwd, payload.path)
558
724
  const listing = await listDirectoryLevel(dir)
559
725
  sendJson(res, 200, { ok: true, value: { ...listing, cwd } })
@@ -573,6 +739,8 @@ export function apply(ctx, config = {}) {
573
739
 
574
740
  export const internals = Object.freeze({
575
741
  GUIDANCE,
742
+ APPROVAL_MODES,
743
+ normalizeApprovalMode,
576
744
  MAX_CONTENT_BYTES,
577
745
  MAX_READ_BYTES,
578
746
  readMindmap,
@@ -585,4 +753,5 @@ export const internals = Object.freeze({
585
753
  listDirectoryLevel,
586
754
  isTrustedRequest,
587
755
  buildResult,
756
+ revisionOfContent,
588
757
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mindmap",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
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",