dsh-mindmap 0.14.1 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/index.js +100 -8
  3. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -24,6 +24,8 @@ All notable changes to this project are documented here. Release-specific notes
24
24
 
25
25
  ### Fixed
26
26
 
27
+ - 0.1.7 settings volatile mechanism: all seven Config fields (`requireApproval`, `approvalMode`, `defaultPanelWidth`, `lineStyle`, `cardStyle`, `colorTheme`, `growthAnimation`) are now marked `.extra('volatile', true)` on their schemastery schema nodes. Without `meta.volatile`, the 0.1.7 host's settings storage (`dsh-settings` `volatileForm`/`isVolatilePath`/`write`) rejects all reads and writes for the `mindmap` namespace — the settings panel (设置 → 思维脑图) displays stale or default values and saving a new choice is silently dropped. The `volatile` meta is transparent to older hosts (0.1.5 and below ignore it), so the dual-path behavior is unchanged. A one-time legacy migration was also added: on startup, when the settings value is all-defaults, the plugin reads `~/.dsh/settings.yaml.imported` (the host-renamed old `settings.yaml`), extracts the `mindmap:` section's scalar fields with a line-by-line parser (no YAML dependency), validates each value against its allowed set, and writes the result to the new settings store via `scope.update()`. The `.imported` file is never deleted (it is host-managed); failures are silently skipped so the plugin still loads and the user can configure manually.
28
+ - dsh-tools peer dependency window extended to cover the `0.1.7-rc.2` release: `^0.1.7-alpha.0` is appended to the comparator list (`^0.1.0-rc.6 || ^0.1.1-rc.0 || ^0.1.2-alpha.0 || ^0.1.3-alpha.0 || ^0.1.5-alpha.0 || ^0.1.7-alpha.0`). Under node-semver prerelease tuple rules, `0.1.7-rc.2` requires a `[0,1,7]` tuple with a prerelease tag in the range — without this comparator, `pnpm add dsh-mindmap` on a 0.1.7 host fails with ERESOLVE. The static API surface (Agent `{ id }`, `SessionHeader.cwd`, `settings.describe` envelope, `ChatSnapshot.legacy.nodes`, `ToolResultNode` fields, `conversation.session.header.actions` / `conversation.chat.turn` slots, `settings.section` slot, client inject ids, `@deepseek-ai/schemastery ^3.18.0`) was verified unchanged against the 0.1.7-rc.2 npm package. A `settings.plugin.item` string found in client.js comments was confirmed to be a documentation remark (the actual registration uses `settings.section`, which remains healthy in 0.1.7); no code migration is required.
27
29
  - 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.
28
30
  - 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.
29
31
  - 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.
package/index.js CHANGED
@@ -18,8 +18,9 @@
18
18
  // 015 起经 settings namespace 可运行时切换。
19
19
  // - 依赖:仅 @deepseek-ai/schemastery(settings schema;发布包正常解析,
20
20
  // link 开发需先 npm i)。工具参数 schema 仍手写 JSON Schema(003 偏差 1)。
21
- import { access, mkdir, open, opendir, realpath, rename, stat, unlink, writeFile } from 'node:fs/promises'
21
+ import { access, mkdir, open, opendir, readFile, realpath, rename, stat, unlink, writeFile } from 'node:fs/promises'
22
22
  import { createHash, randomUUID } from 'node:crypto'
23
+ import { homedir } from 'node:os'
23
24
  import { dirname, isAbsolute, join, relative, resolve as resolvePath, sep } from 'node:path'
24
25
  import Schema from '@deepseek-ai/schemastery'
25
26
 
@@ -41,14 +42,84 @@ function normalizeApprovalMode(value, requireApproval = true) {
41
42
  return 'session'
42
43
  }
43
44
 
