dsh-plugin-tool-management 0.21.1 → 0.21.3

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 (143) hide show
  1. package/CHANGELOG.md +111 -1
  2. package/README.md +43 -7
  3. package/README_EN.md +41 -7
  4. package/docs/{update.md → UPDATE.md} +38 -36
  5. package/docs/images/1-EN.png +0 -0
  6. package/docs/images/1.png +0 -0
  7. package/docs/images/2-EN.png +0 -0
  8. package/docs/images/2.png +0 -0
  9. package/docs/images/3-EN.png +0 -0
  10. package/docs/images/3.png +0 -0
  11. package/docs/images/4-EN.png +0 -0
  12. package/docs/images/4.png +0 -0
  13. package/docs/images/5-EN.png +0 -0
  14. package/docs/images/5.png +0 -0
  15. package/docs/images/6-EN.png +0 -0
  16. package/docs/images/6.png +0 -0
  17. package/docs/images/7-EN.png +0 -0
  18. package/docs/images/7.png +0 -0
  19. package/docs/images/8-EN.png +0 -0
  20. package/docs/images/8.png +0 -0
  21. package/lib/approval-policy.js +2 -2
  22. package/lib/audit-log.js +1 -1
  23. package/lib/boot/reconcile.js +157 -0
  24. package/lib/client.js +6668 -3145
  25. package/lib/compat/capability-specs.js +13 -17
  26. package/lib/compat/host-contracts.js +2 -0
  27. package/lib/compat/host-probe.js +35 -38
  28. package/lib/compat/host-roots.js +86 -15
  29. package/lib/compat/patch-dialect.js +14 -1
  30. package/lib/compat/preset-reach.js +75 -102
  31. package/lib/compat/probe.js +86 -131
  32. package/lib/compat/runtime-notes.js +1 -1
  33. package/lib/context-inject-contract.js +6 -5
  34. package/lib/context-inject-frame.js +124 -73
  35. package/lib/context-inject-select.js +66 -12
  36. package/lib/context-inject-surface.js +52 -4
  37. package/lib/context-inject.js +176 -39
  38. package/lib/desktop-cookie-prune.js +95 -0
  39. package/lib/diagnostics.js +79 -0
  40. package/lib/exports/transcript.js +4 -4
  41. package/lib/host-names.js +6 -6
  42. package/lib/http-api.js +73 -48
  43. package/lib/http-fence.js +44 -9
  44. package/lib/hub.js +12 -13
  45. package/lib/imports/parsers.js +25 -21
  46. package/lib/imports/unzip.js +48 -0
  47. package/lib/imports/upload.js +13 -37
  48. package/lib/index.js +3026 -279
  49. package/lib/mcp/disabled-tools.js +97 -0
  50. package/lib/mcp/loader-token.js +4 -4
  51. package/lib/mcp/manager.js +636 -226
  52. package/lib/mcp/override-blocks.js +1 -1
  53. package/lib/mcp/patch-yaml.js +42 -31
  54. package/lib/mcp/restart-marker.js +110 -0
  55. package/lib/mcp/secret-guard.js +6 -6
  56. package/lib/mcp/state-section.js +190 -60
  57. package/lib/mcp/tool-visibility.js +364 -73
  58. package/lib/memories/archive-engine.js +67 -42
  59. package/lib/memories/archive.js +23 -3
  60. package/lib/memories/constants.js +40 -127
  61. package/lib/memories/discovery.js +41 -12
  62. package/lib/memories/index-io.js +238 -33
  63. package/lib/memories/projection.js +36 -20
  64. package/lib/memories/prompt-layer.js +38 -0
  65. package/lib/memories/search.js +86 -0
  66. package/lib/memories/service.js +350 -111
  67. package/lib/memories/snapshot.js +83 -36
  68. package/lib/op-registry.js +73 -15
  69. package/lib/ops/candidates.js +14 -5
  70. package/lib/ops/compat.js +56 -13
  71. package/lib/ops/ctx.js +1 -1
  72. package/lib/ops/memory.js +89 -20
  73. package/lib/ops/prompts.js +57 -13
  74. package/lib/ops/quick-prompts.js +25 -2
  75. package/lib/ops/scene-records.js +29 -23
  76. package/lib/ops/scene-sync.js +30 -10
  77. package/lib/ops/scope.js +1094 -0
  78. package/lib/ops/sessions.js +15 -11
  79. package/lib/ops/snapshot.js +65 -29
  80. package/lib/ops/state-doctor.js +40 -5
  81. package/lib/ops/trash-retention.js +2 -1
  82. package/lib/ops/trash.js +6 -6
  83. package/lib/paths.js +50 -3
  84. package/lib/prompts/preset-id.js +5 -1
  85. package/lib/prompts/project-instructions.js +162 -0
  86. package/lib/prompts/quick-service.js +6 -4
  87. package/lib/prompts/service.js +30 -18
  88. package/lib/request-gate.js +32 -29
  89. package/lib/scene-linkage.js +17 -4
  90. package/lib/scene-prompt-sync.js +11 -10
  91. package/lib/scene-settings.js +1 -0
  92. package/lib/scenes/candidates.js +17 -11
  93. package/lib/scope/intent-store.js +106 -0
  94. package/lib/scope/intent.js +376 -0
  95. package/lib/scope/resolve.js +190 -0
  96. package/lib/scope/scope-overrides.js +894 -0
  97. package/lib/scope/store.js +263 -0
  98. package/lib/scope/workspace-key.js +64 -0
  99. package/lib/sessions/archive-schemas.js +9 -0
  100. package/lib/sessions/bridge.js +42 -56
  101. package/lib/sessions/history.js +9 -9
  102. package/lib/sessions/workspace.js +21 -23
  103. package/lib/settings-sidecars.js +51 -24
  104. package/lib/sidebar-settings.js +1 -0
  105. package/lib/skills/catalog.js +207 -35
  106. package/lib/skills/core-util.js +5 -0
  107. package/lib/skills/core.js +36 -23
  108. package/lib/skills/frontmatter.js +144 -11
  109. package/lib/skills/homes.js +2 -0
  110. package/lib/skills/import-pipeline.js +8 -1
  111. package/lib/skills/manager-state.js +30 -6
  112. package/lib/skills/official.js +14 -11
  113. package/lib/skills/readonly-discovery.js +1 -0
  114. package/lib/skills/service.js +157 -31
  115. package/lib/skills/skill-roots.js +25 -7
  116. package/lib/skills/skill-trash.js +14 -3
  117. package/lib/skills/system-trash.js +3 -1
  118. package/lib/skills/upload-pipeline.js +19 -3
  119. package/lib/slash-settings.js +1 -0
  120. package/lib/stale-write.js +82 -0
  121. package/lib/subagents/catalog.js +52 -18
  122. package/lib/subagents/child-preset.js +7 -10
  123. package/lib/subagents/persona-parse.js +35 -13
  124. package/lib/subagents/persona-write.js +12 -8
  125. package/lib/subagents/run-provider.js +13 -15
  126. package/lib/subagents/service.js +16 -14
  127. package/lib/subagents/tool-filter.js +1 -1
  128. package/lib/subagents/tools.js +113 -41
  129. package/lib/token-config.js +34 -14
  130. package/lib/tool-table-switch.js +142 -49
  131. package/lib/tools/deps.js +172 -6
  132. package/lib/tools/mcp.js +231 -54
  133. package/lib/tools/memory.js +139 -39
  134. package/lib/tools/prompt.js +81 -17
  135. package/lib/tools/remove.js +52 -26
  136. package/lib/tools/scene.js +139 -42
  137. package/lib/tools/skills.js +211 -51
  138. package/lib/tools/subagent.js +63 -32
  139. package/lib/tools/table.js +63 -25
  140. package/lib/trash-id.js +3 -2
  141. package/lib/trash-retention.js +7 -7
  142. package/lib/update-check.js +222 -0
  143. package/package.json +18 -15
