dsh-plugin-tool-management 0.22.6 → 0.22.7

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.
@@ -88,13 +88,13 @@ export function buildEvolutionOps(deps) {
88
88
  const sessionRecord = sessionId ? sessions.sessions[sessionId] : undefined;
89
89
  // 自动记忆实况:只报计数,不把正文塞进状态回执(它会被界面高频轮询)。
90
90
  const view = runtime.view();
91
+ // 目录最近一次没更新成功的原因。catalog 是派生数据,失败不影响真相,但**会影响注入**:
92
+ // 界面必须能区分"记忆被删了"与"目录没跟上",否则用户只能看到条数凭空空掉。
93
+ const catalogDegraded = deps.learner?.catalogDegraded();
91
94
  const entries = Object.values(view.catalog.entries);
92
- // 两个数分开报:`pendingReview` 是「等你裁决」(不注入),`reviewDue` 是「该看一眼」
93
- // (照常注入)。合成一个数字,用户会以为生效中的条目也在等他处理。
94
- const pendingReview = entries.filter((e) => {
95
- const st = view.state.entries[e.id];
96
- return st && typeof st.pendingReason === 'string' && st.pendingReason !== '';
97
- }).length;
95
+ // 待复核与「已学 / 生效 / 待确认」分开报:`reviewDue` 是「该看一眼」,仍照常注入;
96
+ // `pending` 是候选数(等用户裁决),不要拿 `pendingReason` 的条数混进去 —— 合成一个
97
+ // 数字,用户会以为生效中的条目也在等他处理。
98
98
  const reviewDue = entries.filter((e) => {
99
99
  const st = view.state.entries[e.id];
100
100
  return st && typeof st.reviewDue === 'string' && st.reviewDue !== '';
@@ -129,21 +129,22 @@ export function buildEvolutionOps(deps) {
129
129
  // `byLayer` / `byStatus` 不在这里返回:它们是维护扫描的诊断口径,而 `evolution-health`
130
130
  // 已经给了完整一份。放在 status 里从来没有消费者 —— 一个没人读的字段比不存在更糟,
131
131
  // 它会让下一个人以为界面上有这张图。
132
- pendingReview,
133
132
  reviewDue,
134
133
  pending,
135
134
  archived,
136
135
  broken: view.broken,
136
+ // 有原因才给字段:空串会被界面当成"降级了但没原因",与"没降级"分不开。
137
+ ...(catalogDegraded !== undefined ? { catalogDegraded } : {}),
137
138
  active: entries.filter((e) => e.enabled && isInjectableStatus(e.status)).length,
138
- // 页头「注入预算」用的真实字节数。
139
+ // 页头「注入预算」里**记忆域**的实际字节数。
139
140
  //
140
141
  // 界面自己按 `injects` + 层开关 + 当前工作区累加是**算不准**的:注入侧还要过
141
142
  // 「按渲染块实际字节记账」与「预算装不下就整条让位」两道闸,实际进上下文的比那个和大。
142
143
  // 两个数字对不上时,用户看到的"还剩 30 KiB"与模型看到的上下文会互相矛盾。
143
144
  // 这里直接按注入侧同一份口径算一遍,界面只做展示。
144
145
  // 没接这个回调(单测 / 老装配)时**不给这个字段**,而不是给 0:
145
- // 0 会被界面当成"自主记忆不占字节",于是页头报的用量偏小、超限也不转红。
146
- // 缺字段时界面退回本地累加(会略高估,但不会漏报)。
146
+ // 0 会被界面当成"记忆不占字节",于是页头报的用量偏小、超限也不转红。
147
+ // 缺字段时界面只能显示"未知",不要拿 0 或本地累加顶上去。
147
148
  ...(deps.injectBytesOf === undefined
148
149
  ? {}
149
150
  : { injectBytes: await deps.injectBytesOf(scopeKey, sessionId) }),
@@ -178,8 +179,6 @@ export function buildEvolutionOps(deps) {
178
179
  next.learnWorkspace = patch.enabled;
179
180
  if (typeof patch.autoConfirm === 'boolean')
180
181
  next.autoConfirm = patch.autoConfirm;
181
- if (typeof patch.inject === 'boolean')
182
- next.inject = patch.inject;
183
182
  if (typeof patch.maxReviewsPerSession === 'number')
184
183
  next.maxReviewsPerSession = patch.maxReviewsPerSession;
185
184
  // 学习频率:窗口分钟数与每窗口条数;`null` = 回出厂值(空框语义)。
@@ -449,10 +448,11 @@ export function buildEvolutionOps(deps) {
449
448
  }
450
449
  },
451
450
  /**
452
- * 复核一条:清掉「待复核」标记并重置计时。
451
+ * 复核一条:清掉「待复核」标记并重置老化计时。
453
452
  *
454
453
  * 只清标记不重置时间的话,下一次扫描会立刻按旧时间再挂一次 —— 用户会觉得点了没反应。
455
- * 用户改正文(`evolution-update`)同样会重置,所以这里只服务"内容没变、确认仍然对"。
454
+ * 重置的是 state 里的 `reviewedAt`,**不是文件里的 `auto_updated`**:复核没有改正文,
455
+ * 写成"刚刚更新"会让列表与 catalog 一起说谎。用户改正文(`evolution-update`)另算。
456
456
  */
457
457
  'evolution-review': async (args) => {
458
458
  if (!learner)
@@ -498,9 +498,18 @@ export function buildEvolutionOps(deps) {
498
498
  }
499
499
  status = wanted;
500
500
  }
501
- else {
501
+ else if (typeof args?.enabled === 'boolean') {
502
502
  // 只给了 `enabled` 的旧调用方:开关语义 = 归档 / 恢复。
503
- status = args?.enabled === false ? 'archived' : 'active';
503
+ status = args.enabled ? 'active' : 'archived';
504
+ }
505
+ else {
506
+ // 两个都没给:**拒绝**,不要兜底成 `active`。一次缺参调用不该把一条归档的
507
+ // 记忆重新激活 —— 那是"什么都没传,它自己开始注入"的静默副作用。
508
+ return {
509
+ ok: false,
510
+ error: 'missing status — pass status ("active" / "candidate" / "archived") or enabled (true / false)',
511
+ code: 'bad-args',
512
+ };
504
513
  }
505
514
  const result = await learner.setStatus(id, status, 'user');
506
515
  if (result && result.ok)
@@ -181,9 +181,12 @@ export function createCandidates(deps) {
181
181
  }
182
182
  }
183
183
  /**
184
- * 记忆候选(档案编辑器第 4 段「记忆」):`[{ id, scene, name, description, attach? }]`。
184
+ * 记忆候选(档案编辑器第 4 段「记忆」):`[{ id, scene, name, excerpt, description, attach? }]`。
185
185
  * 只读、不读正文(勾选集只存 id);任何异常降级为空列表,不让档案弹窗崩掉。
186
186
  *
187
+ * `excerpt` 是服务端从正文首行截出的摘要,供选择器扫读;`description` 是旧字段,
188
+ * 规则本身没有独立说明,保留只为兼容旧的读取方。
189
+ *
187
190
  * `attach` 是宿主在 `rules-list` 里给 bundle 记忆补的附件摘要,这里原样带过去 ——
188
191
  * 场景编辑器要在行上标一枚回形针,让用户看见"勾这条会连带把参考资料一起带进场景"。
189
192
  */
@@ -198,6 +201,7 @@ export function createCandidates(deps) {
198
201
  id: String(x.id),
199
202
  scene: String(x.group || ''),
200
203
  name: String(x.name || ''),
204
+ excerpt: String(x.excerpt || ''),
201
205
  description: String(x.description || ''),
202
206
  ...(x.attach ? { attach: x.attach } : {}),
203
207
  }));
@@ -281,10 +281,10 @@ export function createRunProvider(deps) {
281
281
  stopWatching = typeof stop === 'function' ? stop : () => undefined;
282
282
  }
283
283
  const startSignal = signal ?? new AbortController().signal;
284
- // 激活请求在两代宿主上是两种形状:一代把任务字段装在 `request` 里,一代把它们平铺在顶层。
285
- // 官方 `SubagentActivationSpec extends Omit<SubagentStartRequest, 'label' | 'signal'>`:
286
- // 字段全在**最外层**(`cwd` / `prompt` / `parent` / `agentPreset` / `agentOptions` /
287
- // `maxDepth`),没有嵌套的 `request`。所以这里拼成一份扁平载荷。
284
+ // 激活请求的任务字段平铺在**最外层**(`SubagentActivationSpec extends Omit<SubagentStartRequest,
285
+ // 'label' | 'signal'>`:`cwd` / `prompt` / `parent` / `agentPreset` / `agentOptions` / `maxDepth`)。
286
+ // rc.1 及更早把它们装在嵌套的 `request` 里,本插件不支持那种形状 —— 适配范围下界因此落在
287
+ // rc.2(见 `compat/probe.ts` 的 EXPECTED_PEER_RANGE)。所以这里拼成一份扁平载荷。
288
288
  const request = {
289
289
  parent: parentAgent,
290
290
  prompt: [{ type: 'text', text: kind === 'fork' ? renderPersonaPrompt(p) + '\n\n' + task : task }],
package/lib/text-width.js CHANGED
@@ -13,8 +13,14 @@ export function isWideCodePoint(code) {
13
13
  (code >= 0xfe30 && code <= 0xfe6f) ||
14
14
  (code >= 0xff00 && code <= 0xff60) ||
15
15
  (code >= 0xffe0 && code <= 0xffe6) ||
16
- (code >= 0x1f300 && code <= 0x1f64f) ||
17
- (code >= 0x1f900 && code <= 0x1f9ff) ||
16
+ // BMP 里的图形符号:☀ ✅ ⭐ ❤ 这类常见 emoji 不在补充平面,漏掉会让按宽度
17
+ // 截断的标题 / 摘要比上限多出几个单位。区间里有窄符号,按宽算只是把上限估严一点。
18
+ (code >= 0x2600 && code <= 0x27bf) ||
19
+ (code >= 0x2b00 && code <= 0x2bff) ||
20
+ // 补充平面上的图形符号整段按宽算:emoji 散落在几十个块里(火箭、乐器、棋子、
21
+ // 区域指示符、符号扩展……),只挑几段必然漏。区间内少量未分配码点按宽算是把上限
22
+ // 估严一点,不会把字符切坏。
23
+ (code >= 0x1f000 && code <= 0x1fbff) ||
18
24
  (code >= 0x20000 && code <= 0x3fffd));
19
25
  }
20
26
  /** 单个字符的显示宽度(2 = 宽字符,1 = 其它)。 */
@@ -6,8 +6,9 @@ import { addPreset, applyToolTableToggles, buildToolTableReport, classifyToolTab
6
6
  export function createToolTableSwitch(deps) {
7
7
  // ---------- 模型工具表开关(侧车 `tool-table.json`,界面在「兼容」页)----------
8
8
  // 工具表按**每个请求**付钱:整张表的定义合计 ≈6.1k tok 每轮都在。关掉某几个,
9
- // 它们整份不进请求(实测口径与取舍见 src/tools/table.ts 的文件头)。**出厂就已经关了十八条**
10
- // (23 条里实发 5 条)—— 名单、判据与代价在 `DEFAULT_HIDDEN_TOOLS`,只在这个人从没记过
9
+ // 它们整份不进请求(实测口径与取舍见 src/tools/table.ts 的文件头)。**出厂就已经关了十八条**:
10
+ // 可勾选的 22 条里藏 17 条(实发 5 条),第十八条是自主笔记、跟随记忆页的总开关(开则实发 6 条)
11
+ // —— 名单、判据与代价在 `DEFAULT_HIDDEN_TOOLS`,只在这个人从没记过
11
12
  // 选择时铺(见下面的 `toolTableSettingsFrom`)。
12
13
  //
13
14
  // 为什么放在目录之前:两个目录的「用 `X` 查」提示要跟着这份设置变(工具关掉后那句话
@@ -117,7 +118,7 @@ export function createToolTableSwitch(deps) {
117
118
  }
118
119
  /**
119
120
  * 同步快照(热路径用:工具门禁每次调用、注入通道每个 step 都要问一句)。还没加载时先给
120
- * **空集**并异步预热 —— 空集不是出厂默认(出厂关着十四条),是刻意的:预热前的这一瞬与
121
+ * **空集**并异步预热 —— 空集不是出厂默认(出厂在 22 条里关着十七条),是刻意的:预热前的这一瞬与
121
122
  * 用户的选择可能不一致,但方向必须是安全的那一侧(不隐藏任何东西,绝不因为读盘慢而让
122
123
  * 工具凭空消失)。
123
124
  */
@@ -128,11 +129,22 @@ export function createToolTableSwitch(deps) {
128
129
  }
129
130
  return toolTableCache.off;
130
131
  }
131
- // 自主记忆那条工具不进报表:它不出现在面板里,也不该出现在分组计数 / 体积合计里。
132
- const toolTableRows = () => [...toolTableSizes]
133
- .filter(([name]) => name !== PROACTIVE_MEMORY_TOOL)
134
- .map(([name, bytes]) => ({ name, bytes }));
135
- const toolTableReport = (hidden = [...toolTableHidden()]) => buildToolTableReport(toolTableRows(), hidden, deps.carrierHiddenTools ? deps.carrierHiddenTools() : []);
132
+ // 行集是可勾选的那 22 条:自主笔记那条**故意不在里面**(它没有手动开关,开关在记忆页)。
133
+ // 把它塞进来会让界面多画一行改不动的勾选,而"这条在不在表里"与"它发不发"是两件事。
134
+ // 实际发送由 `withProactiveTool` 在总开关开着时补上,报告用 `derived` / `sentCount` 交代。
135
+ const toolTableRows = () => [...toolTableSizes].filter(([name]) => name !== PROACTIVE_MEMORY_TOOL).map(([name, bytes]) => ({ name, bytes }));
136
+ /**
137
+ * 当前生效的关停名单(只含用户手动关的)。
138
+ *
139
+ * 报表与真实发送必须同一口径:自主笔记那条不在这份名单里(用户改不了),报告通过
140
+ * `derived` 单独说它开没开。顺手摘掉旧文件残留的名字 —— 读侧已经摘过一次,这里是第二道。
141
+ */
142
+ const effectiveHidden = (hidden = [...toolTableHidden()]) => stripProactiveToolHidden(hidden);
143
+ const toolTableReport = (hidden) => buildToolTableReport(toolTableRows(), effectiveHidden(hidden), deps.carrierHiddenTools ? deps.carrierHiddenTools() : [], {
144
+ name: PROACTIVE_MEMORY_TOOL,
145
+ active: proactiveOn() && toolTableSizes.has(PROACTIVE_MEMORY_TOOL),
146
+ bytes: toolTableSizes.get(PROACTIVE_MEMORY_TOOL) ?? 0,
147
+ });
136
148
  /** 落盘 + 同步内存缓存;调用方必须已持有写锁。 */
137
149
  async function writeToolTableSettingsLocked(next) {
138
150
  // 锁内再确认一次:外部编辑器可能在这几毫秒里把文件写坏。此时覆盖同样会毁掉原内容。
@@ -51,6 +51,33 @@ export function buildMemoryTools(deps) {
51
51
  throw new Error('missing op: ' + name + ' (the plugin is only partly assembled)');
52
52
  return fn;
53
53
  };
54
+ // 开关决定能力面:关掉的层连 `layer` 参数都不该出现。省略依赖时按两层都开处理,
55
+ // 让旧装配 / 单元测试保持原行为。
56
+ const noteLayersOf = (agent) => {
57
+ const got = deps.autoNoteLayers ? deps.autoNoteLayers(agent) : undefined;
58
+ return got ?? { global: true, workspace: true };
59
+ };
60
+ const noteReadLayersOf = (agent) => {
61
+ const got = deps.autoNoteReadLayers
62
+ ? deps.autoNoteReadLayers(agent)
63
+ : deps.autoNoteLayers ? deps.autoNoteLayers(agent) : undefined;
64
+ return got ?? { global: true, workspace: true };
65
+ };
66
+ // 只有两层都开时层才是模型要选的东西;只剩一层时强制那一层,schema 里不留 `layer`。
67
+ const noteLayerParameter = {
68
+ type: 'string',
69
+ enum: ['global', 'workspace'],
70
+ description: 'global = every project; workspace = this project. Omit when unsure: the user chooses the layer on the card, or its default applies.',
71
+ };
72
+ const applyNoteLayerSchema = (tool, layers) => {
73
+ const properties = tool && tool.parameters && tool.parameters.properties;
74
+ if (!properties)
75
+ return;
76
+ if (layers.global && layers.workspace)
77
+ properties.layer = noteLayerParameter;
78
+ else
79
+ delete properties.layer;
80
+ };
54
81
  /**
55
82
  * 这条规则是不是自主笔记而不是用户记忆。
56
83
  *
@@ -206,15 +233,16 @@ export function buildMemoryTools(deps) {
206
233
  }
207
234
  return lines.join('\n');
208
235
  };
209
- const noteCatalogText = async (all, limit) => {
236
+ const noteCatalogText = async (all, limit, layers) => {
210
237
  if (!evo)
211
238
  return '';
212
239
  const r = await opOf(evo, 'evolution-list')({ all });
213
240
  if (!r || r.ok === false)
214
241
  throw new Error(String((r && r.error) || 'failed to read agent notes'));
215
- const rows = Array.isArray(r.entries) ? r.entries : [];
242
+ const rows = (Array.isArray(r.entries) ? r.entries : [])
243
+ .filter((e) => e.layer === 'workspace' ? layers.workspace : layers.global);
216
244
  const shown = rows.slice(0, limit);
217
- const order = ['workspace', 'global'];
245
+ const order = ['workspace', 'global'].filter((l) => l === 'workspace' ? layers.workspace : layers.global);
218
246
  const lines = [];
219
247
  for (const layer of order) {
220
248
  const group = shown.filter((e) => e.layer === layer);
@@ -238,12 +266,14 @@ export function buildMemoryTools(deps) {
238
266
  (e.oneLine ? ' — ' + String(e.oneLine) : ''));
239
267
  }
240
268
  }
269
+ // 总数只在两层都开时可信:只剩一层时 `r.total` 含已关层的条目,报出来就是泄漏。
270
+ const both = layers.global && layers.workspace;
241
271
  const head = 'agent notes: ' + rows.length + ' listed' +
242
- (r.total !== undefined ? ' / ' + r.total + ' in catalog' : '') +
272
+ (both && r.total !== undefined ? ' / ' + r.total + ' in catalog' : '') +
243
273
  (rows.length > shown.length ? ' (showing ' + shown.length + ', raise limit for more)' : '');
244
274
  return head + '\n' + (lines.join('\n') || '(none)');
245
275
  };
246
- const noteSearchText = async (query, limit) => {
276
+ const noteSearchText = async (query, limit, layers) => {
247
277
  if (!evo)
248
278
  return '';
249
279
  // 与用户记忆搜索同口径:搜索覆盖归档 / 未注入的条目,`all` 只影响清单。
@@ -252,7 +282,9 @@ export function buildMemoryTools(deps) {
252
282
  if (!r || r.ok === false)
253
283
  throw new Error(String((r && r.error) || 'failed to read agent notes'));
254
284
  const words = query.toLowerCase().split(/\s+/).filter((w) => w !== '');
255
- const rows = (Array.isArray(r.entries) ? r.entries : []).filter((e) => {
285
+ const rows = (Array.isArray(r.entries) ? r.entries : [])
286
+ .filter((e) => e.layer === 'workspace' ? layers.workspace : layers.global)
287
+ .filter((e) => {
256
288
  // `kind` 也要能搜:结果行里印着它(「列出所有做法类笔记」是很自然的请求),
257
289
  // 只显示不索引等于「看得见、搜不到」。类型是四个固定词,不会污染正文匹配。
258
290
  const hay = [e.id, e.key, e.title, e.oneLine, e.body, e.boundary, e.alias, e.kind]
@@ -452,7 +484,8 @@ export function buildMemoryTools(deps) {
452
484
  // 自主记忆关着时,笔记不在这份清单里出现:功能没开,模型不该看到「有笔记可读」
453
485
  // 这种半开状态(直接给 note: id 仍然读得到 —— 那是显式请求)。
454
486
  const readable = deps.autoNotesReadable ?? deps.autoLearnEnabled;
455
- const notesOn = Boolean(evo && readable && readable(exec && exec.agent));
487
+ const readLayers = noteReadLayersOf(exec && exec.agent);
488
+ const notesOn = Boolean(evo && readable && readable(exec && exec.agent) && (readLayers.global || readLayers.workspace));
456
489
  if (kind === 'note' && !notesOn) {
457
490
  throw new Error('autonomous memory is off here, so agent notes are not available. The user can turn it on in Memory → Autonomous memory.');
458
491
  }
@@ -463,7 +496,7 @@ export function buildMemoryTools(deps) {
463
496
  : await userCatalogText(all, limit, scene, exec));
464
497
  }
465
498
  if (kind !== 'memory' && notesOn) {
466
- sections.push(query !== '' ? await noteSearchText(query, limit) : await noteCatalogText(all, limit));
499
+ sections.push(query !== '' ? await noteSearchText(query, limit, readLayers) : await noteCatalogText(all, limit, readLayers));
467
500
  }
468
501
  return sections.filter((s) => s !== '').join('\n\n') || '(none)';
469
502
  },
@@ -904,11 +937,11 @@ export function buildMemoryTools(deps) {
904
937
  // 用户记忆是多段、按场景走。读取统一走 `memory_get`,这里只保留写入与删除。
905
938
  // 弹卡策略:自动确认关 → 每次都问;开 → 不弹卡,由 agent 决定。生效判断在 gates 的 `autoActive`。
906
939
  if (!deps.evolutionOps || !deps.autoLearnEnabled)
907
- return;
940
+ return { refreshNoteSchema() { } };
908
941
  const noteOps = deps.evolutionOps;
909
- register(defineTool({
942
+ const noteToolDef = defineTool({
910
943
  name: PROACTIVE_MEMORY_TOOL,
911
- description: 'Agent notes (autonomous memory) — one-line notes YOU decided are worth keeping across conversations: a preference, a fact, a correction of your behaviour, or a repeatable procedure. Use this for your own judgement; when the user explicitly asks you to remember something, use memory_remember instead (that is their asset, this is your cache).\n\nWrite it in one call and move on. If a call is refused, the reply names every problem at once — fix them in one retry, or drop the note and get back to the task. Do not reword the same idea repeatedly: a note that keeps failing is one the user did not need.\n\nRecord what will still hold in a different conversation, and nothing else:\n- A one-off ("this time", "for now", "next step") is not a note.\n- Something re-derivable from the code or config (dependency versions, file lists, config values) is not a note — read the file instead.\n- Say the thing itself, in words. Fragments, markup, and pure punctuation are refused.\n\nlearn: `title` (2-8 words) + `text` (<=1200 Chinese chars / 2400 letters; 1-2 clear sentences, or follow the style line in the learned-notes section); `kind` — preference / fact / correction / procedure (it sets the review interval: fact and procedure are re-checked after 30 days, preference and correction never expire, so a procedure filed as a correction stays forever); `layer` global = every project / workspace = this one; pass `slot` (a stable name) when you may update or forget it later; pass `quote` (their exact words) when you are recording something the user actually said — it is checked verbatim against this conversation, and if it does not match the note is still saved but with weaker evidence, so quote exactly when you can.\n\nEvery note shows the user a card unless they turned auto-confirm on. Check for an existing note on the same thing first (the memory read tool with kind=note lists them) — two notes saying the same thing in different words are both injected into every later conversation, and the duplicate check compares wording, not meaning. forget: `note` = id (note:...), slot, title, or the first line as it was injected. Inspect notes with the memory read tool.',
944
+ description: 'Agent notes (autonomous memory) — one-line notes YOU decided are worth keeping across conversations: a preference, a fact, a correction of your behaviour, or a repeatable procedure. Use this for your own judgement; when the user explicitly asks you to remember something, use memory_remember instead (that is their asset, this is your cache).\n\nWrite it in one call and move on. If a call is refused, the reply names every problem at once — fix them in one retry, or drop the note and get back to the task. Do not reword the same idea repeatedly: a note that keeps failing is one the user did not need.\n\nRecord what will still hold in a different conversation, and nothing else:\n- A one-off ("this time", "for now", "next step") is not a note.\n- Something re-derivable from the code or config (dependency versions, file lists, config values) is not a note — read the file instead.\n- Say the thing itself, in words. Fragments, markup, and pure punctuation are refused.\n\nlearn: `title` (2-8 words) + `text` (<=1200 Chinese chars / 2400 letters; 1-2 clear sentences, or follow the style line in the learned-notes section); `kind` — preference / fact / correction / procedure (it sets the review interval: fact and procedure are re-checked after 30 days, preference and correction never expire, so a procedure filed as a correction stays forever); pass `slot` (a stable name) when you may update or forget it later; pass `quote` (their exact words) when you are recording something the user actually said — it is checked verbatim against this conversation, and if it does not match the note is still saved but with weaker evidence, so quote exactly when you can.\n\nEvery note shows the user a card unless they turned auto-confirm on. Check for an existing note on the same thing first (the memory read tool with kind=note lists them) — two notes saying the same thing in different words are both injected into every later conversation, and the duplicate check compares wording, not meaning. forget: `note` = id (note:...), slot, title, or the first line as it was injected. Inspect notes with the memory read tool.',
912
945
  parameters: {
913
946
  action: { type: 'string', enum: ['learn', 'forget'], required: true, description: 'learn or forget.' },
914
947
  // ── learn ──
@@ -917,7 +950,6 @@ export function buildMemoryTools(deps) {
917
950
  quote: { type: 'string', description: 'learn: the user\'s exact words, copied verbatim, when you are recording something they said. Checked against this conversation; a quote that does not match does not fail the call — the note is kept with weaker evidence. Omit it for your own inferences.' },
918
951
  slot: { type: 'string', description: 'learn: optional stable slot name; learning again with the same slot merges when it says the same thing, and replaces the old note when it conflicts.' },
919
952
  boundary: { type: 'string', description: 'learn: optional; when it may not hold.' },
920
- layer: { type: 'string', enum: ['global', 'workspace'], description: 'learn: global (every project) or workspace (this project). Omit only when unsure; the card asks, or auto-confirm uses the default.' },
921
953
  ttlDays: { type: 'number', description: 'learn: optional; re-check after N days.' },
922
954
  // `kind` 决定保质期(事实 / 做法 30 天后提醒复核,偏好 / 纠正不过期)。不给时由
923
955
  // `inferKind` 按措辞猜,而它只能看字面 —— 「必须 / 不要」这类约束词会把做法误判成
@@ -971,6 +1003,21 @@ export function buildMemoryTools(deps) {
971
1003
  }
972
1004
  if (action !== 'learn')
973
1005
  throw new Error('unknown action: ' + action + ' (expected learn / forget)');
1006
+ const layers = noteLayersOf(agent);
1007
+ const onlyLayer = layers.global && !layers.workspace ? 'global'
1008
+ : layers.workspace && !layers.global ? 'workspace' : undefined;
1009
+ const askedLayer = args && typeof args.layer === 'string' ? args.layer : '';
1010
+ if (askedLayer !== '') {
1011
+ if (askedLayer !== 'global' && askedLayer !== 'workspace') {
1012
+ throw new Error('unknown layer: ' + askedLayer + ' (expected global / workspace)');
1013
+ }
1014
+ // 关掉的层在模型眼里不该存在。显式点名它时拒绝而不是悄悄落到另一层 ——
1015
+ // 静默改层会让模型以为自己记到了它说的那一层。
1016
+ if (!(askedLayer === 'global' ? layers.global : layers.workspace)) {
1017
+ throw new Error('the ' + askedLayer + ' autonomous-memory layer is off here, so nothing was done. The user can turn it on in Memory → Autonomous memory' +
1018
+ (onlyLayer !== undefined ? ', or omit layer to use the enabled ' + onlyLayer + ' layer.' : '.'));
1019
+ }
1020
+ }
974
1021
  // save 的参数串进来时(`body` / `memory`),直接指回用户记忆,
975
1022
  // 别让一次完整记忆被当成一句话笔记丢掉。
976
1023
  if (args && (args.body !== undefined || args.memory !== undefined)) {
@@ -1008,6 +1055,9 @@ export function buildMemoryTools(deps) {
1008
1055
  if (args && args[key] !== undefined && args[key] !== '')
1009
1056
  payload[key] = args[key];
1010
1057
  }
1058
+ // 只剩一层时替模型定层:schema 里没有 `layer`,路由与卡片都需要一个确定值。
1059
+ if (onlyLayer !== undefined && (args.layer === undefined || args.layer === ''))
1060
+ payload.layer = onlyLayer;
1011
1061
  // `slot` 是模型面的名字;op 的字段仍是 `key`(同 slot 合并)。`key` 作为旧名兼容一次。
1012
1062
  const slot = String((args && (args.slot !== undefined ? args.slot : args.key)) || '');
1013
1063
  if (slot !== '')
@@ -1032,7 +1082,7 @@ export function buildMemoryTools(deps) {
1032
1082
  throw gateError(r);
1033
1083
  return learnReceipt(r, 'none', payload);
1034
1084
  }
1035
- // 先只读预演:同时拿到「弹卡后会发生什么」与「不弹卡直接落盘会发生什么」。
1085
+ // 先只读预演:拿到「弹卡后会发生什么」(层、是否合并 / 取代、会不会直接生效)。
1036
1086
  const preview = await previewOp(payload);
1037
1087
  if (!preview || preview.ok === false)
1038
1088
  throw gateError(preview);
@@ -1099,7 +1149,10 @@ export function buildMemoryTools(deps) {
1099
1149
  throw new Error(String((r && r.error) || 'failed to record it'));
1100
1150
  return learnReceipt(r, 'approved', payload);
1101
1151
  },
1102
- }));
1152
+ });
1153
+ applyNoteLayerSchema(noteToolDef, noteLayersOf());
1154
+ register(noteToolDef);
1155
+ return { refreshNoteSchema() { applyNoteLayerSchema(noteToolDef, noteLayersOf()); } };
1103
1156
  }
1104
1157
  /**
1105
1158
  * 门禁拒绝 → 一句给模型看的话。
@@ -4,8 +4,9 @@
4
4
  // 根本用不上。关掉某几个工具,它们整份不进请求(不是"把描述写短点"那种省);面板
5
5
  // (118 个 op)与注入通道完全不受影响。
6
6
  //
7
- // 出厂**默认就关着十八条**(其中自主笔记那一条跟随总开关开合;整张表 23 条,每轮实发 5 条)—— 名单、判据与代价见下面
8
- // `DEFAULT_HIDDEN_TOOLS`;用户自己额外关的与出厂关的在合计那句里分开报。
7
+ // 出厂**默认就关着十八条**:其中十七条在可勾选的 22 条里(关掉后每轮实发 5 条),
8
+ // 第十八条是自主笔记,它不在行集里、跟随记忆页的总开关(开则实发 6 条)—— 名单、判据
9
+ // 与代价见下面 `DEFAULT_HIDDEN_TOOLS`;用户自己额外关的与出厂关的在合计那句里分开报。
9
10
  //
10
11
  // 实测数字(口径:宿主 `recordToolSize` 的 `ceil(JSON.stringify(header.tools).length / 4) + 4`,
11
12
  // 即**字符数 / 4**;`header.tools` 里只有 name / description / parameters —— 官方的
@@ -80,8 +81,9 @@ export function stripProactiveToolHidden(hidden) {
80
81
  return hidden.filter((name) => name !== PROACTIVE_MEMORY_TOOL);
81
82
  }
82
83
  /**
83
- * 出厂默认关掉的**十八条**:整张表 23 条,关掉后**每轮实发 5 条**。下面五组列 16 条,
84
- * 人设清单(`subagent_manager_list`)单列在「人设域」那一段,自主笔记单列在末尾 ——
84
+ * 出厂默认关掉的**十八条**:其中十七条在可勾选的 22 条里(关掉后**每轮实发 5 条**),
85
+ * 第十八条是自主笔记 —— 它不在行集里、跟随记忆页的总开关(开则实发 6 条)。下面五组列
86
+ * 16 条,人设清单(`subagent_manager_list`)单列在「人设域」那一段,自主笔记单列在末尾 ——
85
87
  * 三条计数不要合并,否则又会对不上。
86
88
  *
87
89
  * 判据只有一条:**这些信息或动作常态下由注入段与面板承担,
@@ -155,7 +157,10 @@ export const DEFAULT_HIDDEN_TOOLS = Object.freeze([
155
157
  // 实际被藏着"的错位。
156
158
  PROACTIVE_MEMORY_TOOL,
157
159
  ]);
158
- /** 出厂默认那份设置:十八条不发(名单与理由见上面),方案清单是空的。 */
160
+ /**
161
+ * 出厂默认那份设置:名单十八条(含跟随总开关的自主笔记;落盘 / 读侧都会把它摘掉,
162
+ * 所以用户看到的可恢复项是十七条),方案清单是空的。
163
+ */
159
164
  export const DEFAULT_TOOL_TABLE_SETTINGS = { hidden: [...DEFAULT_HIDDEN_TOOLS], presets: [] };
160
165
  /** 方案名上限(与 MCP 备注那类输入同风格:短到能在一行里读,长了也没人看)。 */
161
166
  export const PRESET_NAME_MAX_LENGTH = 40;
@@ -377,6 +382,10 @@ export function applyToolTableToggles(current, toggles) {
377
382
  /**
378
383
  * 纯函数:把注册时量到的体积按域分组,标出哪些被关掉,给出四档合计。
379
384
  *
385
+ * `rows` 是**可勾选的那部分表**(22 条):只跟总开关走的那条不在里面 —— 它在界面上没有
386
+ * 行、不进名单、不进方案。它由 `derived` 参数单独交代(名字、开没开、体积),报告用
387
+ * `sentCount` 把它加回"实际发送",两个口径因此不会在接口层散掉。
388
+ *
380
389
  * 顺序:域按 `INJECT_DOMAIN_KEYS`(界面与注入通道同一顺序),域内按**注册顺序**
381
390
  * —— 改顺序等于改显示顺序,不额外定义"重要性",免得出现第二份排序真相。
382
391
  *
@@ -385,7 +394,7 @@ export function applyToolTableToggles(current, toggles) {
385
394
  * 全局的 —— 所以由调用方给一份口径明确的名单(`tool-table-switch.ts` 传的是"标准预设下会
386
395
  * 让位"的保守估计),本函数只负责把它从**可见**里扣掉、单独计一档。
387
396
  */
388
- export function buildToolTableReport(rows, hidden, carrierHidden = []) {
397
+ export function buildToolTableReport(rows, hidden, carrierHidden = [], derived) {
389
398
  const off = new Set(hidden.map((name) => String(name)));
390
399
  const carried = new Set(carrierHidden.map((name) => String(name)));
391
400
  // 「控制」组排在最前:它是**管着这张表的那一条工具**,放在末尾的「其它」组里
@@ -406,7 +415,12 @@ export function buildToolTableReport(rows, hidden, carrierHidden = []) {
406
415
  list = [];
407
416
  buckets.set(key, list);
408
417
  }
409
- list.push({ name, tok: estimateTok(row.bytes), hidden: off.has(name), defaultHidden: DEFAULT_HIDDEN_SET.has(name) });
418
+ list.push({
419
+ name,
420
+ tok: estimateTok(row.bytes),
421
+ hidden: off.has(name),
422
+ defaultHidden: DEFAULT_HIDDEN_SET.has(name),
423
+ });
410
424
  }
411
425
  const groups = [];
412
426
  let visibleTok = 0;
@@ -445,9 +459,18 @@ export function buildToolTableReport(rows, hidden, carrierHidden = []) {
445
459
  hiddenTok += offTok;
446
460
  groups.push({ key, tools, tok, hiddenTok: offTok });
447
461
  }
462
+ const derivedTool = derived === undefined
463
+ ? undefined
464
+ : {
465
+ name: String(derived.name),
466
+ active: derived.active === true,
467
+ tok: estimateTok(derived.bytes),
468
+ };
448
469
  return {
449
470
  groups, visibleTok, hiddenTok, totalTok: visibleTok + hiddenTok + carrierHiddenTok,
450
471
  visibleCount, hiddenCount: totalCount - visibleCount - carrierHiddenCount, totalCount,
451
472
  defaultHiddenCount, defaultHiddenTok, carrierHiddenCount, carrierHiddenTok,
473
+ ...(derivedTool === undefined ? {} : { derived: derivedTool }),
474
+ sentCount: visibleCount + (derivedTool !== undefined && derivedTool.active ? 1 : 0),
452
475
  };
453
476
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-tool-management",
3
- "version": "0.22.6",
3
+ "version": "0.22.7",
4
4
  "description": "一个设置面板,统一管理 MCP、技能、记忆、子智能体、提示词和归档会话;可自定义搭配场景,一个场景即可切换整个环境;Agent也能帮你操作这个插件。",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,7 +30,7 @@
30
30
  "docs/TROUBLESHOOTING.md"
31
31
  ],
32
32
  "engines": {
33
- "dsh": ">=0.2.2-rc.1 <0.2.3",
33
+ "dsh": ">=0.2.2-rc.2 <0.2.3",
34
34
  "node": ">=24.9"
35
35
  },
36
36
  "publishConfig": {
@@ -76,17 +76,17 @@
76
76
  "icon": "./docs/images/logo.png",
77
77
  "peerDependencies": {
78
78
  "@deepseek-ai/cordis": "^4.0.2",
79
- "@deepseek-ai/dsh-agent-preset-registry": ">=0.2.2-rc.1 <0.2.3",
80
- "@deepseek-ai/dsh-llm": ">=0.2.2-rc.1 <0.2.3",
81
- "@deepseek-ai/dsh-session": ">=0.2.2-rc.1 <0.2.3",
82
- "@deepseek-ai/dsh-session-projection-cache": ">=0.2.2-rc.1 <0.2.3",
83
- "@deepseek-ai/dsh-settings": ">=0.2.2-rc.1 <0.2.3",
84
- "@deepseek-ai/dsh-spill-local": ">=0.2.2-rc.1 <0.2.3",
85
- "@deepseek-ai/dsh-storage-domain": ">=0.2.2-rc.1 <0.2.3",
86
- "@deepseek-ai/dsh-subagent-fork-in-process": ">=0.2.2-rc.1 <0.2.3",
87
- "@deepseek-ai/dsh-subagent-spawn-in-process": ">=0.2.2-rc.1 <0.2.3",
88
- "@deepseek-ai/dsh-tools": ">=0.2.2-rc.1 <0.2.3",
89
- "@deepseek-ai/dsh-workspace": ">=0.2.2-rc.1 <0.2.3",
79
+ "@deepseek-ai/dsh-agent-preset-registry": ">=0.2.2-rc.2 <0.2.3",
80
+ "@deepseek-ai/dsh-llm": ">=0.2.2-rc.2 <0.2.3",
81
+ "@deepseek-ai/dsh-session": ">=0.2.2-rc.2 <0.2.3",
82
+ "@deepseek-ai/dsh-session-projection-cache": ">=0.2.2-rc.2 <0.2.3",
83
+ "@deepseek-ai/dsh-settings": ">=0.2.2-rc.2 <0.2.3",
84
+ "@deepseek-ai/dsh-spill-local": ">=0.2.2-rc.2 <0.2.3",
85
+ "@deepseek-ai/dsh-storage-domain": ">=0.2.2-rc.2 <0.2.3",
86
+ "@deepseek-ai/dsh-subagent-fork-in-process": ">=0.2.2-rc.2 <0.2.3",
87
+ "@deepseek-ai/dsh-subagent-spawn-in-process": ">=0.2.2-rc.2 <0.2.3",
88
+ "@deepseek-ai/dsh-tools": ">=0.2.2-rc.2 <0.2.3",
89
+ "@deepseek-ai/dsh-workspace": ">=0.2.2-rc.2 <0.2.3",
90
90
  "react": "^18.2.0"
91
91
  },
92
92
  "peerDependenciesMeta": {
@@ -129,17 +129,17 @@
129
129
  },
130
130
  "devDependencies": {
131
131
  "@deepseek-ai/cordis": "^4.1.0",
132
- "@deepseek-ai/dsh-agent-preset-registry": ">=0.2.2-rc.1 <0.2.3",
133
- "@deepseek-ai/dsh-llm": ">=0.2.2-rc.1 <0.2.3",
134
- "@deepseek-ai/dsh-session": ">=0.2.2-rc.1 <0.2.3",
135
- "@deepseek-ai/dsh-session-projection-cache": ">=0.2.2-rc.1 <0.2.3",
136
- "@deepseek-ai/dsh-settings": ">=0.2.2-rc.1 <0.2.3",
137
- "@deepseek-ai/dsh-spill-local": ">=0.2.2-rc.1 <0.2.3",
138
- "@deepseek-ai/dsh-storage-domain": ">=0.2.2-rc.1 <0.2.3",
139
- "@deepseek-ai/dsh-subagent-fork-in-process": ">=0.2.2-rc.1 <0.2.3",
140
- "@deepseek-ai/dsh-subagent-spawn-in-process": ">=0.2.2-rc.1 <0.2.3",
141
- "@deepseek-ai/dsh-tools": ">=0.2.2-rc.1 <0.2.3",
142
- "@deepseek-ai/dsh-workspace": ">=0.2.2-rc.1 <0.2.3",
132
+ "@deepseek-ai/dsh-agent-preset-registry": ">=0.2.2-rc.2 <0.2.3",
133
+ "@deepseek-ai/dsh-llm": ">=0.2.2-rc.2 <0.2.3",
134
+ "@deepseek-ai/dsh-session": ">=0.2.2-rc.2 <0.2.3",
135
+ "@deepseek-ai/dsh-session-projection-cache": ">=0.2.2-rc.2 <0.2.3",
136
+ "@deepseek-ai/dsh-settings": ">=0.2.2-rc.2 <0.2.3",
137
+ "@deepseek-ai/dsh-spill-local": ">=0.2.2-rc.2 <0.2.3",
138
+ "@deepseek-ai/dsh-storage-domain": ">=0.2.2-rc.2 <0.2.3",
139
+ "@deepseek-ai/dsh-subagent-fork-in-process": ">=0.2.2-rc.2 <0.2.3",
140
+ "@deepseek-ai/dsh-subagent-spawn-in-process": ">=0.2.2-rc.2 <0.2.3",
141
+ "@deepseek-ai/dsh-tools": ">=0.2.2-rc.2 <0.2.3",
142
+ "@deepseek-ai/dsh-workspace": ">=0.2.2-rc.2 <0.2.3",
143
143
  "@types/js-yaml": "^4.0.9",
144
144
  "@types/node": "^24.0.0",
145
145
  "@types/semver": "^7.7.0",