45
+ /**
46
+ * 0.1.7 迁移:从 settings.yaml.imported 的 mindmap 段提取标量字段。
47
+ * 该文件是宿主自动改名后的旧 settings.yaml,格式是顶层 YAML 段,
48
+ * mindmap 段下全是 `key: value` 标量行——不引入 YAML 库,只按行解析。
49
+ * 容错:文件不存在、解析失败、mindmap 段缺失一律返回 null(静默跳过)。
50
+ *
51
+ * `raw` 是文件的完整文本;返回已校验过的可写入字段对象,或 null。
52
+ */
53
+ const MIGRATABLE_KEYS = {
54
+ requireApproval: (v) => v === 'true' || v === 'false',
55
+ approvalMode: (v) => APPROVAL_MODES.includes(v) || v === 'once-per-document' || v === 'always',
56
+ defaultPanelWidth: (v) => /^\d+$/.test(v) && Number(v) >= 20 && Number(v) <= 80,
57
+ lineStyle: (v) => v === 'curve' || v === 'elbow',
58
+ cardStyle: (v) => v === 'rounded' || v === 'square',
59
+ colorTheme: (v) => v === 'ocean' || v === 'sunset' || v === 'forest',
60
+ growthAnimation: (v) => v === 'true' || v === 'false',
61
+ }
62
+
63
+ const MIGRATABLE_PARSERS = {
64
+ requireApproval: (v) => v === 'true',
65
+ defaultPanelWidth: (v) => Number(v),
66
+ growthAnimation: (v) => v === 'true',
67
+ }
68
+
69
+ function parseLegacyMindmapSection(raw) {
70
+ if (typeof raw !== 'string') return null
71
+ const lines = raw.split('\n')
72
+ let inMindmap = false
73
+ const found = {}
74
+ for (const line of lines) {
75
+ if (/^mindmap:\s*$/.test(line)) { inMindmap = true; continue }
76
+ if (inMindmap) {
77
+ if (/^\S/.test(line)) break
78
+ const m = /^\s{2,}(\w+):\s*(.+?)\s*$/.exec(line)
79
+ if (!m) continue
80
+ const key = m[1]
81
+ const val = m[2]
82
+ if (MIGRATABLE_KEYS[key] && MIGRATABLE_KEYS[key](val)) {
83
+ found[key] = MIGRATABLE_PARSERS[key] ? MIGRATABLE_PARSERS[key](val) : val
84
+ }
85
+ }
86
+ }
87
+ return Object.keys(found).length ? found : null
88
+ }
89
+
90
+ /**
91
+ * 判断当前 settings value 是否全为默认值(说明新存储里还没写入过用户偏好,
92
+ * 是需要迁移的空状态)。entryConfig 是组合层 base,Config schema 的默认值
93
+ * 和 entryConfig 的默认值一致。
94
+ */
95
+ const CONFIG_DEFAULTS = {
96
+ requireApproval: true,
97
+ approvalMode: 'session',
98
+ defaultPanelWidth: 42,
99
+ lineStyle: 'elbow',
100
+ cardStyle: 'rounded',
101
+ colorTheme: 'ocean',
102
+ growthAnimation: true,
103
+ }
104
+
105
+ function isAllDefaults(value) {
106
+ if (!value || typeof value !== 'object') return true
107
+ // 空对象(新存储里没有任何值)= 需要迁移
108
+ if (Object.keys(value).length === 0) return true
109
+ for (const key in CONFIG_DEFAULTS) {
110
+ if (value[key] !== CONFIG_DEFAULTS[key]) return false
111
+ }
112
+ return true
113
+ }
114
+
44
115
  export const Config = Schema.object({
45
- 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.'),
46
- 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.'),
47
- defaultPanelWidth: Schema.number().default(42).description('Default floating-panel width as a percentage of the viewport (clamped 20-80 on the client).'),
48
- lineStyle: Schema.union(['curve', 'elbow']).default('elbow').description('Connector line style between nodes: curve (bezier) or elbow (orthogonal).'),
49
- cardStyle: Schema.union(['rounded', 'square']).default('rounded').description('Node card corner style.'),
50
- colorTheme: Schema.union(['ocean', 'sunset', 'forest']).default('ocean').description('Node color theme.'),
51
- growthAnimation: Schema.boolean().default(true).description('Progressive growth animation: newly added/changed nodes fade in one by one after each update (total capped at ~2s). Turn off for instant full render.'),
116
+ requireApproval: Schema.boolean().default(true).description('Legacy switch: false skips ordinary confirmations only, and is lifted when the settings panel picks an explicit approval mode. Rename, clearing content, and broad rewrites always require approval.').extra('volatile', true),
117
+ 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.').extra('volatile', true),
118
+ defaultPanelWidth: Schema.number().default(42).description('Default floating-panel width as a percentage of the viewport (clamped 20-80 on the client).').extra('volatile', true),
119
+ lineStyle: Schema.union(['curve', 'elbow']).default('elbow').description('Connector line style between nodes: curve (bezier) or elbow (orthogonal).').extra('volatile', true),
120
+ cardStyle: Schema.union(['rounded', 'square']).default('rounded').description('Node card corner style.').extra('volatile', true),
121
+ colorTheme: Schema.union(['ocean', 'sunset', 'forest']).default('ocean').description('Node color theme.').extra('volatile', true),
122
+ growthAnimation: Schema.boolean().default(true).description('Progressive growth animation: newly added/changed nodes fade in one by one after each update (total capped at ~2s). Turn off for instant full render.').extra('volatile', true),
52
123
  })
