dsh-mindmap 0.13.0 → 0.13.1
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 +8 -0
- package/README.md +17 -2
- package/README.zh-CN.md +17 -2
- package/client.js +32 -5
- package/index.js +238 -29
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,9 @@ All notable changes to this project are documented here. Release-specific notes
|
|
|
6
6
|
|
|
7
7
|
### Added
|
|
8
8
|
|
|
9
|
+
- Default mindmap inbox and naming (036): a request without a location ("创建一个脑图", "把刚才的讨论整理成脑图", "盘点一下这个问题") now files the document in `.mindmaps/` as `YYYYMMDD-HHmmss-中文描述.md` instead of dropping it on top of the session working directory root. `mindmap_create` takes `name` when the user named the mindmap and a short `description` otherwise — the host reads the clock, so the model never guesses a time. Descriptions are whitespace-collapsed, truncated to 24 characters, and rejected outright when they carry path separators or control characters. `.mindmaps/` is created on first use (a same-named ordinary file, a symlinked-out directory, and a missing session cwd all fail closed), is never added to `.gitignore`, and shows in the directory tree as 脑图收件箱(.mindmaps) with the root/blank-space context menu offering 在脑图收件箱新建脑图. An explicit `directory` is still honoured verbatim, and the approval hook now computes the final normalized path before the first write, so a fresh inbox creation still goes through the normal confirmation. The root node title keeps equaling the filename, so a default-created mindmap temporarily shows its timestamp as the root title; splitting filename from display title is left as a separate decision.
|
|
10
|
+
- Approval and write now agree on one path (036 follow-up): the confirmation prompt resolves the first free `-2`/`-3` candidate before the user is asked, instead of naming a file a previous same-second capture had already taken and then silently writing a sibling. If another create claims the confirmed name during the deliberation window, the host steps to the next free suffix, the tool result reports that final path, and the session grant is recorded against it rather than the stale candidate — so an existing file is never overwritten and a confirmation never buys a write nobody was shown. Concurrent default creates are verified end to end: eight same-description creates launched in parallel produce eight distinct documents with no lost bytes.
|
|
11
|
+
|
|
9
12
|
- Node search and quick navigation: ⌘/Ctrl+F (or the 🔍 in the canvas zoom bar) opens a compact search over the current mindmap — case-insensitive substring matching on node text, a `1 / 5` counter, and Enter / ↓ / ↑ (Shift+Enter) stepping through matches with wrap-around. Every match gets a light theme-token ring and the active match a stronger double ring; jumping keeps the user's zoom, scrolls the match to the focus anchor, and auto-expands collapsed ancestors so hits inside folded subtrees are actually revealed. Search is pure view state (no markdown writes, no revision changes), reconciles on stable node ids after an AI re-render, and resets on document switch; the ⌘/Ctrl+F interception only fires while the mindmap canvas is active and never while the caret sits in another text entry.
|
|
10
13
|
|
|
11
14
|
- Canvas focus experience: clicking a node now animates the zoom/scroll transition (≤250 ms, eased) and caps each click's zoom change at ×2/÷2, so focusing into a huge map drills down progressively instead of jumping 4× in one step. The transition interpolates the node's viewport anchor from its clicked position to the left-quarter focus point (no first-frame jump), and animation frames are written directly to the canvas DOM layer without re-rendering the tree per frame. Any new interaction (drag, zoom buttons, another click) interrupts the animation instantly, and the animation self-disables for the session once the resize-observer circuit breaker trips, falling back to the previous instant behavior. When an AI edit pushes the selected node fully out of view, the canvas performs a minimal scroll to bring it back to the edge without touching the user's chosen zoom.
|
|
@@ -15,8 +18,13 @@ All notable changes to this project are documented here. Release-specific notes
|
|
|
15
18
|
- Standalone panel width now remains usable on narrow viewports by clamping the initial, saved, resized, and settings-derived widths together.
|
|
16
19
|
- 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.
|
|
17
20
|
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- `mindmap_create` without `directory` no longer writes to the root of the session working directory: the file goes into the `.mindmaps/` inbox (see above). Existing documents stay exactly where they are — only new creations move.
|
|
24
|
+
|
|
18
25
|
### Fixed
|
|
19
26
|
|
|
27
|
+
- Creating a mindmap re-checks its target against the filesystem immediately before the write (036 follow-up, P1). The path was validated when the confirmation was drawn, but the plan was then trusted as-is: renaming the target directory and replacing it with a symlink pointing outside the session working directory while the user was reading the confirmation made `mindmap_create` write the file outside the workspace. Every candidate — inbox or explicit directory — is now re-resolved through the same inside-the-cwd check right before its atomic `wx` create; a path that no longer resolves inside the session cwd aborts the create (no outside file, no session grant), and the user is asked to start it again. The path confirmed and the path written stay the same one.
|
|
20
28
|
- 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.
|
|
21
29
|
- 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.
|
|
22
30
|
- 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`.
|
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ A DeepSeek Harness plugin that turns a plain Markdown file into a live mindmap.
|
|
|
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
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 plugin-owned read-only routes), lazy-loaded per directory; right-click to create a mindmap
|
|
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 in the inbox 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.
|
|
@@ -34,6 +34,21 @@ Inside Better Sidebar, the mindmap list uses the host's 14px body typography. Ma
|
|
|
34
34
|
|
|
35
35
|
The embedded M badge uses a transparent background and inherits the filename's theme color for both its bold letter and outline, so it follows light/dark themes and custom skins without relying on accent-color contrast.
|
|
36
36
|
|
|
37
|
+
## Where new mindmaps go
|
|
38
|
+
|
|
39
|
+
When you ask for a mindmap without naming a location — "创建一个脑图", "把刚才的讨论整理成脑图", "盘点一下这个问题" — the file lands in **`.mindmaps/`**, the mindmap inbox:
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
.mindmaps/20260918-155230-项目盘点.md
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- The `YYYYMMDD-HHmmss` stamp is read by the host from the real clock; the model only supplies the short description (cleaned and truncated to 24 characters). Two captures in the same second get `-2`, `-3`, … suffixes — an existing file is never overwritten, and the write-confirmation names the exact file it is about to create.
|
|
46
|
+
- The path is checked twice: once when the confirmation is drawn, and again against the filesystem right before the write. If the target directory moved or was swapped for a symlink while you were reading the confirmation, the create is refused instead of writing outside the session working directory.
|
|
47
|
+
- `.mindmaps/` is created on first use, not at install time. The directory tree shows it as **脑图收件箱(.mindmaps)**, because a dotted folder otherwise reads as tool residue.
|
|
48
|
+
- Nothing is added to `.gitignore` for you. A mindmap stays an ordinary Markdown file: review it, diff it, commit it, or move it somewhere permanent.
|
|
49
|
+
- Say the location instead and it is respected: `docs/架构脑图.md`, `planning/迭代计划.md`, or right-click a folder in the tree and choose 在此目录新建 Markdown 脑图. An explicit directory is never rewritten into the inbox (and still has to stay inside the session working directory).
|
|
50
|
+
- Because the root node title *is* the filename, a default-created mindmap shows its own timestamp as the root title for now. Splitting filename from display title is a separate decision, so rename the root when you want a clean title.
|
|
51
|
+
|
|
37
52
|
## Requirements
|
|
38
53
|
|
|
39
54
|
| Component | Baseline |
|
|
@@ -59,7 +74,7 @@ dsh plugin --profile <profile> add <pkg>#v<version>
|
|
|
59
74
|
|
|
60
75
|
| Tool | Description |
|
|
61
76
|
| --- | --- |
|
|
62
|
-
| `mindmap_create(name, directory?)` | Create `<name>.md`
|
|
77
|
+
| `mindmap_create(name? \| description, directory?)` | Create a mindmap and show it in the panel (fails if the file already exists). With `name`, the file is `<name>.md`; without it, pass a short `description` and the host names the file `YYYYMMDD-HHmmss-<description>.md` inside the `.mindmaps/` inbox. Pass `directory` only when the user chose a location. |
|
|
63
78
|
| `mindmap_open(path)` | Open an existing `.md` as a mindmap in the panel. |
|
|
64
79
|
| `mindmap_get(path)` | Read the current Markdown content and revision of a mindmap document. |
|
|
65
80
|
| `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). |
|
package/README.zh-CN.md
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
- **零通道实时面板**——面板直接消费会话快照里的 `mindmap_*` 工具结果,AI 每改一步面板即渲染一次。
|
|
20
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
|
|
22
|
+
- **常驻目录树 tab**——工作目录结构懒加载树(插件自建只读路由);空白处右键新建到脑图收件箱、目录右键新建到该目录;左键点 `.md` 先通过只读路由直接显示,再在草稿为空时交给 AI 对话编辑。独立面板模式标签为「目录」,侧栏模式标签为「脑图列表」。
|
|
23
23
|
- **单脑图模式**——面板只有树/列表和「脑图」两个 tab,打开新脑图替换旧的那颗。
|
|
24
24
|
- **「所见即所编」焦点同步**——可见脑图与 AI 工作文档不一致时,面板自动让 AI 打开它,聊天焦点始终跟随你的眼睛。
|
|
25
25
|
- **MarkGrove 同款映射与连线**——标题层级挂树、列表缩进(空项 = 占位节点)、代码块叶节点、段落升格为独立节点(019 块概念)、稳定结构 ID、节点间直角折线。
|
|
@@ -34,6 +34,21 @@
|
|
|
34
34
|
|
|
35
35
|
内嵌 M 徽标采用透明底、粗体字母与细描边,字母和边框跟随文件名的主题文字颜色;浅色、深色及自定义皮肤切换时同步适配,不依赖品牌色与底色的对比。
|
|
36
36
|
|
|
37
|
+
## 新建的脑图放在哪
|
|
38
|
+
|
|
39
|
+
你说「创建一个脑图」「把刚才的讨论整理成脑图」「盘点一下这个问题」这类没点目录的请求时,文件落在 **`.mindmaps/`**——脑图收件箱:
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
.mindmaps/20260918-155230-项目盘点.md
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- `YYYYMMDD-HHmmss` 由 host 读本机时钟生成,模型只给那句短描述(按文件名安全规则清理,最长 24 字)。同一秒撞名依次加 `-2`、`-3` 后缀,**已有文件永不被覆盖**;写入确认框里报出的就是它准备创建的那条路径。
|
|
46
|
+
- 路径校验走两遍:画确认框时一遍,真正落盘前再按当前文件系统核一遍。你还在读确认框时目标目录被改名、或被换成指向工作区外的符号链接,本次创建直接失败,绝不会把文件写到会话工作目录外面。
|
|
47
|
+
- `.mindmaps/` 第一次需要时才建,不在安装时预生成。目录树里它显示为 **「脑图收件箱(.mindmaps)」**,免得点号目录被当成工具残留以为内容看不见。
|
|
48
|
+
- 不替你写 `.gitignore`。脑图仍是普通 Markdown:可以审阅、diff、提交,也可以挪去正式目录。
|
|
49
|
+
- 你点了位置就尊重位置:`docs/架构脑图.md`、`planning/迭代计划.md`,或在目录树上右键选「在此目录新建 Markdown 脑图」。显式目录不会被改判进收件箱,且照样受会话工作目录边界与符号链接越界校验约束。
|
|
50
|
+
- 根节点标题 = 文件名,所以默认新建的脑图暂时会把时间戳显示成根标题。把「文件名」和「显示标题」拆开是独立需求,想要干净标题就用 `renameRoot` 改名(会同步重命名文件)。
|
|
51
|
+
|
|
37
52
|
## 环境要求
|
|
38
53
|
|
|
39
54
|
| 组件 | 基线 |
|
|
@@ -59,7 +74,7 @@ dsh plugin --profile <profile> add <pkg>#v<version>
|
|
|
59
74
|
|
|
60
75
|
| 工具 | 说明 |
|
|
61
76
|
| --- | --- |
|
|
62
|
-
| `mindmap_create(name, directory?)` |
|
|
77
|
+
| `mindmap_create(name? \| description, directory?)` | 新建脑图并显示到面板(文件已存在则报错)。给了 `name` 就建 `<name>.md`;没给就传一句短 `description`,由 host 命名成 `.mindmaps/YYYYMMDD-HHmmss-<description>.md`。只有用户点了位置才传 `directory`。 |
|
|
63
78
|
| `mindmap_open(path)` | 把已有 `.md` 作为脑图打开到面板。 |
|
|
64
79
|
| `mindmap_get(path)` | 读取脑图文档的当前 Markdown 内容和 revision。 |
|
|
65
80
|
| `mindmap_update(path, content, renameRoot?, expectedRevision?)` | 写入完整的新 Markdown;带上读取时的 revision 可避免覆盖并发修改;可选重命名根节点(重命名文件,撞名拒绝)。 |
|
package/client.js
CHANGED
|
@@ -974,6 +974,29 @@ window.__ModuleLoader__.load({
|
|
|
974
974
|
}
|
|
975
975
|
//#endregion
|
|
976
976
|
|
|
977
|
+
//#region 036 脑图收件箱:默认目录的显示文案与新建入口(纯函数)
|
|
978
|
+
const DEFAULT_MINDMAP_DIR = ".mindmaps";
|
|
979
|
+
const DEFAULT_MINDMAP_DIR_LABEL = "脑图收件箱(.mindmaps)";
|
|
980
|
+
|
|
981
|
+
/** 目录树显示名:点号目录看着像工具残留,收件箱给一句人话(真实路径仍在 title 上)。 */
|
|
982
|
+
function treeDirLabel(name) {
|
|
983
|
+
const raw = String(name ?? "");
|
|
984
|
+
return raw === DEFAULT_MINDMAP_DIR ? DEFAULT_MINDMAP_DIR_LABEL : raw;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
/** 新建入口文案:有目录上下文就写进那个目录,没有才交给默认收件箱。 */
|
|
988
|
+
function treeCreateDraft(relDirectory) {
|
|
989
|
+
const dir = String(relDirectory ?? "").trim();
|
|
990
|
+
return dir
|
|
991
|
+
? `我想在 ${dir} 目录里创建一个 Markdown 脑图`
|
|
992
|
+
: `我想新建一个脑图,按默认命名放进 ${DEFAULT_MINDMAP_DIR} 脑图收件箱`;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
function treeCreateLabel(relDirectory) {
|
|
996
|
+
return String(relDirectory ?? "").trim() ? "在此目录新建 Markdown 脑图" : "在脑图收件箱新建脑图";
|
|
997
|
+
}
|
|
998
|
+
//#endregion
|
|
999
|
+
|
|
977
1000
|
//#region 025 草稿保护:能力探测(宿主是否让插件读到聊天草稿)
|
|
978
1001
|
/**
|
|
979
1002
|
* 读取当前聊天草稿。宿主契约只保证 setDraft/submit,读取面属可选能力:
|
|
@@ -3661,9 +3684,10 @@ window.__ModuleLoader__.load({
|
|
|
3661
3684
|
});
|
|
3662
3685
|
}
|
|
3663
3686
|
function directoryLabel(name, expanded) {
|
|
3687
|
+
const label = treeDirLabel(name);
|
|
3664
3688
|
return (0, react_jsx_runtime.jsx)("span", {
|
|
3665
3689
|
style: { flex: "0 1 auto", overflow: "hidden", textOverflow: "ellipsis", minWidth: 0 },
|
|
3666
|
-
children: variant === "sidebar" ?
|
|
3690
|
+
children: variant === "sidebar" ? label : `${expanded ? "📂" : "📁"} ${label}`,
|
|
3667
3691
|
});
|
|
3668
3692
|
}
|
|
3669
3693
|
function blockFileInteraction(event) {
|
|
@@ -3894,11 +3918,9 @@ window.__ModuleLoader__.load({
|
|
|
3894
3918
|
style: S.treeMenuItem,
|
|
3895
3919
|
onClick: () => {
|
|
3896
3920
|
setTreeMenu(null);
|
|
3897
|
-
fillDraft(treeMenu.
|
|
3898
|
-
? `我想在 ${treeMenu.rel} 目录里创建一个 Markdown 脑图`
|
|
3899
|
-
: "我想创建一个脑图");
|
|
3921
|
+
fillDraft(treeCreateDraft(treeMenu.rel));
|
|
3900
3922
|
},
|
|
3901
|
-
children: treeMenu.
|
|
3923
|
+
children: treeCreateLabel(treeMenu.rel),
|
|
3902
3924
|
}),
|
|
3903
3925
|
],
|
|
3904
3926
|
}) : null,
|
|
@@ -4886,6 +4908,11 @@ window.__ModuleLoader__.load({
|
|
|
4886
4908
|
planGrowthReveal,
|
|
4887
4909
|
relPathWithin,
|
|
4888
4910
|
visibleTreeRows,
|
|
4911
|
+
// 036 脑图收件箱:默认目录的显示文案与新建入口(供测试)。
|
|
4912
|
+
DEFAULT_MINDMAP_DIR,
|
|
4913
|
+
treeDirLabel,
|
|
4914
|
+
treeCreateDraft,
|
|
4915
|
+
treeCreateLabel,
|
|
4889
4916
|
// 025 草稿保护:宿主草稿读取面的能力探测(供测试)。
|
|
4890
4917
|
readDraftText,
|
|
4891
4918
|
draftBlocksAutoSend,
|
package/index.js
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
// - 根节点标题 = 文档名(决策 2):renameRoot 触发文件重命名,撞名报错不覆盖;
|
|
8
8
|
// 文件被外部改名时根标题由 client 从路径推导,天然跟随。
|
|
9
9
|
// - 四工具都带 path/name 参数(决策 3:多脑图并存,作用于指定那颗)。
|
|
10
|
+
// - 036 默认落点:用户没指定目录的随手创建进 `.mindmaps/` 脑图收件箱,
|
|
11
|
+
// 名字 `YYYYMMDD-HHmmss-中文描述.md`——时间戳由 host 读表(模型不猜时间),
|
|
12
|
+
// 描述由 AI 给。收件箱按需创建、不进 .gitignore,同秒撞名加 -2/-3 不覆盖。
|
|
10
13
|
// - 结果 JSON {ok, op, path, rootTitle, content, renamedFrom?}:content 全文
|
|
11
14
|
// 供模型续编辑,client 用同一份重放面板(工具结果即实时通道,002 第二节)。
|
|
12
15
|
// - requireApproval 配置(决策 6):默认 true;approvalMode 默认按「当前会话 + 当前文件」
|
|
@@ -15,7 +18,7 @@
|
|
|
15
18
|
// 015 起经 settings namespace 可运行时切换。
|
|
16
19
|
// - 依赖:仅 @deepseek-ai/schemastery(settings schema;发布包正常解析,
|
|
17
20
|
// link 开发需先 npm i)。工具参数 schema 仍手写 JSON Schema(003 偏差 1)。
|
|
18
|
-
import { access, open, opendir, realpath, rename, stat, unlink, writeFile } from 'node:fs/promises'
|
|
21
|
+
import { access, mkdir, open, opendir, realpath, rename, stat, unlink, writeFile } from 'node:fs/promises'
|
|
19
22
|
import { createHash, randomUUID } from 'node:crypto'
|
|
20
23
|
import { dirname, isAbsolute, join, relative, resolve as resolvePath, sep } from 'node:path'
|
|
21
24
|
import Schema from '@deepseek-ai/schemastery'
|
|
@@ -58,13 +61,20 @@ const BROAD_REWRITE_MIN_BYTES = 16 * 1024
|
|
|
58
61
|
// 比例判定只对足够大的文档生效:几百字节的脑图整体改写不算「大范围重写」,
|
|
59
62
|
// 否则小文档的每次更新都会被升级成高风险确认,会话授权形同虚设。
|
|
60
63
|
const BROAD_REWRITE_RATIO_MIN_BYTES = 4 * 1024
|
|
64
|
+
// 036 默认脑图收件箱:用户没指定目录时的落点。目录只在第一次需要时按需创建,
|
|
65
|
+
// 也不自动进 .gitignore——脑图仍是普通 Markdown,用户可以审阅、diff、提交。
|
|
66
|
+
export const DEFAULT_MINDMAP_DIR = '.mindmaps'
|
|
67
|
+
// 描述只占默认名的一段,上限留足时间戳(15)与连接符的余量后仍远低于 MAX_NAME_CHARS。
|
|
68
|
+
const MAX_DESCRIPTION_CHARS = 24
|
|
69
|
+
// 同一秒同名(默认命名)时的后缀尝试次数上限。
|
|
70
|
+
const MAX_CREATE_ATTEMPTS = 50
|
|
61
71
|
|
|
62
72
|
const GUIDANCE = `## Mindmap editing (dsh-mindmap)
|
|
63
73
|
|
|
64
74
|
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.
|
|
65
75
|
|
|
66
76
|
Tools:
|
|
67
|
-
- mindmap_create(name, directory?): create
|
|
77
|
+
- mindmap_create(name? | description, directory?): create a mindmap and show it in the panel (fails if the file already exists). Give \`name\` when the user named the mindmap; otherwise give a short \`description\` and the host names the file \`YYYYMMDD-HHmmss-<description>.md\`. Give \`directory\` only when the user picked a location.
|
|
68
78
|
- mindmap_open(path): open an existing .md as a mindmap in the panel.
|
|
69
79
|
- mindmap_get(path): read the current markdown content.
|
|
70
80
|
- 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.
|
|
@@ -72,6 +82,9 @@ Tools:
|
|
|
72
82
|
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.
|
|
73
83
|
|
|
74
84
|
Behavior rules:
|
|
85
|
+
- Where new files go: for casual requests ("创建一个脑图", "把刚才的讨论整理成脑图", "盘点一下这个问题") omit \`directory\` — the host files them in \`${DEFAULT_MINDMAP_DIR}/\`, the mindmap inbox, created on first use. That is the only location the plugin ever chooses on its own: when the user names a directory (or right-clicks one in the tree), pass that \`directory\` and leave their placement alone.
|
|
86
|
+
- Never write a date or time into a mindmap filename yourself. Pass a bare \`description\` (e.g. 项目盘点) and the host stamps the real current time, then takes the first free name (\`-2\`, \`-3\`, …) so an existing file is never overwritten. The path the user confirms is the path it writes; if another create claims that name while the confirmation is pending, the host steps to the next free suffix and reports the final path in the tool result — relay that path to the user rather than assuming the one they confirmed.
|
|
87
|
+
- Because the root node title is the filename, a default-created mindmap shows its timestamp as the root title (e.g. 20260918-155230-项目盘点). Rename it with renameRoot only when the user asks; do not restructure the document to hide the stamp.
|
|
75
88
|
- 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.
|
|
76
89
|
- 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.
|
|
77
90
|
- 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.
|
|
@@ -262,6 +275,61 @@ function sanitizeStem(input) {
|
|
|
262
275
|
return stem
|
|
263
276
|
}
|
|
264
277
|
|
|
278
|
+
/** 本地时间 → `YYYYMMDD-HHmmss`。时间只由 host 读表,绝不交给模型猜。 */
|
|
279
|
+
function timestampStamp(date) {
|
|
280
|
+
const pad = (value, width = 2) => String(value).padStart(width, '0')
|
|
281
|
+
return `${pad(date.getFullYear(), 4)}${pad(date.getMonth() + 1)}${pad(date.getDate())}-${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}`
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* AI 描述 → 默认名的描述段:折叠空白、按 sanitizeStem 同款安全规则拒绝越界字符、
|
|
286
|
+
* 截断到 MAX_DESCRIPTION_CHARS。清理后为空(含只剩点号)一律拒绝,不静默造怪文件名。
|
|
287
|
+
*/
|
|
288
|
+
function sanitizeDescription(input) {
|
|
289
|
+
const raw = String(input ?? '').replace(/\s+/g, ' ').trim().replace(/\.+$/, '')
|
|
290
|
+
if (!raw) throw new Error('mindmap description must not be empty.')
|
|
291
|
+
if (/[\\/:*?"<>|]/.test(raw)) throw new Error(`Invalid mindmap description ${JSON.stringify(input)}: path separators and :*?"<>| are not allowed.`)
|
|
292
|
+
// eslint-disable-next-line no-control-regex
|
|
293
|
+
if (/[\u0000-\u001f]/.test(raw)) throw new Error('Invalid mindmap description: control characters are not allowed.')
|
|
294
|
+
const chars = [...raw]
|
|
295
|
+
return chars.length > MAX_DESCRIPTION_CHARS ? chars.slice(0, MAX_DESCRIPTION_CHARS).join('') : raw
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** 默认脑图主干:`YYYYMMDD-HHmmss-中文描述`(例 20260918-155230-项目盘点)。 */
|
|
299
|
+
function defaultStem(date, description) {
|
|
300
|
+
return `${timestampStamp(date)}-${sanitizeDescription(description)}`
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** create 参数里的显式目录(去空白);缺省 = 走默认收件箱。 */
|
|
304
|
+
function explicitDirectory(args) {
|
|
305
|
+
return typeof args?.directory === 'string' && args.directory.trim() ? args.directory.trim() : ''
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* 一次 create 的路径计划——纯计算,不落盘,因此可以安全地在审批钩子里调用。
|
|
310
|
+
* 主干与目录在此定死,`execute` 复用同一份(含同一时间戳),避免两处二次取时间
|
|
311
|
+
* 算出不同文件名,让审批确认的路径和真正写入的路径脱节。
|
|
312
|
+
* @returns {{stem: string, relative: string, defaultDir: boolean, autoNamed: boolean}}
|
|
313
|
+
* `defaultDir` = 落点由插件决定(需要时现建收件箱);`autoNamed` = 主干由 host
|
|
314
|
+
* 生成,撞名可以加后缀。两者互相独立:只给名字不给目录时进收件箱,但那是用户的
|
|
315
|
+
* 命名意图,撞名了不能替他改名。
|
|
316
|
+
*/
|
|
317
|
+
function planCreatePaths(cwd, args, now = new Date()) {
|
|
318
|
+
if (!cwd) throw new Error('The session has no working directory; cannot create a mindmap.')
|
|
319
|
+
const directory = explicitDirectory(args)
|
|
320
|
+
const explicitName = typeof args?.name === 'string' ? args.name.trim() : ''
|
|
321
|
+
if (!explicitName && (typeof args?.description !== 'string' || !args.description.trim())) {
|
|
322
|
+
throw new Error('mindmap_create needs either `name` (an explicit title) or `description` (a short phrase such as 项目盘点); the host supplies the timestamp.')
|
|
323
|
+
}
|
|
324
|
+
const stem = explicitName ? sanitizeStem(explicitName) : defaultStem(now, args?.description)
|
|
325
|
+
return {
|
|
326
|
+
stem,
|
|
327
|
+
relative: join(directory || DEFAULT_MINDMAP_DIR, `${stem}.md`),
|
|
328
|
+
defaultDir: !directory,
|
|
329
|
+
autoNamed: !explicitName,
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
265
333
|
/**
|
|
266
334
|
* 解析脑图文件路径:相对路径以会话 cwd 为基;结果必须落在 cwd 内(决策 1),
|
|
267
335
|
* 且必须以 .md 结尾。cwd 是文件授权边界,缺失时必须失败关闭。
|
|
@@ -290,6 +358,113 @@ async function pathExists(p) {
|
|
|
290
358
|
}
|
|
291
359
|
}
|
|
292
360
|
|
|
361
|
+
/**
|
|
362
|
+
* 默认收件箱目录按需创建(036):不在插件初始化时预生成,第一次需要时才落盘,
|
|
363
|
+
* 已存在则直接复用(不重复 mkdir,免得碰用户目录的 mtime)。
|
|
364
|
+
* 三条失败关闭:符号链接越界、同名普通文件占位、真建不出来(权限/只读盘)。
|
|
365
|
+
* @returns 绝对目录路径。
|
|
366
|
+
*/
|
|
367
|
+
async function ensureDefaultDirectory(cwd) {
|
|
368
|
+
const dir = resolvePath(cwd, DEFAULT_MINDMAP_DIR)
|
|
369
|
+
const rel = relative(cwd, dir)
|
|
370
|
+
if (escapesBase(rel) || !(await resolvesInsideBase(dir, cwd))) {
|
|
371
|
+
throw new Error(`Mindmap directory must stay inside the session working directory (${cwd}).`)
|
|
372
|
+
}
|
|
373
|
+
let info = await stat(dir).catch(() => null)
|
|
374
|
+
if (!info) {
|
|
375
|
+
const failure = await mkdir(dir, { recursive: true }).then(() => null, (error) => error)
|
|
376
|
+
info = await stat(dir).catch(() => null)
|
|
377
|
+
if (!info) {
|
|
378
|
+
// 并发创建下另一个调用可能刚建好(所以 stat 得到了结果);这里仍拿不到,
|
|
379
|
+
// 才是真失败——把 mkdir 的原始错误码带出去,别只报一句"建不出来"。
|
|
380
|
+
throw new Error(`Cannot create the default mindmap directory ${JSON.stringify(dir)}: ${String(failure?.message ?? 'it vanished right after creation')}`)
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (!info.isDirectory()) {
|
|
384
|
+
throw new Error(`Cannot create the default mindmap directory: ${JSON.stringify(dir)} exists and is not a directory.`)
|
|
385
|
+
}
|
|
386
|
+
return dir
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* 默认命名的候选主干:第 1 次原名,之后依次 `-2`、`-3`。
|
|
391
|
+
* 后缀规则的唯一出口,挑名字和写文件都走它,避免两处算法各写一遍就漂。
|
|
392
|
+
*/
|
|
393
|
+
function stemForAttempt(stem, attempt) {
|
|
394
|
+
return attempt > 1 ? `${stem}-${attempt}` : stem
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* 收件箱里第一个没被占用的候选序号(纯探测,不建文件)。必须由**审批钩子**先跑一遍:
|
|
399
|
+
* 确认框里报出的路径若已被上一个同秒创建占用,用户点的就不是真正会写的那条,会话授权
|
|
400
|
+
* 也会登记到错文件上(036 并发一致性)。显式 `name` 不走这里——用户的命名意图优先,
|
|
401
|
+
* 撞名不能替他改名。
|
|
402
|
+
* @returns 候选序号(1 = 原名)。
|
|
403
|
+
*/
|
|
404
|
+
async function firstFreeAttempt(directory, stem, maxAttempts = MAX_CREATE_ATTEMPTS) {
|
|
405
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
406
|
+
if (!(await pathExists(join(directory, `${stemForAttempt(stem, attempt)}.md`)))) return attempt
|
|
407
|
+
}
|
|
408
|
+
throw new Error(`Too many mindmaps already share ${JSON.stringify(stem)} in this second; give the description more detail.`)
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* 写入瞬间的路径复核(P1):审批只代表"用户同意往这条路径写",不是路径安全的
|
|
413
|
+
* 长期保证——等待确认期间目录可能被改名、原位换成指向 cwd 外的符号链接。审批
|
|
414
|
+
* 阶段的校验结论不能顶替落盘前的校验,每条候选都用当前文件系统状态重新解析。
|
|
415
|
+
* @returns 重解析后的绝对路径(写盘用这一份,不用审批阶段缓存的)。
|
|
416
|
+
*/
|
|
417
|
+
async function resolveWriteTimeTarget(cwd, relativeTarget) {
|
|
418
|
+
try {
|
|
419
|
+
return await resolveMindmapPath(cwd, relativeTarget)
|
|
420
|
+
} catch (error) {
|
|
421
|
+
const detail = error instanceof Error ? error.message : String(error)
|
|
422
|
+
throw new Error(`Refusing to create the mindmap at ${JSON.stringify(relativeTarget)}: ${detail} The target directory may have changed while the write was being confirmed; start the create again.`)
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* 原子新建空脑图:`wx` 不存在才创建,挡掉已存在与同名目录,无 TOCTOU 窗口。
|
|
428
|
+
* 首选候选 `plan.relative`(= `stem` 第 `attempt` 号)——就是审批确认过的那条,
|
|
429
|
+
* 绝大多数情况一次即中。默认命名只有在极窄的竞态窗口里(探测到写盘之间被别人
|
|
430
|
+
* 抢注)才往后挪 -2、-3:覆盖别人的文件永远不可能发生,而挪了名之后授权由
|
|
431
|
+
* `actualCreates` 跟着纠正,工具结果里的 `path` 也始终是真正落盘的那条。
|
|
432
|
+
* 显式 `name` 只试一次、不改名。
|
|
433
|
+
* 每条候选落盘前都过 `resolveWriteTimeTarget`(P1):审批报的路径在确认期间被
|
|
434
|
+
* 换成越界符号链接时,这里拒写,绝不把文件建到工作区外面。
|
|
435
|
+
* @param {{relative: string, stem: string, attempt: number, autoNamed: boolean}} plan
|
|
436
|
+
* @returns 实际创建出来的绝对路径。
|
|
437
|
+
*/
|
|
438
|
+
async function createMindmapFile(cwd, plan) {
|
|
439
|
+
const { stem, attempt, autoNamed } = plan
|
|
440
|
+
const relDirectory = dirname(plan.relative)
|
|
441
|
+
const planned = join(cwd, plan.relative)
|
|
442
|
+
const targetFor = (index) => resolveWriteTimeTarget(cwd, join(relDirectory, `${stemForAttempt(stem, index)}.md`))
|
|
443
|
+
if (!autoNamed) {
|
|
444
|
+
// 显式命名只试这一条:命名意图优先,撞名就报错让他去开那份旧的。
|
|
445
|
+
try {
|
|
446
|
+
const target = await targetFor(attempt)
|
|
447
|
+
await writeFile(target, '', { encoding: 'utf8', flag: 'wx' })
|
|
448
|
+
return target
|
|
449
|
+
} catch (error) {
|
|
450
|
+
if (error?.code === 'EEXIST' || error?.code === 'EISDIR') {
|
|
451
|
+
throw new Error(`Mindmap already exists: ${JSON.stringify(planned)}. Open it with mindmap_open instead.`)
|
|
452
|
+
}
|
|
453
|
+
throw error
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
for (let index = attempt; index <= MAX_CREATE_ATTEMPTS; index += 1) {
|
|
457
|
+
try {
|
|
458
|
+
const candidate = await targetFor(index)
|
|
459
|
+
await writeFile(candidate, '', { encoding: 'utf8', flag: 'wx' })
|
|
460
|
+
return candidate
|
|
461
|
+
} catch (error) {
|
|
462
|
+
if (error?.code !== 'EEXIST' && error?.code !== 'EISDIR') throw error
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
throw new Error(`Cannot create mindmap ${JSON.stringify(planned)}: every nearby suffix is already taken, give the description more detail.`)
|
|
466
|
+
}
|
|
467
|
+
|
|
293
468
|
/**
|
|
294
469
|
* 两个路径是否指向同一个文件(dev + inode 比较)。大小写不敏感 FS(macOS/
|
|
295
470
|
* Windows)上仅大小写不同的路径命中同一文件——case-only 改名时据此区分
|
|
@@ -422,6 +597,9 @@ export function apply(ctx, config = {}) {
|
|
|
422
597
|
// 自然释放,不把授权带到别的会话。
|
|
423
598
|
let approvedTargets = new WeakMap()
|
|
424
599
|
const pendingApprovals = new WeakMap()
|
|
600
|
+
// 实际写盘路径:默认命名在「审批到写盘」之间被别人抢注时会挪到下一个空闲后缀,
|
|
601
|
+
// 授权必须跟着记真实路径,不能把审批阶段的旧候选登记成本次会话的授权目标。
|
|
602
|
+
const actualCreates = new WeakMap()
|
|
425
603
|
let lastMode
|
|
426
604
|
const readApprovalMode = () => {
|
|
427
605
|
const value = activeConfig()
|
|
@@ -458,23 +636,44 @@ export function apply(ctx, config = {}) {
|
|
|
458
636
|
const id = exec?.agent?.id
|
|
459
637
|
return id && ctx.sessions?.get ? ctx.sessions.get(id) ?? null : null
|
|
460
638
|
}
|
|
639
|
+
// 036:一次 create 的路径计划只算一遍,审批钩子与 execute 共用(含同一个时间戳)。
|
|
640
|
+
// WeakMap 以 exec 为键,和 pendingApprovals 一样依赖「整个工具生命周期内 exec
|
|
641
|
+
// 对象稳定」这一宿主契约;取不到缓存时 execute 自行重算,最多多要一次确认,
|
|
642
|
+
// 不会把审批过的路径和写盘的路径搞混。
|
|
643
|
+
const createPlans = new WeakMap()
|
|
644
|
+
/**
|
|
645
|
+
* 定稿一次 create 的落盘路径:纯计划 → 权威路径校验(越界与符号链接在这里拒)→
|
|
646
|
+
* 默认命名避开已占用的名字 → 重算并再校验一次。顺序不能换:先校验才敢探测,
|
|
647
|
+
* 否则 `.mindmaps` 是指向外部的符号链接时,探测会把外面的目录当成候选清单读。
|
|
648
|
+
* 也不在这里建目录——用户可能当场拒绝,不能凭一次确认之前先落一只空目录。
|
|
649
|
+
*/
|
|
650
|
+
const plannedCreate = async (exec, cwd, args) => {
|
|
651
|
+
const cached = createPlans.get(exec)
|
|
652
|
+
if (cached && cached.args === args) return cached.plan
|
|
653
|
+
const base = planCreatePaths(cwd, args ?? {})
|
|
654
|
+
const first = await resolveMindmapPath(cwd, base.relative)
|
|
655
|
+
// 顺序不能换:先过权威路径校验才敢探测。`.mindmaps` 若是指向外部的符号链接,
|
|
656
|
+
// 上面这一步已经拒了,不会把别人的目录当成候选清单来读。
|
|
657
|
+
const attempt = base.autoNamed ? await firstFreeAttempt(dirname(first), base.stem) : 1
|
|
658
|
+
const path = attempt === 1 ? first : await resolveMindmapPath(cwd, join(dirname(base.relative), `${stemForAttempt(base.stem, attempt)}.md`))
|
|
659
|
+
const plan = { ...base, attempt, path }
|
|
660
|
+
createPlans.set(exec, { args, plan })
|
|
661
|
+
return plan
|
|
662
|
+
}
|
|
461
663
|
const targetOf = async (exec) => {
|
|
462
664
|
const args = exec.arguments ?? {}
|
|
463
665
|
const cwd = sessionCwd(exec, ctx.sessions)
|
|
464
|
-
let raw
|
|
465
666
|
if (exec.name === 'mindmap_create') {
|
|
466
667
|
try {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
raw = join(directory, `${stem}.md`)
|
|
668
|
+
// 审批目标 = 校验过、且已避开占用名字的最终绝对路径:确认的就是真正会写的那条。
|
|
669
|
+
return (await plannedCreate(exec, cwd, args)).path
|
|
470
670
|
} catch {
|
|
471
671
|
// Let the tool return its normal argument error; approval lookup must
|
|
472
672
|
// never turn malformed input into a hook-level exception.
|
|
473
|
-
|
|
673
|
+
return `mindmap_create:${typeof args.name === 'string' ? args.name.trim() : '?'}`
|
|
474
674
|
}
|
|
475
|
-
} else {
|
|
476
|
-
raw = typeof args.path === 'string' ? args.path.trim() : ''
|
|
477
675
|
}
|
|
676
|
+
const raw = typeof args.path === 'string' ? args.path.trim() : ''
|
|
478
677
|
if (cwd && raw) {
|
|
479
678
|
try { return await resolveMindmapPath(cwd, raw) } catch { /* 工具本身负责报告参数错误 */ }
|
|
480
679
|
}
|
|
@@ -515,9 +714,10 @@ export function apply(ctx, config = {}) {
|
|
|
515
714
|
if (mode === 'session' && !highRisk && state?.paths.has(target)) return decision
|
|
516
715
|
if (mode === 'session' && !highRisk && state) pendingApprovals.set(exec, { session, target, state, generation: state.generation })
|
|
517
716
|
if (exec.name === 'mindmap_create') {
|
|
717
|
+
const title = String(target).split(/[\\/]/).pop()?.replace(/\.md$/i, '') ?? '?'
|
|
518
718
|
return {
|
|
519
719
|
kind: 'ask',
|
|
520
|
-
reason: `Create mindmap ${JSON.stringify(
|
|
720
|
+
reason: `Create mindmap ${JSON.stringify(title)} at ${JSON.stringify(target)}. ${mode === 'per-operation' ? 'Confirm this write.' : 'Confirm once for this document in the current session.'}`,
|
|
521
721
|
}
|
|
522
722
|
}
|
|
523
723
|
const renameNote = rename ? `, rename root to "${args.renameRoot}"` : ''
|
|
@@ -539,38 +739,36 @@ export function apply(ctx, config = {}) {
|
|
|
539
739
|
if (readApprovalMode() !== 'session') return
|
|
540
740
|
// 撤销或策略切换之后,尚未结束的旧调用不能重新恢复授权。
|
|
541
741
|
if (approvedTargets.get(pending.session) !== pending.state || pending.state.generation !== pending.generation) return
|
|
542
|
-
|
|
742
|
+
// 审批后被抢注、实际写到了 -2 的情形:授权记真实路径,不记用户没见过的那条。
|
|
743
|
+
const actual = actualCreates.get(exec)
|
|
744
|
+
if (actual) actualCreates.delete(exec)
|
|
745
|
+
pending.state.paths.add(actual ?? pending.target)
|
|
543
746
|
})
|
|
544
747
|
|
|
545
748
|
ctx.tools.register(defineTool({
|
|
546
749
|
name: 'mindmap_create',
|
|
547
|
-
description:
|
|
750
|
+
description: `Create a new mindmap markdown file and show it in the mindmap panel. Fails if the file already exists. The filename becomes the root node title. Pass \`name\` when the user gave an explicit title, otherwise pass \`description\` and the file is auto-named YYYYMMDD-HHmmss-<description>.md inside the default mindmap inbox (${DEFAULT_MINDMAP_DIR}/) — the host picks the next free -2/-3 suffix when that name is already taken, so nothing is ever overwritten. Only pass \`directory\` when the user chose a location.`,
|
|
548
751
|
parameters: {
|
|
549
752
|
type: 'object',
|
|
550
753
|
properties: {
|
|
551
|
-
name: { type: 'string', description: '
|
|
552
|
-
|
|
754
|
+
name: { type: 'string', description: 'Explicit mindmap document name (without .md). Becomes the filename and the root node title; a name collision is reported instead of auto-renaming. Omit it for a quick capture and pass `description` instead.' },
|
|
755
|
+
description: { type: 'string', description: `Short phrase for the auto-generated filename when \`name\` is omitted (e.g. 项目盘点). Cleaned and truncated to ${MAX_DESCRIPTION_CHARS} characters. Never put a date or time here — the host stamps the real current time.` },
|
|
756
|
+
directory: { type: 'string', description: `Directory relative to the session working directory, only when the user picked one (it must already exist). Omit it to file the mindmap in the default inbox ${DEFAULT_MINDMAP_DIR}/, which is created on first use.` },
|
|
553
757
|
},
|
|
554
|
-
required: [
|
|
758
|
+
required: [],
|
|
555
759
|
},
|
|
556
760
|
output: { schema: { type: 'string' }, render: (_args, value) => textOut(value) },
|
|
557
761
|
timeoutMs: TOOL_TIMEOUT_MS,
|
|
558
762
|
async execute(args, exec) {
|
|
559
763
|
const cwd = sessionCwd(exec, ctx.sessions)
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
//
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
if (error && (error.code === 'EEXIST' || error.code === 'EISDIR')) {
|
|
569
|
-
throw new Error(`Mindmap already exists: ${JSON.stringify(path)}. Open it with mindmap_open instead.`)
|
|
570
|
-
}
|
|
571
|
-
throw error
|
|
572
|
-
}
|
|
573
|
-
return buildResult('create', path, { content: '', created: true, revision: revisionOfContent('') })
|
|
764
|
+
const plan = await plannedCreate(exec, cwd, args)
|
|
765
|
+
// 默认收件箱按需建;显式目录沿用既有边界(不代建,越界与不存在都直接失败)。
|
|
766
|
+
if (plan.defaultDir) await ensureDefaultDirectory(cwd)
|
|
767
|
+
// 审批阶段的 plan 只能当作「确认过哪条路径」的备忘,写盘前由 createMindmapFile
|
|
768
|
+
// 重新解析校验,确认期间目录被掉包不会把文件写到工作区外。
|
|
769
|
+
const created = await createMindmapFile(cwd, plan)
|
|
770
|
+
actualCreates.set(exec, created)
|
|
771
|
+
return buildResult('create', created, { content: '', created: true, revision: revisionOfContent('') })
|
|
574
772
|
},
|
|
575
773
|
}))
|
|
576
774
|
|
|
@@ -743,9 +941,20 @@ export const internals = Object.freeze({
|
|
|
743
941
|
normalizeApprovalMode,
|
|
744
942
|
MAX_CONTENT_BYTES,
|
|
745
943
|
MAX_READ_BYTES,
|
|
944
|
+
DEFAULT_MINDMAP_DIR,
|
|
945
|
+
MAX_DESCRIPTION_CHARS,
|
|
746
946
|
readMindmap,
|
|
747
947
|
writeMindmap,
|
|
748
948
|
sanitizeStem,
|
|
949
|
+
sanitizeDescription,
|
|
950
|
+
timestampStamp,
|
|
951
|
+
defaultStem,
|
|
952
|
+
stemForAttempt,
|
|
953
|
+
firstFreeAttempt,
|
|
954
|
+
planCreatePaths,
|
|
955
|
+
ensureDefaultDirectory,
|
|
956
|
+
createMindmapFile,
|
|
957
|
+
resolveWriteTimeTarget,
|
|
749
958
|
resolveMindmapPath,
|
|
750
959
|
sessionCwd,
|
|
751
960
|
sessionCwdOf,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mindmap",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.1",
|
|
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",
|