@@ -0,0 +1,222 @@
1
+ // 更新检查—— 只读、可缓存、绝不自动更新。
2
+ //
3
+ // 判据只有一条:**每个候选版本自己的 `engines.dsh`**。插件版本号与宿主版本号之间没有可推导的
4
+ // 对应关系(本仓库的版本约定是人工映射),拿 `latest` 或"版本号更大"当兼容结论都会把人带到
5
+ // 一个装不上的版本上。所以:
6
+ // · 只从 registry 的 `versions` 里挑 `engines.dsh` 满足当前宿主的;
7
+ // · 挑不出来就说 `no-compatible-version`,不给"最新版"这种没有意义的答案;
8
+ // · 命令固定 `dsh plugin --profile <p> add <pkg>@<version>`,**绝不出现 `@latest`**。
9
+ //
10
+ // 网络策略:只请求 npm registry;3 秒硬超时;检测到代理环境变量直接返回 `proxy-unsupported`,
11
+ // 不尝试穿透(穿透失败会挂住启动流程,而这件事本来就不该阻塞任何东西)。
12
+ import { mkdir, readFile } from 'node:fs/promises';
13
+ import { join } from 'node:path';
14
+ import * as semver from 'semver';
15
+ import { writeFileAtomically } from './memories/index-io.js';
16
+ /** 更新检查结果的缓存文件名(在 hub 内);删掉只是下次重新查。 */
17
+ export const UPDATE_CHECK_FILE = 'update-check.json';
18
+ /** 本插件在 npm 上的包名 —— 查更新与拼安装命令都用它。 */
19
+ export const PACKAGE_NAME = 'dsh-plugin-tool-management';
20
+ /** npm registry 的元数据地址(只读一次、3 秒超时、走系统代理设置)。 */
21
+ export const REGISTRY_URL = 'https://registry.npmjs.org/' + PACKAGE_NAME;
22
+ /** 代理环境变量:命中任意一个就当作"网络路径不确定",不尝试请求。 */
23
+ export function proxyDetected(env) {
24
+ return ['HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'http_proxy', 'https_proxy', 'all_proxy']
25
+ .some((key) => String(env[key] || '').trim() !== '');
26
+ }
27
+ /**
28
+ * 从 registry 的 `versions` 里挑与 `host` 兼容的最高版本。
29
+ *
30
+ * 兼容判据是**每个版本自己的** `engines.dsh`:没有该字段、不是合法 range、或不满足 → 跳过。
31
+ * `host` 为空 / 非法 → `null`(调用方报 `host-unknown`)。
32
+ */
33
+ export function pickBestCompatible(versions, host) {
34
+ if (!host || !semver.valid(host))
35
+ return null;
36
+ const list = Array.isArray(versions)
37
+ ? versions.map((v, i) => ({ version: v?.version || String(i), meta: v }))
38
+ : Object.entries(versions).map(([version, meta]) => ({ version, meta }));
39
+ const compatible = [];
40
+ for (const { version, meta } of list) {
41
+ if (!semver.valid(version))
42
+ continue;
43
+ const range = meta && meta.engines && typeof meta.engines.dsh === 'string' ? meta.engines.dsh.trim() : '';
44
+ if (range === '')
45
+ continue;
46
+ let ok = false;
47
+ try {
48
+ ok = semver.satisfies(host, range, { includePrerelease: true });
49
+ }
50
+ catch {
51
+ ok = false;
52
+ }
53
+ if (ok)
54
+ compatible.push(version);
55
+ }
56
+ if (!compatible.length)
57
+ return null;
58
+ return semver.rsort(compatible)[0];
59
+ }
60
+ /** 由"当前 / 宿主 / 最高兼容版本"三个事实得出状态(纯函数,便于测试)。 */
61
+ export function updateStatusOf(input) {
62
+ const { current, host, bestCompatible } = input;
63
+ if (!host || !semver.valid(host))
64
+ return 'host-unknown';
65
+ if (!bestCompatible) {
66
+ const own = String(input.currentEngines || '').trim();
67
+ if (own !== '') {
68
+ try {
69
+ if (!semver.satisfies(host, own, { includePrerelease: true }))
70
+ return 'current-incompatible';
71
+ }
72
+ catch { /* range 写错按未知处理 */ }
73
+ }
74
+ return 'no-compatible-version';
75
+ }
76
+ if (!semver.valid(current))
77
+ return 'unknown';
78
+ if (semver.gt(bestCompatible, current))
79
+ return 'update-available';
80
+ if (semver.gt(current, bestCompatible))
81
+ return 'local-ahead';
82
+ return 'up-to-date';
83
+ }
84
+ /** 安装命令:永远 pin 到具体版本,不出现 `@latest`。 */
85
+ export function installCommand(profile, version) {
86
+ return 'dsh plugin --profile ' + (profile && profile.trim() !== '' ? profile.trim() : '<profile>') +
87
+ ' add ' + PACKAGE_NAME + '@' + version;
88
+ }
89
+ /** 更新检查器:按 TTL 缓存结果,3 秒超时,检测到代理直接跳过,绝不自动更新。 */
90
+ export function createUpdateChecker(options) {
91
+ const ttlMs = options.ttlMs ?? 12 * 60 * 60 * 1000;
92
+ const failureTtlMs = options.failureTtlMs ?? 60 * 60 * 1000;
93
+ const timeoutMs = options.timeoutMs ?? 3000;
94
+ const env = options.env ?? process.env;
95
+ const now = options.now ?? Date.now;
96
+ const cacheFile = join(options.stateDir, UPDATE_CHECK_FILE);
97
+ let last = null;
98
+ let inflight = null;
99
+ const base = () => {
100
+ let host = null;
101
+ try {
102
+ const raw = options.hostVersion();
103
+ host = raw && semver.valid(raw) ? raw : null;
104
+ }
105
+ catch {
106
+ host = null;
107
+ }
108
+ return {
109
+ current: options.current,
110
+ host,
111
+ newest: null,
112
+ bestCompatible: null,
113
+ command: null,
114
+ };
115
+ };
116
+ const finish = (status, extra = {}) => {
117
+ const result = {
118
+ ok: status !== 'unknown',
119
+ ...base(),
120
+ status,
121
+ checkedAt: new Date(now()).toISOString(),
122
+ fromCache: false,
123
+ ...extra,
124
+ };
125
+ // `command` 只跟 `bestCompatible` 走,避免两处各拼一次。
126
+ if (result.bestCompatible) {
127
+ const profile = typeof options.profile === 'function' ? options.profile() : options.profile;
128
+ result.command = installCommand(profile, result.bestCompatible);
129
+ }
130
+ last = result;
131
+ return result;
132
+ };
133
+ const readCache = async () => {
134
+ try {
135
+ const raw = JSON.parse(await readFile(cacheFile, 'utf8'));
136
+ if (!raw || typeof raw !== 'object')
137
+ return null;
138
+ if (raw.current !== options.current)
139
+ return null;
140
+ if ((raw.host || null) !== base().host)
141
+ return null;
142
+ const age = now() - Date.parse(String(raw.checkedAt || ''));
143
+ if (!Number.isFinite(age) || age < 0)
144
+ return null;
145
+ const ttl = raw.ok === false ? failureTtlMs : ttlMs;
146
+ if (age > ttl)
147
+ return null;
148
+ const result = { ...raw, fromCache: true };
149
+ last = result;
150
+ return result;
151
+ }
152
+ catch {
153
+ return null;
154
+ }
155
+ };
156
+ const writeCache = async (result) => {
157
+ try {
158
+ await mkdir(options.stateDir, { recursive: true });
159
+ await writeFileAtomically(cacheFile, JSON.stringify({ ...result, fromCache: false }, null, 2) + '\n', { mode: 0o600 });
160
+ }
161
+ catch {
162
+ // 缓存写不进去不影响结论:下一次重新请求即可。
163
+ }
164
+ };
165
+ const run = async () => {
166
+ const b = base();
167
+ if (proxyDetected(env))
168
+ return finish('proxy-unsupported');
169
+ if (!b.host)
170
+ return finish('host-unknown');
171
+ const fetchImpl = options.fetchImpl ?? globalThis.fetch;
172
+ if (typeof fetchImpl !== 'function')
173
+ return finish('unknown', { ok: false, error: 'fetch unavailable' });
174
+ let meta;
175
+ try {
176
+ const res = await fetchImpl(REGISTRY_URL, {
177
+ headers: { accept: 'application/vnd.npm.install-v1+json' },
178
+ signal: AbortSignal.timeout(timeoutMs),
179
+ });
180
+ if (!res.ok)
181
+ return finish('unknown', { ok: false, error: 'registry HTTP ' + res.status });
182
+ meta = await res.json();
183
+ }
184
+ catch (e) {
185
+ const message = e instanceof Error ? e.message : String(e);
186
+ return finish('unknown', { ok: false, error: message });
187
+ }
188
+ const versions = meta && meta.versions && typeof meta.versions === 'object' ? meta.versions : {};
189
+ const all = Object.keys(versions).filter((v) => semver.valid(v));
190
+ const newest = all.length ? semver.rsort(all)[0] : (meta && meta['dist-tags'] && meta['dist-tags'].latest) || null;
191
+ const bestCompatible = pickBestCompatible(versions, b.host);
192
+ const status = updateStatusOf({
193
+ current: options.current,
194
+ host: b.host,
195
+ bestCompatible,
196
+ currentEngines: options.currentEngines ?? null,
197
+ });
198
+ return finish(status, { newest, bestCompatible });
199
+ };
200
+ const check = async (force) => {
201
+ if (!force) {
202
+ const cached = await readCache();
203
+ if (cached)
204
+ return cached;
205
+ }
206
+ if (inflight)
207
+ return inflight;
208
+ inflight = run()
209
+ .then(async (result) => { await writeCache(result); return result; })
210
+ .finally(() => { inflight = null; });
211
+ return inflight;
212
+ };
213
+ return {
214
+ check,
215
+ start() {
216
+ void check(false).catch(() => { });
217
+ },
218
+ peek() {
219
+ return last;
220
+ },
221
+ };
222
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-tool-management",
3
- "version": "0.21.1",
3
+ "version": "0.21.3",
4
4
  "description": "一个设置面板,统一管理 MCP、技能、记忆、子智能体、提示词和归档会话;可自定义搭配场景,一个场景即可切换整个环境;Agent也能帮你操作这个插件。",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,10 +25,10 @@
25
25
  "LICENSE",
26
26
  "screenshots.json",
27
27
  "docs/images",
28
- "docs/update.md"
28
+ "docs/UPDATE.md"
29
29
  ],
30
30
  "engines": {
31
- "dsh": ">=0.1.7-rc.2 <0.2.0-rc.1 || >=0.2.0-rc.1 <0.2.1-rc.2 || >=0.2.1-rc.2 <0.2.2",
31
+ "dsh": ">=0.2.1-rc.2 <0.2.2",
32
32
  "node": ">=18"
33
33
  },
34
34
  "publishConfig": {
@@ -42,6 +42,7 @@
42
42
  "typecheck:client": "node scripts/sync-client.mjs && tsc -p tsconfig.client.json",
43
43
  "check:i18n": "node scripts/check-i18n.mjs lib/client.js",
44
44
  "check:host": "node scripts/host-deps.mjs && node scripts/doctor.mjs",
45
+ "check:strict": "node scripts/check-strict.mjs",
45
46
  "host-deps": "node scripts/host-deps.mjs --fix",
46
47
  "doctor": "node scripts/doctor.mjs",
47
48
  "test": "npm run build && npm run check:i18n && npm run typecheck:client && node --test test/contracts.test.mjs test/client-exports.test.mjs",
@@ -72,17 +73,17 @@
72
73
  "icon": "./docs/images/icon.png",
73
74
  "peerDependencies": {
74
75
  "@deepseek-ai/cordis": "^4.0.2",
75
- "@deepseek-ai/dsh-agent-preset-registry": ">=0.1.7-rc.2 <0.2.0-rc.1 || >=0.2.0-rc.1 <0.2.1-rc.2 || >=0.2.1-rc.2 <0.2.2",
76
- "@deepseek-ai/dsh-llm": ">=0.1.7-rc.2 <0.2.0-rc.1 || >=0.2.0-rc.1 <0.2.1-rc.2 || >=0.2.1-rc.2 <0.2.2",
77
- "@deepseek-ai/dsh-session": ">=0.1.7-rc.2 <0.2.0-rc.1 || >=0.2.0-rc.1 <0.2.1-rc.2 || >=0.2.1-rc.2 <0.2.2",
78
- "@deepseek-ai/dsh-session-projection-cache": ">=0.1.7-rc.2 <0.2.0-rc.1 || >=0.2.0-rc.1 <0.2.1-rc.2 || >=0.2.1-rc.2 <0.2.2",
79
- "@deepseek-ai/dsh-settings": ">=0.1.7-rc.2 <0.2.0-rc.1 || >=0.2.0-rc.1 <0.2.1-rc.2 || >=0.2.1-rc.2 <0.2.2",
80
- "@deepseek-ai/dsh-spill-local": ">=0.1.7-rc.2 <0.2.0-rc.1 || >=0.2.0-rc.1 <0.2.1-rc.2 || >=0.2.1-rc.2 <0.2.2",
81
- "@deepseek-ai/dsh-storage-domain": ">=0.1.7-rc.2 <0.2.0-rc.1 || >=0.2.0-rc.1 <0.2.1-rc.2 || >=0.2.1-rc.2 <0.2.2",
82
- "@deepseek-ai/dsh-subagent-fork-in-process": ">=0.1.7-rc.2 <0.2.0-rc.1 || >=0.2.0-rc.1 <0.2.1-rc.2 || >=0.2.1-rc.2 <0.2.2",
83
- "@deepseek-ai/dsh-subagent-spawn-in-process": ">=0.1.7-rc.2 <0.2.0-rc.1 || >=0.2.0-rc.1 <0.2.1-rc.2 || >=0.2.1-rc.2 <0.2.2",
84
- "@deepseek-ai/dsh-tools": ">=0.1.7-rc.2 <0.2.0-rc.1 || >=0.2.0-rc.1 <0.2.1-rc.2 || >=0.2.1-rc.2 <0.2.2",
85
- "@deepseek-ai/dsh-workspace": ">=0.1.7-rc.2 <0.2.0-rc.1 || >=0.2.0-rc.1 <0.2.1-rc.2 || >=0.2.1-rc.2 <0.2.2",
76
+ "@deepseek-ai/dsh-agent-preset-registry": ">=0.2.1-rc.2 <0.2.2",
77
+ "@deepseek-ai/dsh-llm": ">=0.2.1-rc.2 <0.2.2",
78
+ "@deepseek-ai/dsh-session": ">=0.2.1-rc.2 <0.2.2",
79
+ "@deepseek-ai/dsh-session-projection-cache": ">=0.2.1-rc.2 <0.2.2",
80
+ "@deepseek-ai/dsh-settings": ">=0.2.1-rc.2 <0.2.2",
81
+ "@deepseek-ai/dsh-spill-local": ">=0.2.1-rc.2 <0.2.2",
82
+ "@deepseek-ai/dsh-storage-domain": ">=0.2.1-rc.2 <0.2.2",
83
+ "@deepseek-ai/dsh-subagent-fork-in-process": ">=0.2.1-rc.2 <0.2.2",
84
+ "@deepseek-ai/dsh-subagent-spawn-in-process": ">=0.2.1-rc.2 <0.2.2",
85
+ "@deepseek-ai/dsh-tools": ">=0.2.1-rc.2 <0.2.2",
86
+ "@deepseek-ai/dsh-workspace": ">=0.2.1-rc.2 <0.2.2",
86
87
  "react": "^18.2.0"
87
88
  },
88
89
  "peerDependenciesMeta": {
@@ -108,12 +109,14 @@
108
109
  "@deepseek-ai/dsh-workspace": "^0.2.1-rc.2",
109
110
  "@types/js-yaml": "^4.0.9",
110
111
  "@types/node": "^24.0.0",
112
+ "@types/semver": "^7.7.0",
111
113
  "react": "^18.2.0",
112
114
  "typescript": "^6.0.0"
113
115
  },
114
116
  "license": "MIT",
115
117
  "dependencies": {
116
118
  "fflate": "^0.8.3",
117
- "js-yaml": "^4.3.2"
119
+ "js-yaml": "^4.3.2",
120
+ "semver": "^7.7.2"
118
121
  }
119
122
  }