53
124
 
54
125
  const MAX_CONTENT_BYTES = 2 * 1024 * 1024
@@ -585,6 +656,23 @@ export function apply(ctx, config = {}) {
585
656
  ctx.inject(['settings'], (sctx) => {
586
657
  const scope = sctx.settings.register(SETTINGS_NAMESPACE, Config, { base: entryConfig })
587
658
  activeConfig = () => scope.get()
659
+ // 0.1.7 迁移:宿主把 ~/.dsh/settings.yaml 改名 .imported 后,legacy 导入
660
+ // 因 Config 无 volatile 字段而静默失败(volatile 已修,但 .imported 只导入一次,
661
+ // 不会重跑)。启动时自查:settings value 全为默认值 → 读 .imported 的 mindmap
662
+ // 段 → 校验后一次性写入新存储。失败静默跳过;不删除 .imported(宿主管理的文件)。
663
+ ;(async () => {
664
+ try {
665
+ if (!isAllDefaults(scope.get())) return
666
+ const imported = join(homedir(), '.dsh', 'settings.yaml.imported')
667
+ const raw = await readFile(imported, 'utf8').catch(() => null)
668
+ if (!raw) return
669
+ const legacy = parseLegacyMindmapSection(raw)
670
+ if (!legacy) return
671
+ await scope.update(legacy)
672
+ } catch {
673
+ // 迁移失败不影响插件运行:用户仍可在设置面板手动配置。
674
+ }
675
+ })()
588
676
  sctx.effect(() => () => {
589
677
  activeConfig = () => entryConfig
590
678
  })
@@ -963,4 +1051,8 @@ export const internals = Object.freeze({
963
1051
  isTrustedRequest,
964
1052
  buildResult,
965
1053
  revisionOfContent,
1054
+ Config,
1055
+ parseLegacyMindmapSection,
1056
+ isAllDefaults,
1057
+ CONFIG_DEFAULTS,
966
1058
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mindmap",
3
- "version": "0.14.1",
3
+ "version": "0.15.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",
@@ -36,7 +36,7 @@
36
36
  "@deepseek-ai/schemastery": "^3.18.0"
37
37
  },
38
38
  "peerDependencies": {
39
- "@deepseek-ai/dsh-tools": "^0.1.0-rc.6 || ^0.1.1-rc.0 || ^0.1.2-alpha.0 || ^0.1.3-alpha.0 || ^0.1.5-alpha.0",
39
+ "@deepseek-ai/dsh-tools": "^0.1.0-rc.6 || ^0.1.1-rc.0 || ^0.1.2-alpha.0 || ^0.1.3-alpha.0 || ^0.1.5-alpha.0 || ^0.1.7-alpha.0",
40
40
  "dsh-better-sidebar": ">=0.10.0"
41
41
  },
42
42
  "peerDependenciesMeta": {