dsh-plugin-tool-management 0.21.0 → 0.21.2
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 +108 -0
- package/README.md +47 -10
- package/README_EN.md +45 -10
- package/docs/images/1-EN.png +0 -0
- package/docs/images/1.png +0 -0
- package/docs/images/2-EN.png +0 -0
- package/docs/images/2.png +0 -0
- package/docs/images/3-EN.png +0 -0
- package/docs/images/3.png +0 -0
- package/docs/images/4-EN.png +0 -0
- package/docs/images/4.png +0 -0
- package/docs/images/5-EN.png +0 -0
- package/docs/images/5.png +0 -0
- package/docs/images/6-EN.png +0 -0
- package/docs/images/6.png +0 -0
- package/docs/images/7-EN.png +0 -0
- package/docs/images/7.png +0 -0
- package/docs/images/8-EN.png +0 -0
- package/docs/images/8.png +0 -0
- package/docs/images/icon.png +0 -0
- package/docs/images/icon.svg +1 -0
- package/docs/update.md +37 -35
- package/lib/boot/reconcile.js +157 -0
- package/lib/client.js +7166 -3084
- package/lib/compat/patch-dialect.js +14 -1
- package/lib/compat/probe.js +25 -21
- package/lib/context-inject-frame.js +62 -40
- package/lib/context-inject-select.js +59 -4
- package/lib/context-inject-surface.js +49 -3
- package/lib/context-inject.js +145 -22
- package/lib/diagnostics.js +77 -0
- package/lib/http-api.js +39 -23
- package/lib/http-fence.js +40 -5
- package/lib/imports/unzip.js +48 -0
- package/lib/imports/upload.js +8 -36
- package/lib/index.js +2933 -169
- package/lib/mcp/disabled-tools.js +96 -0
- package/lib/mcp/manager.js +559 -128
- package/lib/mcp/restart-marker.js +110 -0
- package/lib/mcp/state-section.js +132 -43
- package/lib/mcp/tool-visibility.js +348 -56
- package/lib/memories/archive-engine.js +39 -14
- package/lib/memories/discovery.js +30 -10
- package/lib/memories/index-io.js +217 -18
- package/lib/memories/projection.js +20 -3
- package/lib/memories/prompt-layer.js +37 -0
- package/lib/memories/search.js +86 -0
- package/lib/memories/service.js +327 -91
- package/lib/memories/snapshot.js +66 -19
- package/lib/op-registry.js +49 -4
- package/lib/ops/candidates.js +11 -3
- package/lib/ops/compat.js +46 -4
- package/lib/ops/memory.js +78 -9
- package/lib/ops/prompts.js +49 -5
- package/lib/ops/quick-prompts.js +24 -2
- package/lib/ops/scene-records.js +7 -0
- package/lib/ops/scene-sync.js +23 -4
- package/lib/ops/scope.js +1093 -0
- package/lib/ops/sessions.js +5 -2
- package/lib/ops/snapshot.js +55 -20
- package/lib/ops/state-doctor.js +39 -4
- package/lib/ops/trash.js +12 -1
- package/lib/paths.js +50 -3
- package/lib/prompts/preset-id.js +4 -0
- package/lib/prompts/project-instructions.js +162 -0
- package/lib/prompts/quick-service.js +5 -4
- package/lib/prompts/service.js +20 -9
- package/lib/request-gate.js +6 -4
- package/lib/scene-linkage.js +12 -0
- package/lib/scene-prompt-sync.js +1 -1
- package/lib/scenes/candidates.js +8 -1
- package/lib/scope/intent-store.js +105 -0
- package/lib/scope/intent.js +376 -0
- package/lib/scope/resolve.js +190 -0
- package/lib/scope/scope-overrides.js +894 -0
- package/lib/scope/store.js +262 -0
- package/lib/scope/workspace-key.js +64 -0
- package/lib/sessions/history.js +3 -2
- package/lib/settings-sidecars.js +82 -19
- package/lib/sidebar-settings.js +13 -0
- package/lib/skills/catalog.js +206 -33
- package/lib/skills/core.js +1 -1
- package/lib/skills/frontmatter.js +121 -0
- package/lib/skills/service.js +145 -20
- package/lib/stale-write.js +74 -0
- package/lib/subagents/catalog.js +47 -13
- package/lib/subagents/persona-parse.js +26 -5
- package/lib/subagents/persona-write.js +11 -7
- package/lib/subagents/service.js +3 -2
- package/lib/subagents/tools.js +78 -8
- package/lib/token-config.js +25 -5
- package/lib/tool-table-switch.js +141 -49
- package/lib/tools/deps.js +151 -5
- package/lib/tools/mcp.js +189 -39
- package/lib/tools/memory.js +103 -18
- package/lib/tools/prompt.js +61 -9
- package/lib/tools/remove.js +46 -21
- package/lib/tools/scene.js +120 -26
- package/lib/tools/skills.js +191 -30
- package/lib/tools/subagent.js +52 -20
- package/lib/tools/table.js +48 -11
- package/lib/trash-retention.js +3 -2
- package/lib/update-check.js +218 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +19 -14
package/lib/ops/prompts.js
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
// 仍作用在组装后的整张表上(见 index.ts)。
|
|
5
5
|
import { resolveAgentsHome } from '../skills/homes.js';
|
|
6
6
|
import { existsSync } from 'node:fs';
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
7
8
|
import { join } from 'node:path';
|
|
9
|
+
import { stampConflict, stampOfText } from '../stale-write.js';
|
|
8
10
|
export function buildPromptOps(deps) {
|
|
9
11
|
/**
|
|
10
12
|
* 共享 agents 根的 `AGENTS.md`(`~/.agents/AGENTS.md`)。
|
|
@@ -31,10 +33,22 @@ export function buildPromptOps(deps) {
|
|
|
31
33
|
// 提示词页生效中的应该是场景选择的那个」。
|
|
32
34
|
// - `fileApplied` = 文件比对结果(AGENTS.md 里确实是它)。两者同时为真说明
|
|
33
35
|
// 场景绑的就是已应用的那份,正文一致时宿主不会再注入第二遍(去重)。
|
|
34
|
-
'agentsmd-list': async () => {
|
|
36
|
+
'agentsmd-list': async (args) => {
|
|
35
37
|
const base = await deps.promptsService.list();
|
|
36
38
|
if (!base || base.ok === false)
|
|
37
39
|
return base;
|
|
40
|
+
// 会话层「生效中」:拿本会话真正注入的正文与每份预设的正文比对(沿用的可能是
|
|
41
|
+
// 全局文件、场景预设或冻结快照,三者都不带 presetId,只能比内容)。读不到就不标。
|
|
42
|
+
const sessionId = String((args && args.sessionId) || '').trim();
|
|
43
|
+
let sessionHash = null;
|
|
44
|
+
if (sessionId !== '' && deps.sessionPromptText !== undefined) {
|
|
45
|
+
try {
|
|
46
|
+
const text = deps.sessionPromptText(sessionId);
|
|
47
|
+
if (text.trim() !== '')
|
|
48
|
+
sessionHash = createHash('sha256').update(text).digest('hex');
|
|
49
|
+
}
|
|
50
|
+
catch { /* 读不到 = 不做会话标记,不影响预设库 */ }
|
|
51
|
+
}
|
|
38
52
|
let scenePrompt;
|
|
39
53
|
try {
|
|
40
54
|
const r = await deps.rulesOps['rules-list']({});
|
|
@@ -58,12 +72,20 @@ export function buildPromptOps(deps) {
|
|
|
58
72
|
active,
|
|
59
73
|
fileApplied,
|
|
60
74
|
activeVia: byScene ? 'scene' : (active && fileApplied ? 'file' : null),
|
|
75
|
+
// 会话层:这一份就是本会话实际注入的正文(比对内容,不依赖 presetId)。
|
|
76
|
+
sessionActive: sessionHash !== null && p.contentHash === sessionHash,
|
|
61
77
|
refs: refs ? refs.get(p.id) || [] : [],
|
|
62
78
|
};
|
|
63
79
|
});
|
|
64
80
|
return { ...base, presets, ...(scenePrompt ? { scenePrompt } : {}), agentsHomeAgentsMd: agentsHomeAgentsMd() };
|
|
65
81
|
},
|
|
66
|
-
'agentsmd-read': (args) =>
|
|
82
|
+
'agentsmd-read': async (args) => {
|
|
83
|
+
const res = await deps.promptsService.read(String((args && args.id) || ''));
|
|
84
|
+
if (!res || res.ok === false)
|
|
85
|
+
return res;
|
|
86
|
+
// 并发编辑判据(与记忆 `rules-read` 同一条口径):编辑弹窗把这份指纹带回来。
|
|
87
|
+
return { ...res, stamp: stampOfText(res.content) };
|
|
88
|
+
},
|
|
67
89
|
// content 与 from 都可选:新建弹窗里直接写正文(content),或从现有预设复制(from)。
|
|
68
90
|
'agentsmd-create': (args) => deps.promptsService.create(String((args && args.id) || ''), {
|
|
69
91
|
...(args && args.from ? { from: String(args.from) } : {}),
|
|
@@ -75,7 +97,17 @@ export function buildPromptOps(deps) {
|
|
|
75
97
|
// 保存后同步一次全局基线:若改的正是「正在驱动基线的那份」,正文要跟着写进
|
|
76
98
|
// `~/.dsh/AGENTS.md`(否则页面标着「生效中」而文件里还是旧内容)。
|
|
77
99
|
'agentsmd-update': async (args) => {
|
|
78
|
-
const
|
|
100
|
+
const id = String((args && args.id) || '');
|
|
101
|
+
// 并发编辑:先核对磁盘那份是否还是用户看到的那一份。不传 expectedStamp = 旧行为。
|
|
102
|
+
if (args && args.expectedStamp !== undefined) {
|
|
103
|
+
const before = await deps.promptsService.read(id);
|
|
104
|
+
if (!before || before.ok === false)
|
|
105
|
+
return before;
|
|
106
|
+
const conflict = stampConflict(stampOfText(before.content), args.expectedStamp);
|
|
107
|
+
if (conflict)
|
|
108
|
+
return conflict;
|
|
109
|
+
}
|
|
110
|
+
const res = await deps.promptsService.update(id, String((args && args.content) ?? ''), args && args.nextId !== undefined ? String(args.nextId) : undefined,
|
|
79
111
|
// 描述与正文同一次提交:省略(undefined)= 不动,空串 = 清空。
|
|
80
112
|
args && typeof args.description === 'string' ? String(args.description) : undefined);
|
|
81
113
|
if (!res || res.ok === false)
|
|
@@ -91,7 +123,18 @@ export function buildPromptOps(deps) {
|
|
|
91
123
|
return deps.withAgentsMdSync({ ...res, ...renamed });
|
|
92
124
|
},
|
|
93
125
|
// 应用 = 写全局基线文件;场景接管期间只放行「场景绑定的那一份」(见 applyPresetGuarded)。
|
|
94
|
-
|
|
126
|
+
// 并发编辑判据落在**全局文件**上(这次写的就是它):`agentsmd-get-current` 回的 `stamp`。
|
|
127
|
+
'agentsmd-apply': async (args) => {
|
|
128
|
+
if (args && args.expectedStamp !== undefined) {
|
|
129
|
+
const cur = await deps.promptsService.getCurrent();
|
|
130
|
+
if (!cur || cur.ok === false)
|
|
131
|
+
return cur;
|
|
132
|
+
const conflict = stampConflict(cur.exists ? cur.content : null, args.expectedStamp);
|
|
133
|
+
if (conflict)
|
|
134
|
+
return conflict;
|
|
135
|
+
}
|
|
136
|
+
return deps.applyPresetGuarded(String((args && args.id) || ''));
|
|
137
|
+
},
|
|
95
138
|
// 取消应用 = **回到链起点**(这一串应用/取消往复开始之前的状态):起点有内容就把
|
|
96
139
|
// `__last-applied__/AGENTS.md` 写回去,起点文件不存在就把文件删掉(`removed: true`)。
|
|
97
140
|
// 连续应用过 A、B 时是**一步回到起点**,不是只退一步 —— 与场景基线同一条口径
|
|
@@ -134,7 +177,8 @@ export function buildPromptOps(deps) {
|
|
|
134
177
|
const res = await deps.promptsService.getCurrent();
|
|
135
178
|
if (!res || res.ok === false)
|
|
136
179
|
return res;
|
|
137
|
-
|
|
180
|
+
// `stamp` 是「应用 / 取消应用」的并发编辑判据:文件不存在时是 null。
|
|
181
|
+
return { ...res, stamp: res.exists ? stampOfText(res.content) : null, agentsHomeAgentsMd: agentsHomeAgentsMd() };
|
|
138
182
|
},
|
|
139
183
|
// 删除:**场景绑定**与**当前应用的那份**拦得住(判据见下方注释)。拒绝时逐条说明「谁在用」,
|
|
140
184
|
// 用户知道该先改哪里。引用清单由 scene-prompt-sync 与显示/注入同源算出。
|
package/lib/ops/quick-prompts.js
CHANGED
|
@@ -4,11 +4,33 @@
|
|
|
4
4
|
// `~/.dsh/AGENTS.md`、不参与场景同步、没有"生效中"。所以这里既不需要 `withAgentsMdSync`
|
|
5
5
|
// 也不需要引用探测 —— 反过来,正因为它是纯侧车读写,才更要老老实实进 `op-registry`
|
|
6
6
|
// 的写门禁清单(配了令牌的宿主上,免令牌请求不该能改用户存好的文字)。
|
|
7
|
-
export function buildQuickPromptOps(quick) {
|
|
7
|
+
export function buildQuickPromptOps(quick, deps = {}) {
|
|
8
|
+
const flagFor = (sessionId) => deps.flagFor === undefined ? undefined : deps.flagFor(sessionId);
|
|
8
9
|
const text = (args, key) => args && typeof args[key] === 'string' ? String(args[key]) : undefined;
|
|
9
10
|
return {
|
|
10
11
|
// 列表连正文一起回(客户端点用时手里就得有那段字,见 quick-service.ts 头注)。
|
|
11
|
-
|
|
12
|
+
//
|
|
13
|
+
// 会话层:给了 `sessionId` 就按本会话的生效值算 `enabled`(并额外带 `globalEnabled` /
|
|
14
|
+
// `overridden`)。**只改这一条回执里的值** —— 侧车里的 `meta.json` 一个字不动,
|
|
15
|
+
// 别的会话读到的仍是全局值。
|
|
16
|
+
'quickprompt-list': async (args) => {
|
|
17
|
+
const sessionId = args && typeof args.sessionId === 'string' ? args.sessionId.trim() : '';
|
|
18
|
+
const res = await quick.list();
|
|
19
|
+
if (sessionId === '' || !res || res.ok === false)
|
|
20
|
+
return res;
|
|
21
|
+
const resolver = flagFor(sessionId);
|
|
22
|
+
if (resolver === undefined)
|
|
23
|
+
return res;
|
|
24
|
+
return {
|
|
25
|
+
...res,
|
|
26
|
+
prompts: res.prompts.map((row) => {
|
|
27
|
+
const over = resolver(String(row.id));
|
|
28
|
+
if (typeof over !== 'boolean')
|
|
29
|
+
return row;
|
|
30
|
+
return { ...row, enabled: over, globalEnabled: row.enabled, overridden: true };
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
},
|
|
12
34
|
'quickprompt-create': (args) => quick.create(String((args && args.id) || ''), text(args, 'content') ?? '', text(args, 'description')),
|
|
13
35
|
// 改名不牵连任何别处:快捷提示词不被场景绑定、不被引用,改完就是改完了。
|
|
14
36
|
'quickprompt-update': (args) => quick.update(String((args && args.id) || ''), text(args, 'content') ?? '', args && args.nextId !== undefined ? String(args.nextId) : undefined, text(args, 'description')),
|
package/lib/ops/scene-records.js
CHANGED
|
@@ -34,6 +34,13 @@ export function buildSceneRecordOps(rc) {
|
|
|
34
34
|
* 场景名按放宽后的规则校验;不存在的场景名也允许保存(目录随后创建即可生效)。
|
|
35
35
|
*/
|
|
36
36
|
async function rulesSetActive(args) {
|
|
37
|
+
// 会话层切换**不走这里**(0.21.2,决策 14):本 op 改的是索引里的全局 `active`,还会
|
|
38
|
+
// 触发场景模式的运行时应用(见 ops/scene-sync.ts 与 index.ts 的包装)。会话层切场景
|
|
39
|
+
// 只改"本会话看到什么" —— 不切运行时、不写 AGENTS.md、不碰全局 active。
|
|
40
|
+
// 带着 sessionId 调过来必须当场拒绝:静默切全局正是"A 切场景,B 也跟着变"的成因。
|
|
41
|
+
if (args && typeof args.sessionId === 'string' && args.sessionId.trim() !== '') {
|
|
42
|
+
return fail('error.rules.sessionScopeWrite', '会话层场景请走 scope-set(本 op 改的是全局当前场景,会切换运行时)');
|
|
43
|
+
}
|
|
37
44
|
// 参数必须显式二选一。旧实现把「没传参数」「传了未知参数名」都落进 else 分支、
|
|
38
45
|
// 用空数组覆盖 active,于是 `rules-set-active {}` 会静默把模式切成 custom 且零激活场景
|
|
39
46
|
// (用户以为自己只是"没改动",实际已经改了注入范围)。这里显式拒绝。
|
package/lib/ops/scene-sync.js
CHANGED
|
@@ -75,24 +75,43 @@ export function buildSceneSyncOps(deps) {
|
|
|
75
75
|
},
|
|
76
76
|
'rules-update-scene': async (args) => {
|
|
77
77
|
const res = await deps.rulesOps['rules-update-scene'](args);
|
|
78
|
+
// 改名成功后,停在这个场景里的会话跟着换名(0.21.2 复核)。要在下面两个绑定回调
|
|
79
|
+
// **之前**做:它们按场景名找当前模式 / 档案,旧名这时候已经不存在了。
|
|
80
|
+
const renamedFrom = res && res.ok !== false && typeof res.renamedFrom === 'string' ? res.renamedFrom : '';
|
|
81
|
+
const finalName = String((res && res.scene && res.scene.name) || (args && args.nextName) || (args && args.name) || '');
|
|
82
|
+
if (renamedFrom !== '' && finalName !== '' && deps.onSceneRenamed !== undefined) {
|
|
83
|
+
try {
|
|
84
|
+
await deps.onSceneRenamed(renamedFrom, finalName);
|
|
85
|
+
}
|
|
86
|
+
catch { /* 会话同步失败不拦保存;下次启动的孤儿修复会兜 */ }
|
|
87
|
+
}
|
|
78
88
|
// 工具表方案绑定改动(0.15.0):改的是**当前启用场景**且这次真的带了这一参数时即时生效;
|
|
79
|
-
// 改名在场景处于模式中时会被拦(rulesUpdateScene 的 sceneInMode),所以这里
|
|
89
|
+
// 改名在场景处于模式中时会被拦(rulesUpdateScene 的 sceneInMode),所以这里 finalName 就是生效场景的名字。
|
|
80
90
|
if (res && res.ok !== false && deps.onToolTablePresetChanged && args && args.toolTablePreset !== undefined) {
|
|
81
91
|
try {
|
|
82
|
-
await deps.onToolTablePresetChanged(
|
|
92
|
+
await deps.onToolTablePresetChanged(finalName, String(args.toolTablePreset));
|
|
83
93
|
}
|
|
84
94
|
catch { /* 即时生效失败不拦保存;下次进/退场景会对齐 */ }
|
|
85
95
|
}
|
|
86
96
|
// 快捷提示词勾选集同理:只有这次真的带了这一参数才动(不传 = 不碰这一域)。
|
|
87
97
|
if (res && res.ok !== false && deps.onQuickPromptsChanged && args && args.quickPrompts !== undefined) {
|
|
88
98
|
try {
|
|
89
|
-
await deps.onQuickPromptsChanged(
|
|
99
|
+
await deps.onQuickPromptsChanged(finalName, Array.isArray(args.quickPrompts) ? args.quickPrompts.map((x) => String(x)) : null);
|
|
90
100
|
}
|
|
91
101
|
catch { /* 同上 */ }
|
|
92
102
|
}
|
|
93
103
|
return deps.withAgentsMdSync(res);
|
|
94
104
|
},
|
|
95
105
|
'rules-create-scene': async (args) => deps.withAgentsMdSync(await deps.rulesOps['rules-create-scene'](args)),
|
|
96
|
-
'rules-remove-scene': async (args) =>
|
|
106
|
+
'rules-remove-scene': async (args) => {
|
|
107
|
+
const res = await deps.rulesOps['rules-remove-scene'](args);
|
|
108
|
+
if (res && res.ok !== false && deps.onSceneRemoved !== undefined) {
|
|
109
|
+
try {
|
|
110
|
+
await deps.onSceneRemoved(String(res.name || (args && args.name) || ''));
|
|
111
|
+
}
|
|
112
|
+
catch { /* 会话同步失败不拦删除;下次启动的孤儿修复会兜 */ }
|
|
113
|
+
}
|
|
114
|
+
return deps.withAgentsMdSync(res);
|
|
115
|
+
},
|
|
97
116
|
};
|
|
98
117
|
}
|