dsh-plugin-tool-management 0.22.3 → 0.22.4

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.
@@ -19,7 +19,7 @@
19
19
  // 本身。memory_manager_save 受 tools/pre-execute 审批门禁。
20
20
  // 路径锚点:$DSH_HOME/tool-management/memories/<场景>/…(场景 `global` = 界面「全局」)。
21
21
  import { GLOBAL_SCENE, SHARED_GROUP } from '../memories/constants.js';
22
- import { candidateNote, effectiveScope, existingNote, globalActionNote, globalUnchangedNote, isolationOffNote, scopeOnlyNote, scopeSessionDesc, sessionScopeOf, text } from './deps.js';
22
+ import { candidateNote, effectiveScope, existingNote, globalActionNote, globalUnchangedNote, isolationOffNote, listLimit, moreNotShown, scopeOnlyNote, scopeSessionDesc, sessionScopeOf, text } from './deps.js';
23
23
  /** 注册记忆域的 model 工具(列表 / 读取 / 检索 / 切换 / 保存)。 */
24
24
  export function buildMemoryTools(deps) {
25
25
  const { defineTool, register } = deps;
@@ -33,8 +33,9 @@ export function buildMemoryTools(deps) {
33
33
  // 而 `scene` 是它在 `scene_manager_*`、`<scene>/<name>` 与注入段标题里的叫法。
34
34
  // op 的内部契约字段仍是 `group`(`rules-list` 与界面侧调用方都读它),所以 execute 里
35
35
  // 显式映射一次 —— 改 op 的字段名要动界面,那不是这一条能顺手做的事。
36
- scene: { type: 'string', description: 'Optional scene filter; `global` is the always-on scene.' },
36
+ scene: { type: 'string', description: 'Optional scene filter; `global` and `_shared` are the always-on scenes.' },
37
37
  all: { type: 'boolean', description: 'Include memories that are off, in an inactive scene, or shadowed (default false).' },
38
+ limit: { type: 'number', description: 'Max entries (default 50, max 100).' },
38
39
  },
39
40
  output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
40
41
  async execute(args, exec) {
@@ -76,7 +77,10 @@ export function buildMemoryTools(deps) {
76
77
  };
77
78
  const rows = (r.rules || []).map((x) => ({ x, ...stateOf(x) }));
78
79
  const shown = showAll ? rows : rows.filter((row) => row.injects);
79
- const lines = shown.map(({ x, label }) => ('- ' + x.id + ' [' + (x.group || 'no scene') + '] ' + label +
80
+ // 返回体也要有上限:返回值进上下文,而工具表只管 schema —— 这一笔它管不着。
81
+ const limit = listLimit(args && args.limit);
82
+ const visible = shown.slice(0, limit);
83
+ const lines = visible.map(({ x, label }) => ('- ' + x.id + ' [' + (x.group || 'no scene') + '] ' + label +
80
84
  // 形态与附件:此前不报,模型分不清哪条是 bundle、更不知道它带了几个附件
81
85
  // (`rules-list` 早就把 `form` 与 bundle 的附件摘要给了出来,只是这里没渲染)。
82
86
  (x.form === 'bundle'
@@ -108,7 +112,7 @@ export function buildMemoryTools(deps) {
108
112
  // 注入边界:压制型预设(persona complete / 关闭运行时上下文)下本插件默认不注入,
109
113
  // 此时列出的记忆**不在**模型上下文里。必须说出来,否则模型会假设自己已经看到正文。
110
114
  const notice = await deps.reachNoticeForAgent(deps.presetRoster(), exec && exec.agent && exec.agent.ctx, deps.injectNoticeOptions());
111
- return header + (lines.join('\n') || '(none)') + notice;
115
+ return header + (lines.join('\n') || '(none)') + moreNotShown(shown.length, visible.length) + notice;
112
116
  },
113
117
  }));
114
118
  register(defineTool({
@@ -261,7 +265,7 @@ export function buildMemoryTools(deps) {
261
265
  // (场景段 128 KiB),而模型很乐意把「这个项目用 pnpm」记一条 —— 那看一眼 `package.json`
262
266
  // 就知道,记下来却永久占着每一轮请求。合并 write/update 后这两句更要留:upsert 降低了
263
267
  // "再记一条"的摩擦,而摩擦正是这里唯一拦得住它的东西。
264
- description: 'Create a memory, or update the one with this id — the receipt says which. Memories cost context on every later request: record only what cannot be re-derived from code, config or git, and update an existing one rather than adding a near-duplicate. Blocked while the active scene is locked. Only on the user\'s instruction.',
268
+ description: 'Create a memory, or update the one with this id — the receipt says which. Memories cost context on every later request: record only what cannot be re-derived from code, config or git, and update an existing one rather than adding a near-duplicate. Blocked while the active scene is locked. Asks the user to confirm before it runs. Only on the user\'s instruction.',
265
269
  parameters: {
266
270
  memory: { type: 'string', required: true, description: 'Memory id like <scene>/<name> — copy it from the list. `global` is the always-on scene.' },
267
271
  description: { type: 'string', description: 'One-sentence description (<=500 chars). Required when creating. Empty string = drop it and re-derive from the body; omit = keep.' },
@@ -4,15 +4,15 @@
4
4
  // 模型可查、可切;**不能造** —— 预设正文是用户自己写的一份长文(`AGENTS.md`),
5
5
  // 模型没有创建入口,要新建只能由用户在面板里写。
6
6
  //
7
- // 删除在 `tools/remove.ts` 的 `prompt_manager_remove`(加)。此前这里写的是
7
+ // 删除在 `tools/remove.ts` 的 `plugin_manager_remove`(加)。此前这里写的是
8
8
  // 「不能造 / **不能删** —— 避免模型乱删用户预设」,那条理由针对的是**不可恢复**的删除:
9
- // 预设正文是用户手写的、删了就得重写。回收站把它的前提消掉了 —— 五条 `*_manager_remove`
10
- // 一律「进回收站、可恢复、需用户指令、过场景冻结守卫」,永久删除仍只留在面板。
9
+ // 预设正文是用户手写的、删了就得重写。回收站把它的前提消掉了 —— 那条删除工具
10
+ // 「进回收站、可恢复、需用户指令、过场景冻结守卫」,永久删除仍只留在面板。
11
11
  // 换句话说:**能删的是可恢复的那一步,不可逆的那一步照旧不给模型。**
12
12
  import { join } from 'node:path';
13
13
  import { normalizePresetDescription } from '../prompts/service.js';
14
14
  import { hasPromptOverride } from '../scope/scope-overrides.js';
15
- import { candidateNote, sessionScopeOf, text } from './deps.js';
15
+ import { candidateNote, sessionScopeOf, text, toolAccessSentence } from './deps.js';
16
16
  /** 注册提示词域的 model 工具(列表 / 读取 / 应用)。 */
17
17
  export function buildPromptTools(deps) {
18
18
  const { defineTool, register } = deps;
@@ -78,7 +78,7 @@ export function buildPromptTools(deps) {
78
78
  }));
79
79
  register(defineTool({
80
80
  name: 'prompt_manager_apply',
81
- description: 'Apply one AGENTS.md preset by id; effective next turn. When a scene drives the baseline this does not refuse — it rebinds that scene, so tell the user which one. A locked scene blocks the call. apply=false cancels instead: AGENTS.md goes back to what it was before this run of applies (removed if there was none), which a scene-driven baseline refuses — rebind the scene instead. Only on the user\'s instruction.',
81
+ description: 'Apply one AGENTS.md preset by id; effective next turn. When a scene drives the baseline this does not refuse — it rebinds that scene, so tell the user which one. A locked scene blocks the call. apply=false cancels instead: AGENTS.md goes back to what it was before this run of applies (removed if there was none), which a scene-driven baseline refuses — rebind the scene instead. Applying asks the user to confirm first; cancelling (apply=false) does not. Only on the user\'s instruction.',
82
82
  parameters: {
83
83
  // `id` 从 required 摘掉:描述一直写着 "Ignored when
84
84
  // apply=false",schema 却把它标成必填 —— 模型照描述「取消不用给 id」操作,先被 schema
@@ -142,9 +142,8 @@ export function buildPromptTools(deps) {
142
142
  : pinned === target
143
143
  ? '\nnote: that is the scene pinned here, so this scope follows it.'
144
144
  : '\nnote: this scope pins scene "' + pinned + '", so what it gets here is unchanged — this call rebound the machine-wide scene "' + shown + '". '
145
- + (deps.toolVisibleFor('scene_manager_save', exec && exec.agent)
146
- ? 'To change the binding that applies here, save scene "' + pinned + '" with that preset (scene_manager_save).'
147
- : 'To change the binding that applies here, the user has to rebind scene "' + pinned + '" in the panel.');
145
+ + 'To change the binding that applies here, save scene "' + pinned + '" with that preset'
146
+ + ' — ' + toolAccessSentence(deps, 'scene_manager_save', exec && exec.agent, 'the user has to rebind that scene in the panel') + '.';
148
147
  return 'OK: preset ' + id + ' is now the prompt binding of scene "' + shown + '" and the scene was re-synced (effective next turn; ~/.dsh/AGENTS.md now carries that scene\'s binding).' + scopeNote;
149
148
  }
150
149
  // 生效时机与宿主行为对齐(index.ts 提示词服务一节考证过):dsh-agent-instructions
@@ -1,9 +1,14 @@
1
- // 删除 / 回收站族的 model 工具:五个域各一条 `*_manager_remove`。
1
+ // 删除 / 回收站族的 model 工具:**一条** `plugin_manager_remove`(五个域共用)。
2
2
  //
3
- // 为什么单开一族:此前模型**只能停用、不能删除** —— "把这条过时的记忆删掉"这类要求手里
3
+ // 为什么要有这一族:此前模型**只能停用、不能删除** —— "把这条过时的记忆删掉"这类要求手里
4
4
  // 没有出口,模型会去调 `*_switch(enabled:false)` 然后回一句"已停用",用户以为删了。面板上
5
5
  // 每个域都有删除,模型侧一条都没有。
6
6
  //
7
+ // 为什么是**一条**而不是五个域各一条:五个域的动词、参数、回执骨架完全相同,只有名词与
8
+ // id 形状不同 —— 分成五条就是同一段文字抄五遍(≈1.1k token/轮)。合成一条后省下 ≈800 token,
9
+ // 代价是模型要多填一个 `domain`。
10
+ // ⚠️ 代价只在**全开模式**兑现:出厂默认关着的工具,schema 一分不付。
11
+ //
7
12
  // 三条纪律:
8
13
  // · **删除一律进回收站**(可恢复),与面板同一条路 —— 回执如实说"可恢复"。
9
14
  // · **不做 purge**(永久删除):低频且不可恢复,用户要求"使用频率低的可以不要,
@@ -14,22 +19,29 @@
14
19
  // 参数名统一 `id`:`trash` 时是资源标识(记忆 `<场景>/<名>`、技能名、人设名、预设 id、
15
20
  // 场景名),`restore` 时是 `action=list` 给出的**回收站条目 id** —— 两种含义在描述里写清。
16
21
  import { candidateNote, globalActionNote, locateSkillRoot, requireGlobalScope, scopeGlobalOnlyDesc, sessionLayerOn, text, toolOrNeutral, } from './deps.js';
17
- /** 三个动词共用的描述骨架。 */
18
- function removeDescription(noun) {
19
- return 'Delete one ' + noun + ' (to the trash), restore one, or list the trash. '
22
+ /**
23
+ * 三个动词共用的描述骨架(跨域版)。
24
+ *
25
+ * 五个域共用这一段,所以这里**不点名任何一个域、也不点名任何一条工具** —— 域由
26
+ * `domain` 参数说,别的工具该不该点名按可见性在运行时分叉(见 `toolOrNeutral`)。
27
+ * 静态文案点名一条模型手里没有的工具就是把它往墙上推(插件的既定纪律)。
28
+ */
29
+ function removeDescription() {
30
+ return 'Delete one item (to the trash), restore one, or list the trash. '
20
31
  + 'Deletes are recoverable; this tool never empties the trash. '
21
- + 'Blocked while the active scene is locked. Only on the user\'s instruction.';
32
+ + 'Deleting asks the user to confirm; listing the trash and restoring do not. '
33
+ + 'Blocked while the active scene is locked. '
34
+ + 'Only on the user\'s instruction.';
22
35
  }
23
36
  /** `action` 参数:三个动词 + 每个动词要哪个 `id`。 */
24
37
  const ACTION_DESC = 'trash = delete the item named by `id`; restore = put back a trash entry id (from list); list = list the trash (no `id`).';
25
- /** 删除只有全局一份(会话层没有可删的东西),四个域同一句话。 */
26
- const REMOVE_SCOPE_DESC = scopeGlobalOnlyDesc('one machine-wide copy', 'switch it off here instead');
27
38
  /**
28
- * 场景的变体:`REMOVE_SCOPE_DESC` 让模型「在本会话里把它关掉」,
29
- * 而场景根本没有「关掉」这个动作 —— `scene_manager_switch` 只有 enter / exit。照抄那一句
30
- * 会让模型去找一个不存在的开关,或者干脆回一句「做不到」。
39
+ * 删除只有全局一份(会话层没有可删的东西),五个域同一句话。
40
+ *
41
+ * 「改用开关停掉」那句只写通配形式:五个域里只有记忆 / 技能 / 人设有对应的开关,
42
+ * 场景没有「关掉」这个动作(退出是另一件事,见 `sceneExitNote`),预设根本没有开关。
31
43
  */
32
- const REMOVE_SCOPE_DESC_SCENE = scopeGlobalOnlyDesc('the scene record and archive are machine-wide', 'exit it here with scene_manager_switch (action=exit)');
44
+ const REMOVE_SCOPE_DESC = scopeGlobalOnlyDesc('these items have one machine-wide copy', 'to stop one being used instead, switch it off with the matching *_manager_switch');
33
45
  /**
34
46
  * 恢复 op 回传的**最终落盘名**。五个域把名字放在不同字段上:
35
47
  * · 记忆 / 技能 / 人设 / 场景 → `name`(退号恢复时它是新名字,不是回收站里的原名)
@@ -54,6 +66,14 @@ function restoredName(r) {
54
66
  };
55
67
  return pick(r) || pick(r && r.data);
56
68
  }
69
+ /**
70
+ * 一条删除工具的 execute:三个动词的分派与回执。
71
+ *
72
+ * 会话层:删除是**全局**动作 —— 技能正文、人设 `.md`、场景档案、MCP 补丁
73
+ * 提示词预设都只有一份,没有「本会话的副本」,所以这一格的口径就是「全局动作」。
74
+ * 所以这里不写会话层,只在**这个对话真有该域覆盖**时补一句尾注:
75
+ * 删完之后那条会话覆盖还在(读时忽略,对账才清),不说明的话用户会以为它跟着没了。
76
+ */
57
77
  async function runRemove(deps, cfg, args, agent, isMemoryId) {
58
78
  const action = String((args && args.action) || '');
59
79
  if (action !== 'trash' && action !== 'restore' && action !== 'list') {
@@ -95,15 +115,19 @@ async function runRemove(deps, cfg, args, agent, isMemoryId) {
95
115
  // 只按形状(`a/b`)判会误伤 —— 场景名与技能名都没有禁止斜杠的校验,用户起的名字里
96
116
  // 完全可能出现。所以这里读一次记忆库确认存在;读不到就当不是,宁可少说一句。
97
117
  if (action === 'trash' && cfg.domain !== 'memory' && id.indexOf('/') > 0 && await isMemoryId(id)) {
98
- throw new Error('"' + id + '" is a memory id (memory ids are <scene>/<name>); this tool handles ' + cfg.noun + 's.'
99
- + toolOrNeutral(deps, agent, 'memory_manager_remove', ' Use `memory_manager_remove` with action=trash for it.', ' Pass it to the memory manager instead — this one only handles ' + cfg.noun + 's.'));
118
+ // 五个域合进一条之后,这条错误只差一个 domain —— 说的是同一个工具,不必绕。
119
+ throw new Error('"' + id + '" is a memory id (memory ids are <scene>/<name>), but domain=' + cfg.domain
120
+ + ' handles ' + cfg.noun + 's. Call this tool again with domain=memory (action=trash) for it.');
100
121
  }
101
122
  const r = action === 'trash' ? await cfg.trash(args) : await cfg.restore(args);
102
123
  if (!r || r.ok === false)
103
124
  throw new Error((r && r.error) || (action === 'trash' ? 'failed to move it to the trash' : 'restore failed'));
104
125
  if (action === 'trash') {
105
- return 'OK: ' + cfg.label + ' "' + id + '" moved to the trash (recoverable; permanent deletion lives in the panel trash)' +
106
- (cfg.domain === undefined ? '' : globalActionNote(deps, agent, cfg.domain, cfg.label));
126
+ // 永久删除是**刻意不给模型**的(不可恢复,且低频)—— 但这句话是给模型看的,
127
+ // 说清「这里只到回收站」就够,不必把人推去面板。
128
+ return 'OK: ' + cfg.label + ' "' + id + '" moved to the trash (recoverable; permanent deletion is not offered here)' +
129
+ (cfg.domain === undefined ? '' : globalActionNote(deps, agent, cfg.domain, cfg.label)) +
130
+ sceneExitNote(deps, agent, cfg.domain);
107
131
  }
108
132
  // 恢复的回执要说**恢复成了什么**,而不是回收站条目 id:
109
133
  // `id` 是 `action=list` 给的那一串(记忆 `mv…`、技能 `<时间戳>-<uuid>`),模型看到它
@@ -112,7 +136,21 @@ async function runRemove(deps, cfg, args, agent, isMemoryId) {
112
136
  return 'OK: restored ' + cfg.label + ' "' + name + '" from the trash' +
113
137
  (name === id ? '' : ' (trash entry ' + id + ')');
114
138
  }
115
- /** 注册删除类工具:技能 / 人设 / 场景三种对象各一个动词。 */
139
+ /**
140
+ * 删掉场景之后的补充:场景删了**不等于离开了当前场景**。
141
+ *
142
+ * 退出是另一件事(`scene_manager_switch` action=exit),而那条工具出厂关着 ——
143
+ * 静态描述里点名它就是在指一条模型手里没有的工具,所以这句话按可见性分叉:
144
+ * 看得见就点名,看不见就退回中性说法(工具面的一致纪律,见 `toolOrNeutral`)。
145
+ *
146
+ * 只有场景域需要这一句:其余四个域删掉的就是「不再被使用」,没有「留在里面」这回事。
147
+ */
148
+ function sceneExitNote(deps, agent, domain) {
149
+ if (domain !== 'scene')
150
+ return '';
151
+ return ' ' + toolOrNeutral(deps, agent, 'scene_manager_switch', 'You are still in it — leave it with scene_manager_switch (action=exit).', 'You are still in it — leaving it is a separate action, and the scene tools are off here.');
152
+ }
153
+ /** 注册删除类工具:五个域共用一条 `plugin_manager_remove`(按 `domain` 分派)。 */
116
154
  export function buildRemoveTools(deps) {
117
155
  const { defineTool, register } = deps;
118
156
  const mem = deps.memoryOps;
@@ -257,60 +295,41 @@ export function buildRemoveTools(deps) {
257
295
  },
258
296
  },
259
297
  };
298
+ // 五个域的配置表:一条工具按 `domain` 取用哪一份。
299
+ const cfgs = {
300
+ memory: memoryCfg,
301
+ skill: skillCfg,
302
+ persona: subagentCfg,
303
+ preset: promptCfg,
304
+ scene: sceneCfg,
305
+ };
260
306
  register(defineTool({
261
- name: 'memory_manager_remove',
262
- description: removeDescription('memory'),
263
- parameters: {
264
- action: { type: 'string', required: true, enum: ['trash', 'restore', 'list'], description: ACTION_DESC },
265
- id: { type: 'string', description: 'For trash: the memory id `<scene>/<name>`; for restore: a trash entry id; omit for list.' },
266
- scope: { type: 'string', enum: ['session', 'global'], description: REMOVE_SCOPE_DESC },
267
- },
268
- output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
269
- async execute(args, exec) { return runRemove(deps, memoryCfg, args, exec && exec.agent, isMemoryId); },
270
- }));
271
- register(defineTool({
272
- name: 'skill_manager_remove',
273
- description: removeDescription('skill'),
274
- parameters: {
275
- action: { type: 'string', required: true, enum: ['trash', 'restore', 'list'], description: ACTION_DESC },
276
- id: { type: 'string', description: 'For trash: the skill name; for restore: a trash entry id; omit for list.' },
277
- scope: { type: 'string', enum: ['session', 'global'], description: REMOVE_SCOPE_DESC },
278
- root: { type: 'string', description: 'Source root the skill lives in. Default: whichever source holds that skill; only used by action=trash.' },
279
- },
280
- output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
281
- async execute(args, exec) { return runRemove(deps, skillCfg, args, exec && exec.agent, isMemoryId); },
282
- }));
283
- register(defineTool({
284
- name: 'subagent_manager_remove',
285
- description: removeDescription('persona'),
307
+ name: 'plugin_manager_remove',
308
+ description: removeDescription(),
286
309
  parameters: {
287
310
  action: { type: 'string', required: true, enum: ['trash', 'restore', 'list'], description: ACTION_DESC },
288
- id: { type: 'string', description: 'For trash: the persona name; for restore: a trash entry id; omit for list.' },
311
+ domain: {
312
+ type: 'string', required: true, enum: ['memory', 'skill', 'persona', 'preset', 'scene'],
313
+ description: 'Which kind of item: memory | skill | persona | preset | scene. Their ids differ — '
314
+ + 'memory is `<scene>/<name>`, the others are a plain name (a preset uses its id).',
315
+ },
316
+ id: {
317
+ type: 'string',
318
+ description: 'For trash: that item\'s id (`<scene>/<name>` for memory, a name for skill/persona/scene, '
319
+ + 'the preset id for preset); for restore: a trash entry id from action=list for that domain; omit for list.',
320
+ },
289
321
  scope: { type: 'string', enum: ['session', 'global'], description: REMOVE_SCOPE_DESC },
322
+ root: { type: 'string', description: 'Source root the skill lives in — skills only. Default: whichever source holds that skill; only used by action=trash.' },
290
323
  },
291
324
  output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
292
- async execute(args, exec) { return runRemove(deps, subagentCfg, args, exec && exec.agent, isMemoryId); },
293
- }));
294
- register(defineTool({
295
- name: 'prompt_manager_remove',
296
- description: removeDescription('AGENTS.md preset'),
297
- parameters: {
298
- action: { type: 'string', required: true, enum: ['trash', 'restore', 'list'], description: ACTION_DESC },
299
- id: { type: 'string', description: 'For trash: the preset id; for restore: a trash entry id; omit for list.' },
300
- scope: { type: 'string', enum: ['session', 'global'], description: scopeGlobalOnlyDesc('a preset writes the one global baseline', 'there is nothing per-conversation to delete') },
301
- },
302
- output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
303
- async execute(args, exec) { return runRemove(deps, promptCfg, args, exec && exec.agent, isMemoryId); },
304
- }));
305
- register(defineTool({
306
- name: 'scene_manager_remove',
307
- description: removeDescription('scene'),
308
- parameters: {
309
- action: { type: 'string', required: true, enum: ['trash', 'restore', 'list'], description: ACTION_DESC },
310
- id: { type: 'string', description: 'For trash: the scene name; for restore: a trash entry id; omit for list.' },
311
- scope: { type: 'string', enum: ['session', 'global'], description: REMOVE_SCOPE_DESC_SCENE },
325
+ async execute(args, exec) {
326
+ const domain = String((args && args.domain) || '').trim();
327
+ const cfg = cfgs[domain];
328
+ if (cfg === undefined) {
329
+ throw new Error('missing argument: domain — one of ' + Object.keys(cfgs).join(', ')
330
+ + ' (which kind of item to trash, restore or list)');
331
+ }
332
+ return runRemove(deps, cfg, args, exec && exec.agent, isMemoryId);
312
333
  },
313
- output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
314
- async execute(args, exec) { return runRemove(deps, sceneCfg, args, exec && exec.agent, isMemoryId); },
315
334
  }));
316
335
  }