dsh-plugin-tool-management 0.22.2 → 0.22.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.
@@ -31,7 +31,7 @@ export const SUPERSEDE_NOTE = 'Supersedes earlier injected content of the same k
31
31
  * (`hiddenTools`),而工具注册在热重载 / 启动间隙会瞬时为空 —— 并进键会先注入一句
32
32
  * "你手里没有这个工具"(假话),下一步再撤回。静态字符串型 `how` 已经自动进键(见 `frameKeyOf`)。
33
33
  */
34
- export const FRAME_REVISION = 1;
34
+ export const FRAME_REVISION = 2;
35
35
  /**
36
36
  * 框架指纹:决定"该域消息的框架是不是这一版"。
37
37
  *
@@ -81,21 +81,16 @@ export const DOMAIN_FRAME = {
81
81
  },
82
82
  memory: {
83
83
  title: 'Current memories',
84
- // 但没给出口——被截掉的条目连名字都没列出来,模型既调不了 `memory_manager_read`(不知道
85
- // 传什么名字),也不知道该用 `memory_manager_list` 去发现。另外三个域的溢出行都点名了
86
- // 自己的 list 工具,唯独记忆段没有。
87
- //
88
- // 修法选了「frame `how` 条件点名」而不是「把 listToolVisible 管道接到记忆服务」:记忆 SWR
89
- // 缓存是指纹驱动的(缓存渲染结果,不是缓存数据按 agent 重渲染),重构成技能目录那种方式
90
- // 要动 4–5 个文件。而 `how` 已经能看 `{ text }`——MCP 就是这么按正文内容决定发不发的。
84
+ // 出口句放在**正文之后**(`afterBody`):它说的是"刚才那段没列全的部分去哪查"——
85
+ // 模型读完 `## Not injected` 名单紧接着读到出口,顺序才通。条件判据不变:
91
86
  // `text.includes('more not listed')` 只在折叠行出现时命中(rest > 0);rest = 0(清单列全)
92
- // 时折叠行不出现,how 不发——那些条目有名字,模型调 `memory_manager_read` 就行。
93
- // 工具被关掉(兼容页 / 人设 toolsDeny)时不点名——与另外三域同一纪律。
94
- how: ({ text, toolHidden }) => {
87
+ // 时不发——那些条目有名字,模型调 `memory_manager_read` 就行;工具被关掉(兼容页 /
88
+ // 人设 toolsDeny)时不点名——与另外三域同一纪律。
89
+ afterBody: ({ text, toolHidden }) => {
95
90
  // 折叠行 `more not listed` 和截断标记 `(Truncated:` 两种信号都要覆盖:
96
91
  // - 折叠行 = 清单部分列了 + 剩余没列 → 没名的那些需要 list 工具发现
97
92
  // - 标记 = 连清单都没放进来 → 全部没名,更需要 list 工具
98
- // - 清单列全(`## Not injected` + 所有名字,rest = 0)→ 两种信号都没有 → 不发 how:
93
+ // - 清单列全(`## Not injected` + 所有名字,rest = 0)→ 两种信号都没有 → 不发:
99
94
  // 模型用 `memory_manager_read` 按名字读就行
100
95
  if (!text.includes('more not listed') && !text.includes('(Truncated:'))
101
96
  return undefined;
@@ -125,7 +120,10 @@ export const DOMAIN_FRAME = {
125
120
  // 也就无从提示"它在重连 / 检查网络"。这是该要求的直接代价,与 state-section.ts 文件头
126
121
  // 记的是同一件事。剩下的 `no tools enabled here` 是 server **此刻在跑**、只是工具被关掉,
127
122
  // 那句话仍然防着"别把它报成缺失"。
128
- how: ({ text }) => {
123
+ // 两句解释都放在**正文之后**(`afterBody`):它们解释的是"刚才那些行上的记号怎么读"
124
+ // (`user hint:` / `no tools enabled here`),模型扫完服务器行紧接着读到读法,顺序才通。
125
+ // 按需发的判据不变。
126
+ afterBody: ({ text }) => {
129
127
  const parts = [];
130
128
  if (text.includes('user hint: ')) {
131
129
  parts.push("`user hint:` marks the user's own note on that server — read it before choosing one.");
@@ -139,36 +137,61 @@ export const DOMAIN_FRAME = {
139
137
  },
140
138
  skills: {
141
139
  title: 'Current skills',
142
- // 两句都只在预设没挂官方 `skill` 工具时出现,差别只在点名不点名那个取正文的工具
143
- // (工具被用户在兼容页关掉时不点名 —— 点名一个模型手里没有的工具只会让它去猜名字)。
144
- //
145
- // 两句都要有:**怎么想起它**("任务对得上就去读")与**读完再用**(已经决定用之后的
146
- // 纪律)。官方那条行两者都有(`if … the task clearly matches … call the skill tool …
147
- // before taking task actions`),而这一域恰恰只在官方那条行**缺席**时才注入 —— 模型手上
148
- // 既没有 `skill` 工具、也没人告诉过它技能的调用时机,缺的正是这一句。同理补上"描述不是
149
- // 指令"(官方对应句 `do not infer or follow a skill's instructions until it has been
150
- // loaded`),免得它拿 500 字摘要当正文照做。
151
- // 不点名工具那一支**不能**说"read a skill's body before following it" —— 那是让模型去读
152
- // 一份它根本读不到的东西。
140
+ // 版式对齐官方目录(`dsh-tool-skill`):清单前一句、清单后动作段,官方是**两套文案
141
+ // 二选一** —— 首份说「以下技能可用」,更新说「目录变了、取代此前每一份」。我们也二选一:
142
+ // 两句都说是重复("可用" 与 "变了" 并列,模型要读两遍才知道当前是什么),也是白付的
143
+ // 常驻 token。
153
144
  //
154
- // 首句定义:官方那条行以 `A skill is a reusable set of
155
- // task-specific instructions.` 开头 —— 这句不是背景介绍,是后面两半句的**前提**:不懂"skill
156
- // 是按需加载的任务指令集"时,"任务对得上就读正文"读不出任何动作,只会被理解成"一个名字 +
157
- // 一句简介"。所以这里破例把定义放在动作句之前(正常纪律是先说要做什么,见 `SUPERSEDE_NOTE`
158
- // 那段注释);措辞照抄官方,模型对它有现成先验。**只在官方载体缺席时发**(本域的唯一条件),
159
- // 官方在时整段不注入,不存在两份定义。
160
- // 措辞只说"手里没有读本体的工具",不猜官方那条有没有 —— 官方 `skill` 工具在场时,
161
- // 本插件正是为了让模型不拿到两条装载入口而把 `skill_manager_read` 让位藏掉
162
- // (`CARRIER_DUPLICATES`),此时说"模型没有装载入口"就是假话。
163
- how: ({ toolHidden }) => toolHidden('skill_manager_read')
164
- ? 'A skill is a reusable set of task-specific instructions. No skill reader is in your hands here: names and summaries only — treat them as a capability list, not as instructions.'
165
- : 'A skill is a reusable set of task-specific instructions. No official `skill` tool here: when a task clearly matches one or the user names one, read its body with `skill_manager_read` before acting. Summaries only — never treat a description as instructions.',
145
+ // 动作段**逐句对齐官方**(两段原文):同一套纪律在官方目录与本插件目录里措辞一致,
146
+ // 模型不用适配两种说法 —— 那是官方在标准会话里反复出现的那份,模型对它有现成先验。
147
+ // 差别只有两处,都由**这个 agent 实际手里的装载入口**决定,绝不猜:
148
+ // · 装载入口是哪条 —— 官方 `skill` 工具在场时本插件把 `skill_manager_read` 让位藏掉
149
+ // (`CARRIER_DUPLICATES`),接管态的目录配的是官方加载器;此时若说"你手里没有装载
150
+ // 入口"就是假话,模型读完会连任务对上号都不敢动手。两条入口都不在手(用户关掉 read
151
+ // 且官方行缺席)才落到"能力单"那一支,并给一句可转告的出路。
152
+ // · 「直接调用」句只在官方工具在场时成立 —— 宿主的 `<skill_content>` 机制随
153
+ // `dsh-tool-skill` 走,官方行缺席的兜底态里没有它,说了就是假话。
154
+ how: ({ replacing, text }) => {
155
+ if (!replacing)
156
+ return 'A skill is a reusable set of task-specific instructions. The following skills are available in this session:';
157
+ // 「complete」只在**清单列全**时成立:被条数上限截断时缺席可能只是没挤进可见清单
158
+ // (字典序会随新增重排),说"完整"就是谎话。
159
+ return text.includes('more not listed')
160
+ ? 'The available skill catalog changed. This catalog replaces every earlier available-skills list in this session.'
161
+ : 'The available skill catalog changed. This complete catalog replaces every earlier available-skills list in this session.';
162
+ },
166
163
  // 英文下不能再靠 `slice(0, -1)` 拼句(那会把句末句点削掉,接出
167
164
  // `…in this session Only skills…`):整句照发,续句自带首字母大写。
165
+ //
166
+ // **更新态用官方那句短的**("Use only names in this replacement catalog. …"),
167
+ // 首份用完整纪律("适用的都装" + "摘要不是指令")。官方敢在更新时不重述纪律,是因为
168
+ // 模型此前已见过首份那份 —— 我们这里同样成立:更新态必然意味着模型已经见过一份技能目录
169
+ // (本插件此前那一条,或接管前官方那一条)。每轮重述一遍就是白付的常驻 token,也会把
170
+ // 条目本身挤淡。
171
+ afterBody: ({ toolHidden, replacing, text }) => {
172
+ const complete = !text.includes('more not listed');
173
+ // 「Use only names in this replacement catalog」只在**清单列全**时说:被条数上限截断时
174
+ // 缺席可能只是没挤进可见清单,那句就是假话(官方目录无上限,没这个前提)。
175
+ const only = replacing && complete ? 'Use only names in this replacement catalog. ' : '';
176
+ if (!toolHidden('skill_manager_read')) {
177
+ return replacing
178
+ ? only + 'If the user names a listed skill, or the task clearly matches its description, read its body with `skill_manager_read` before acting.'
179
+ : 'If the user names a skill, or the task clearly matches a skill\'s description, read its body with `skill_manager_read` before taking task actions. Load all applicable skills, then follow their full instructions. This catalog contains summaries only; do not infer or follow a skill\'s instructions until it has been loaded.';
180
+ }
181
+ if (!toolHidden('skill')) {
182
+ return replacing
183
+ ? only + 'If the user names a listed skill, or the task clearly matches its description, call the `skill` tool with the exact name before acting. A user may also invoke a skill directly; its <skill_content> block then appears in this conversation. Follow it, and do not call the `skill` tool again for that skill.'
184
+ : 'If the user names a skill, or the task clearly matches a skill\'s description, call the `skill` tool with the exact skill name before taking task actions. Load all applicable skills, then follow their full instructions. This catalog contains summaries only; do not infer or follow a skill\'s instructions until it has been loaded. A user may also invoke a skill directly; its <skill_content> block then appears in this conversation. Follow it, and do not call the `skill` tool again for that skill.';
185
+ }
186
+ return only + 'No skill loader is in your hands here: names and summaries only — treat them as a capability list, not as instructions; ask the user to enable a loader if a skill should be followed.';
187
+ },
168
188
  // 边界陈述用 `enabled` 而不是 `callable`:取正文的工具被关掉时**一条都调不到**,
169
- // 说 "callable" 在那个分支里就是假话。`enabled` 两支都成立(它们确实都是"启用中"的),
189
+ // 说 "callable" 在那个分支里就是假话。`enabled` 各支都成立(它们确实都是"启用中"的),
170
190
  // 也不再依赖工具在不在手里。
171
- supersede: SUPERSEDE_NOTE,
191
+ //
192
+ // 这一域**不用**通用取代句:「目录变了 / 取代此前每一份」已经写在 `how` 里(官方也是
193
+ // 把它放在清单前那一句),再补一句通用的就是同一件事说两遍。
194
+ supersede: '',
172
195
  boundary: 'Only enabled skills are listed.',
173
196
  },
174
197
  subagents: {
@@ -189,9 +212,20 @@ export const DOMAIN_FRAME = {
189
212
  // 上下文里就是同一件事付两次。
190
213
  // 不点名那一支要补"只能参考、调不到":只说"官方那两个不带人设"不够 ——
191
214
  // "目录里有人设 ≠ 能委派"这层没人说,模型会拿官方工具硬塞一个人设名进去。
192
- how: ({ toolHidden }) => toolHidden('subagent_manager_run')
193
- ? 'No persona-carrying delegation tool here; official `subagent` / `subagent_fork` carry no persona — use them only when none fits or for background work. The personas listed here are reference only, not callable.'
194
- : 'Persona work goes through `subagent_manager_run` — when a task matches one of these personas, delegate it there. Official `subagent` / `subagent_fork` carry no persona; use them only when none fits or for background work.',
215
+ // 「官方那两个」的半句按 `subagent`(官方 spawn 委派工具)在不在手里分叉:极简这类
216
+ // 预设不挂 `dsh-tool-subagent`,那两个工具根本不存在 —— 点名它们正是"诱导模型去调
217
+ // 不存在的名字"那条老毛病。路由规则本身(人设 → 本插件、没有合适人设/后台 → 官方)
218
+ // 只在官方工具真的在手时才讲全。
219
+ // 路由规则放在**正文之后**(`afterBody`):模型先扫完有哪些人设,紧接着读"拿它们做什么"
220
+ // —— 与技能域同一版式理由。
221
+ afterBody: ({ toolHidden }) => {
222
+ const official = toolHidden('subagent')
223
+ ? ''
224
+ : ' Official `subagent` / `subagent_fork` carry no persona — use them only when none fits or for background work.';
225
+ return toolHidden('subagent_manager_run')
226
+ ? 'No persona-carrying delegation tool here.' + official + ' The personas listed here are reference only, not callable; ask the user to enable the delegation tool if a persona should run.'
227
+ : 'Persona work goes through `subagent_manager_run` — when a task matches one of these personas, delegate it there.' + official;
228
+ },
195
229
  supersede: SUPERSEDE_NOTE,
196
230
  },
197
231
  prompt: {
@@ -208,7 +242,8 @@ export const DOMAIN_FRAME = {
208
242
  },
209
243
  };
210
244
  /**
211
- * `how` 行里**点名过的工具**(skills / subagents / memory 三个域会点名)。
245
+ * `how` 行里**点名过的工具**(`skill` / `skill_manager_read` / `subagent` /
246
+ * `subagent_manager_run` / `memory_manager_list`)。
212
247
  *
213
248
  * 为什么要有这份名单:一条 `how` 行是否成立,取决于它点名的工具在**这个 agent 手里**还在不在。
214
249
  * 名单放在这里而不是调用方 —— 与上面那几条 `how` 相邻,改一处不会漏另一处。
@@ -219,11 +254,15 @@ export const DOMAIN_FRAME = {
219
254
  * 人设启动的子代理)。②此前没人管:目录照注、`how` 行照样点名一个模型手里没有的工具,
220
255
  * 等于诱导它去调一个不存在的名字。
221
256
  *
257
+ * 官方的两条(`skill` / `subagent`)也在名单里:技能目录接管态下装载入口是官方 `skill` 工具、
258
+ * 人设目录的「没有合适人设 → 用官方委派」半句只在官方委派工具真的存在时才成立 —— 它们不是
259
+ * 本插件的工具,但 `toolVisibleFor` 走 `tools.get(name, agent)`,官方注册表照样答得上来。
260
+ *
222
261
  * `memory_manager_list` 加入:记忆段截断折叠行不点名查询工具时,
223
262
  * 被截掉的条目无名、模型无法发现它们。`how` 在折叠行出现时点名它,与技能 / 子智能体 /
224
263
  * MCP 三个域的溢出行同构。
225
264
  */
226
- export const HOW_NAMED_TOOLS = ['skill_manager_read', 'subagent_manager_run', 'memory_manager_list'];
265
+ export const HOW_NAMED_TOOLS = ['skill', 'skill_manager_read', 'subagent', 'subagent_manager_run', 'memory_manager_list'];
227
266
  /** 域声明里没登记的 key(理论上到不了这里):给一个不出错的通用框架。 */
228
267
  export const fallbackFrame = (label) => ({
229
268
  title: `Current ${label}`,
@@ -300,7 +339,10 @@ export function renderDomainText(section, toolHidden = () => false, replacing =
300
339
  // 开标签后**必须空一行**:markdown 里 `#` 紧跟在一行文字后面只是**段落续行**,不会被渲染成
301
340
  // 标题 —— 用户截图里 `## 本机当前的场景` 就是这么被吞掉的(和 `<system-reminder>` 挤成一段)。
302
341
  // 收尾同理:正文末尾先归一成单个空行,免得 `</system-reminder>` 粘在最后一行上。
303
- // 结构:标题 → 补充说明(有才发)→ 权威声明(只在替换时)→ 边界陈述(有才发)→ 正文。
342
+ // 结构:标题 → 补充说明(有才发)→ 权威声明(只在替换时)→ 正文 → 动作段(`afterBody`,
343
+ // 有才发)→ 边界陈述(有才发)。动作段与边界在**收尾区**(官方目录版式:一句引入 →
344
+ // 清单 → 动作段 —— 模型扫完条目紧接着读到"拿这些名字做什么",说明压在清单前面会把
345
+ // 清单推到消息末尾)。
304
346
  // 没有 cue 那一行(见 `DomainFrame` 的注释)。
305
347
  const info = { toolHidden, text: section.text, replacing };
306
348
  const lines = [FRAME_OPEN, '', `# ${frame.title}`];
@@ -318,11 +360,21 @@ export function renderDomainText(section, toolHidden = () => false, replacing =
318
360
  lines.push(how);
319
361
  // 权威声明只在**替换**时发:本会话的第一份没有旧内容可取代,那句话
320
362
  // 只是占一行。边界陈述反过来 —— 它不依赖"有没有旧的",第一份就要发。
321
- if (replacing)
322
- lines.push(frame.supersede);
363
+ // 空串 = 这一域不用通用取代句(技能域把"目录变了 / 取代此前每一份"写进了清单前那句,
364
+ // 官方也是这么写的 —— 再补一句通用的就是同一件事说两遍)。
365
+ if (replacing) {
366
+ const supersede = typeof frame.supersede === 'function' ? frame.supersede(info) : frame.supersede;
367
+ if (supersede !== '')
368
+ lines.push(supersede);
369
+ }
370
+ lines.push('', escapeFrameBody(section.text).replace(/\n+$/, ''));
371
+ // 收尾区:动作段(按 agent 与正文内容求值)与边界句各占一段,与清单隔开。
372
+ const after = typeof frame.afterBody === 'function' ? frame.afterBody(info) : frame.afterBody;
373
+ if (after !== undefined)
374
+ lines.push('', after);
323
375
  if (frame.boundary !== undefined)
324
- lines.push(frame.boundary);
325
- lines.push('', escapeFrameBody(section.text).replace(/\n+$/, ''), '', FRAME_CLOSE);
376
+ lines.push('', frame.boundary);
377
+ lines.push('', FRAME_CLOSE);
326
378
  return { text: lines.join('\n'), body: section.text, frameKey };
327
379
  }
328
380
  /** 「已清空」通知正文:某个域曾经注入过、现在没有内容时发一条(纯函数,测试用)。 */
@@ -1,4 +1,24 @@
1
1
  import { CARRIER_FACT_OF, DEFAULT_INJECT_SETTINGS, INJECT_DOMAIN_KEYS, } from './context-inject-contract.js';
2
+ /**
3
+ * 目录上限的夹取范围。条数下限 1(关掉目录是域开关的事,上限不为它开口);描述下限 20
4
+ * (再短截不出可读摘要,模型只会拿到一串残句);上限给到覆盖一切正常装机 —— 官方目录
5
+ * 本就无条数上限,这里只挡手滑输入的四位数。
6
+ */
7
+ const CAP_ENTRIES_MAX = 500;
8
+ const CAP_DESCRIPTION_MIN = 20;
9
+ const CAP_DESCRIPTION_MAX = 2000;
10
+ /**
11
+ * 夹一个目录上限值:`0` / 空 / 非法 → `undefined`(回到出厂值);其余夹进 `[lo, hi]`。
12
+ *
13
+ * "0 = 回默认"而不是"列 0 条":把目录清空是域开关的语义,上限这里给 0 只会让用户以为
14
+ * 保存失败。写盘前在 {@link normalizeInjectSettings} 统一夹一遍,读侧与写侧看到同一份形状。
15
+ */
16
+ function clampCap(raw, lo, hi) {
17
+ const n = typeof raw === 'number' ? Math.floor(raw) : Number.NaN;
18
+ if (!Number.isFinite(n) || n <= 0)
19
+ return undefined;
20
+ return Math.min(Math.max(n, lo), hi);
21
+ }
2
22
  /** 把任意输入夹成合法设置(缺项/类型不对一律退回默认;默认从不阻止注入)。 */
3
23
  export function normalizeInjectSettings(raw) {
4
24
  const obj = (raw && typeof raw === 'object' ? raw : {});
@@ -7,11 +27,19 @@ export function normalizeInjectSettings(raw) {
7
27
  for (const key of INJECT_DOMAIN_KEYS) {
8
28
  domains[key] = typeof domainsRaw[key] === 'boolean' ? domainsRaw[key] : DEFAULT_INJECT_SETTINGS.domains[key];
9
29
  }
30
+ const capsRaw = (obj.catalogCaps && typeof obj.catalogCaps === 'object' ? obj.catalogCaps : {});
10
31
  return {
11
32
  underSuppressingPresets: typeof obj.underSuppressingPresets === 'boolean'
12
33
  ? obj.underSuppressingPresets
13
34
  : DEFAULT_INJECT_SETTINGS.underSuppressingPresets,
14
35
  domains,
36
+ catalogCaps: {
37
+ skills: clampCap(capsRaw.skills, 1, CAP_ENTRIES_MAX),
38
+ skillsDescription: clampCap(capsRaw.skillsDescription, CAP_DESCRIPTION_MIN, CAP_DESCRIPTION_MAX),
39
+ mcp: clampCap(capsRaw.mcp, 1, CAP_ENTRIES_MAX),
40
+ subagents: clampCap(capsRaw.subagents, 1, CAP_ENTRIES_MAX),
41
+ subagentsDescription: clampCap(capsRaw.subagentsDescription, CAP_DESCRIPTION_MIN, CAP_DESCRIPTION_MAX),
42
+ },
15
43
  };
16
44
  }
17
45
  /**
package/lib/index.js CHANGED
@@ -265,7 +265,29 @@ export default {
265
265
  // 来源裁剪为 dsh/agents/codex/claude);服务层把 core 的结果适配成 { op, args }
266
266
  // 协议,并在全局层与每个活动 agent 的 scope 内注册 manager provider:
267
267
  // rank 覆盖实现不改源文件的启停;外部来源由 provider 接入。
268
- const skillsService = createSkillsService(ctx);
268
+ /**
269
+ * 技能 provider 的**会话层**:官方技能服务问 provider「有哪些技能」时,provider 按
270
+ * **查看方**(官方传进来的 `options.scope` = 调用方 agent)那一层的生效值回答。
271
+ *
272
+ * 为什么必须有:策略表 / 来源状态是**机器级**的 —— 会话 A 开一条全局关着的技能,那条
273
+ * 必须临时落进机器级那张表才加载得了(官方 `skill` 工具只认那张表),于是**每个**
274
+ * 会话的清单里都看得见它。注入目录早就按会话过滤了(`renderSkillCatalog` 的 layer),
275
+ * 官方那份清单(宿主 `/` 菜单的「技能」段、官方 `skill` 工具的候选)没有 —— 那条串味
276
+ * 就留在那里:A 会话开的技能出现在 B / C 会话的菜单里。
277
+ *
278
+ * 两格与注入目录**同一份判据**(`skillViewOf` / `skillSourceViewOf`),不多定义第二套。
279
+ * 全局粒度没有会话层(`scopeKeyForAgent` 返回 null)→ 按机器级那一份,与面板一致。
280
+ */
281
+ const skillProviderSessionViewOf = (viewer) => {
282
+ const scopeKey = scopeKeyForAgent(viewer);
283
+ if (!scopeKey)
284
+ return undefined;
285
+ return {
286
+ skill: (key) => skillViewOf(scopeKey, key).visible,
287
+ source: (rootKey) => skillSourceViewOf(scopeKey, rootKey).visible,
288
+ };
289
+ };
290
+ const skillsService = createSkillsService(ctx, { sessionViewOf: skillProviderSessionViewOf });
269
291
  try {
270
292
  ctx.effect(() => skillsService.registerProviders(), 'dsh-plugin-tool-management: skills providers');
271
293
  }
@@ -2009,6 +2031,11 @@ export default {
2009
2031
  // 场景绑定的排除项;没话说时目录自己落到全局口径(场景绑定 ∩ 全局启停)。
2010
2032
  flagFor: (agent) => flagResolverOfAgent(agent, 'subagents'),
2011
2033
  layerKeyFor: (agent) => layerKeyOfAgent(agent),
2034
+ }, {
2035
+ // 目录上限吃兼容页注入设置(`catalogCaps`):函数式取值,设置有 TTL 缓存,
2036
+ // 这里只是转发(目录在启动时建,传死数会让界面改完不生效)。
2037
+ maxEntries: () => injectSettingsSync().catalogCaps.subagents,
2038
+ maxDescription: () => injectSettingsSync().catalogCaps.subagentsDescription,
2012
2039
  });
2013
2040
  // ⚠️ 取数必须用 mcpmRowsWithNotes(false):true 会带上**未打码**的 url/headers/env(含明文密钥)。
2014
2041
  // 技能目录与提示词两个域是**官方载体的兜底**:预设挂得到官方
@@ -2035,6 +2062,10 @@ export default {
2035
2062
  return { skill, source };
2036
2063
  },
2037
2064
  layerKeyFor: (agent) => layerKeyOfAgent(agent),
2065
+ }, {
2066
+ // 目录上限吃兼容页注入设置(`catalogCaps`):与子智能体目录同一条理由 —— 函数式取值。
2067
+ maxEntries: () => injectSettingsSync().catalogCaps.skills,
2068
+ maxDescription: () => injectSettingsSync().catalogCaps.skillsDescription,
2038
2069
  });
2039
2070
  /**
2040
2071
  * 技能目录重算的**合并调度**。
@@ -2627,6 +2658,19 @@ export default {
2627
2658
  throw e;
2628
2659
  }
2629
2660
  }
2661
+ /**
2662
+ * 宿主平面 patch 文本(全局 + 当前 profile 两份 `cordis.patch.yml` 拼接)。
2663
+ *
2664
+ * 官方载体行(`dsh-tool-skill` / `dsh-agent-instructions`)预设事实的第二来源:
2665
+ * 组合文本里缺席时,注入侧(`candidates.presetFactsForAgent`)与兼容页矩阵
2666
+ * (`preset-reach` op)都拿它做并集判定,两处同一份文本、不会各说各话。
2667
+ * 不带缓存:调用方各有自己的节拍(注入事实 15s TTL、矩阵点开才算),缺文件返回空串。
2668
+ */
2669
+ async function patchCarrierText() {
2670
+ const paths = await ensurePaths();
2671
+ const [globalText, profileText] = await Promise.all([readPatch(paths.globalPatch), readPatch(paths.projectPatch)]);
2672
+ return globalText + '\n' + profileText;
2673
+ }
2630
2674
  // 每次写补丁前留一份带时间戳的副本:cordis.patch.yml 改坏能让 DSH 起不来,
2631
2675
  // 所以写前那份必须不靠 git 也能拿回来。
2632
2676
  const KEEP_PATCH_BACKUPS = 5;
@@ -2917,6 +2961,8 @@ export default {
2917
2961
  // 状态段尾句那句「用 `mcp_manager_list` 查」的前提:与技能 / 子智能体两个目录同一份判据
2918
2962
  // 。
2919
2963
  listToolVisible: (agent) => toolVisibleFor('mcp_manager_list', agent),
2964
+ // 状态段条数上限:与技能 / 子智能体两个目录同一份设置来源(`catalogCaps.mcp`)。
2965
+ catalogCaps: () => injectSettingsSync().catalogCaps,
2920
2966
  // 会话层:两半各管一头 ——
2921
2967
  // · `sessionMcpOverlay`(异步)给 restrictAgent:在**此刻注册着的**工具全名上算
2922
2968
  // allow / deny(deny 追加、allow 从全局停用名单里减掉,见 tool-visibility.ts);
@@ -3044,6 +3090,8 @@ export default {
3044
3090
  // 传 getter 而不是快照:登记发生在 apply 过程中(本行之后 600 余行),
3045
3091
  // 而这个工厂现在就要构造完。
3046
3092
  selfToolNames: () => selfToolNames,
3093
+ // 预设事实的 patch 第二来源:官方载体行挂在宿主平面 patch 时组合里没有那一行。
3094
+ profilePatchText: patchCarrierText,
3047
3095
  });
3048
3096
  // 提示词预设域的 op 表。单独提出来是为了让**模型工具**能复用同一份判定:
3049
3097
  // `prompt_manager_list` 以前直调 `promptsService.list()`,于是它报的「生效中」是
@@ -4210,6 +4258,8 @@ export default {
4210
4258
  // 先读一次:预热前 state 是乐观的 'ok',而这一行要回答的是"文件现在能不能读"。
4211
4259
  toolTableState: async () => { await readToolTableSettings(); return toolTableState(); },
4212
4260
  presetRoster: candidates.presetRoster,
4261
+ // 预设矩阵的 patch 第二来源:与注入侧同一份文本(`patchCarrierText`),口径不分叉。
4262
+ profilePatchText: patchCarrierText,
4213
4263
  listPatchBackups,
4214
4264
  cleanPatchBackups,
4215
4265
  getContextInjectorLive: () => contextInjectorLive,
@@ -4401,6 +4451,11 @@ export default {
4401
4451
  scheduleSkillCatalogRefresh();
4402
4452
  void subagentCatalog.refresh().catch(() => { });
4403
4453
  }
4454
+ // 会话层改了技能的启停 → 官方那份清单(宿主 `/` 菜单的「技能」段、官方 `skill`
4455
+ // 工具的候选)得重新算:它是按会话过滤的,缓存键里没有会话层,不作废就停在
4456
+ // 改动前那一份。机器级那张表没变时("本对话关掉一条全局开着的技能")尤其需要。
4457
+ if (domain === 'skills' || domain === 'skillSources' || domain === '')
4458
+ skillsService.invalidateSkills();
4404
4459
  },
4405
4460
  message,
4406
4461
  }),
@@ -143,6 +143,8 @@ export function createMcpManager(deps) {
143
143
  const mcpStateCatalog = createMcpStateCatalog({
144
144
  rows: () => mcpmRowsWithNotes(false),
145
145
  ...(deps.listToolVisible === undefined ? {} : { listToolVisible: deps.listToolVisible }),
146
+ // 条数上限吃兼容页注入设置(`catalogCaps.mcp`):函数式取值,设置有 TTL 缓存,这里只是转发。
147
+ ...(deps.catalogCaps === undefined ? {} : { maxEntries: () => deps.catalogCaps().mcp }),
146
148
  // 会话层:本会话隐藏的服务器整条不进段(理由见 state-section.ts)。逐行问谓词 ——
147
149
  // 行数组本身就是服务器全集,不需要另建一份。
148
150
  ...(deps.sessionHiddenServer === undefined ? {} : { sessionServerHidden: deps.sessionHiddenServer }),
@@ -44,8 +44,9 @@
44
44
  //
45
45
  // 同步性:`text()` 必须同步返回(renderPrompt 不接受 Promise),而 MCP 清单是异步读盘 →
46
46
  // 与子智能体目录同构的 stale-while-revalidate(见 src/subagents/catalog.ts)。
47
+ import { CATALOG_CAP_DEFAULTS } from '../catalog-caps.js';
47
48
  /** 段里最多列几台 server;超出部分只报数量。 */
48
- export const DEFAULT_MCP_MAX_ENTRIES = 50;
49
+ export const DEFAULT_MCP_MAX_ENTRIES = CATALOG_CAP_DEFAULTS.mcp;
49
50
  /**
50
51
  * 备注截断长度。界面上那两枚输入框(MCP 页与场景档案)用同一个数当字数上限,
51
52
  * 客户端镜像在 `42-shared-ui.js` 的 `MCP_NOTE_MAX` —— 改这里要一起改它。
@@ -194,13 +195,13 @@ sessionTools = { on: [], off: [] }) {
194
195
  const out = [...lines];
195
196
  const hidden = (usable.length + muted.length)
196
197
  - (shownUsable.length + shownMuted.length);
197
- // 超上限时给出口:技能与子智能体两个目录早就这么写了,这是唯一漏掉
198
- // 的一处。工具被关掉(兼容页 / 人设 toolsDeny)时不点名 —— 点名一个模型手里没有的工具,
199
- // 只会让它去猜名字;数量照报,那是实话。
198
+ // 超上限时给出口:工具可见就点名(技能与子智能体两个目录同款);被关掉时不点名"去调它"
199
+ // —— 点名一个模型手里没有的工具,只会让它去猜名字;但也不只报数量,补一句可转告的事实
200
+ // (工具是关着的、用户能开),别让被截掉的部分在模型看来"不存在"。数量照报,那是实话。
200
201
  if (hidden > 0) {
201
202
  out.push('', listToolVisible
202
203
  ? `(${hidden} more not listed — see them with \`mcp_manager_list\`.)`
203
- : `(${hidden} more not listed.)`);
204
+ : `(${hidden} more not listed — the listing tool is disabled in this session; ask the user to enable it.)`);
204
205
  }
205
206
  return out.join('\n');
206
207
  }
@@ -214,8 +215,8 @@ export function createMcpStateCatalog(deps, opts = {}) {
214
215
  let data = null;
215
216
  let loadedAt = Number.NEGATIVE_INFINITY;
216
217
  let inflight = null;
217
- // 渲染缓存键 = (尾句前提, 本会话停用的服务器)。两者都影响正文,少一个就会让 A 的段
218
- // 出现在 B 里(与技能 / 人设两个目录同一手法)。
218
+ // 渲染缓存键 = (尾句前提, 本会话停用的服务器, 逐工具判定, 条数上限)。全都影响正文,
219
+ // 少一个就会让 A 的段出现在 B 里,或让改完设置后的旧文本继续发(与技能 / 人设两个目录同一手法)。
219
220
  let rendered = null;
220
221
  /** 空清单按 `emptyTtlMs` 走,有行时仍按 `ttlMs`(判据见 `emptyTtlMs` 的注释)。 */
221
222
  const ttlFor = () => (data !== null && data.length === 0 ? emptyTtlMs : ttlMs);
@@ -301,16 +302,20 @@ export function createMcpStateCatalog(deps, opts = {}) {
301
302
  toolOff.length = 0;
302
303
  }
303
304
  }
305
+ // 上限每次渲染现取(设置有 TTL 缓存,这里只是转发);缺省回落厂值。
306
+ const maxEntries = (typeof opts.maxEntries === 'function' ? opts.maxEntries() : opts.maxEntries) ?? DEFAULT_MCP_MAX_ENTRIES;
304
307
  const key = (visible ? '1' : '0') +
305
308
  '\u0000' + sessionOff.slice().sort().join('\u0001') +
306
309
  '\u0002' + toolOn.slice().sort().join('\u0001') +
307
- '\u0003' + toolOff.slice().sort().join('\u0001');
310
+ '\u0003' + toolOff.slice().sort().join('\u0001') +
311
+ // 缓存键必须带上条数上限:改了设置而键没变的话,渲染缓存会一直发旧文本。
312
+ '\u0004' + maxEntries;
308
313
  if (rendered && rendered.key === key) {
309
314
  if (rendered.text !== '')
310
315
  markNonEmpty(agent);
311
316
  return rendered.text;
312
317
  }
313
- const out = renderMcpStateSection(data, opts, visible, sessionOff, { on: toolOn, off: toolOff });
318
+ const out = renderMcpStateSection(data, { ...opts, maxEntries }, visible, sessionOff, { on: toolOn, off: toolOff });
314
319
  rendered = { key, text: out };
315
320
  if (out !== '')
316
321
  markNonEmpty(agent);
@@ -46,7 +46,7 @@ export const SHARED_GROUP = '_shared'; // 保留场景名:公共基线(历
46
46
  */
47
47
  export const TRUNCATION_MARKER = '(Truncated: some entries are not shown.)';
48
48
  // 段尾清单:让模型知道自己漏了什么。不挂「场景记忆」前缀 —— 它紧跟在场景块之后,
49
- // 与段首引导语同一说法,两者都是英文(见 SCENE_MEMORY_NOTE)。
49
+ // 与收尾的授权语同一说法,两者都是英文(见 SCENE_MEMORY_NOTE)。
50
50
  // 每行只有 `场景/名称`,不带 `(N B)`:字节数对人有用、对模型零动作价值
51
51
  //(它不能凭"这条 800 B"决定读不读)。
52
52
  /** 超预算时替换掉被丢段落的标题(英文,因为它会进模型上下文,与其余注入文案同语言)。 */
@@ -69,16 +69,18 @@ export const ATTACHMENT_LIST_MAX = 10;
69
69
  * 当成"不重要就可以忽略",而这里要说的是"可以提,只是别主动提"。
70
70
  * ④ **完整性声明**:`this is the complete set`。这是本段唯一的**防探测**手段 —— 没有它,
71
71
  * 模型在清单里找不到某件事时会去调 `memory_manager_list` 找更多。真发生截断时改用
72
- * `SCENE_MEMORY_NOTE_PARTIAL`:否则段首声称"全部"、段尾 `## Not injected` 又列出没
73
- * 进来的条目,每一条注入都在说谎。
72
+ * `SCENE_MEMORY_NOTE_PARTIAL`:否则段尾声称"全部"、其后的 `## Not injected` 又列出
73
+ * 没进来的条目,每一条注入都在说谎。
74
74
  *
75
- * 形式:单行、加粗,放在**板块层**(第一个场景块之前),整段只出现一次 —— 挂在每个场景的
76
- * 段头里会在多场景时重复注入。加粗是 markdown 里最省字符的强调手段。
75
+ * 形式:单行、加粗,放在**板块层收尾**(全部场景块之后、`## Not injected` 尾注之前),整段
76
+ * 只出现一次 —— 挂在每个场景的段头里会在多场景时重复注入。加粗是 markdown 里最省字符的
77
+ * 强调手段。句式是**收束**不是引入:原版以冒号结尾引出清单,挪到条目后面后改句号收尾
78
+ * (与其他五域"说明句后置"同一版式)。
77
79
  *
78
80
  * **不点名任何工具**:模型从工具 schema 就知道 `memory_manager_list` 存在,点名反而像在
79
81
  * 提示它去调。用户写的内容(记忆正文、场景名与说明)一律原样注入,一个字符都不动。
80
82
  */
81
- export const SCENE_MEMORY_NOTE = '**Memories for the current scene; where they conflict with what you observe or with what the user says in this conversation, trust that instead; bring them up only when relevant; this is the complete set:**';
83
+ export const SCENE_MEMORY_NOTE = '**Memories for the current scene; where they conflict with what you observe or with what the user says in this conversation, trust that instead; bring them up only when relevant; this is the complete set.**';
82
84
  /**
83
85
  * 同一条授权语,**去掉完整性声明**的版本 —— 只在真发生截断时用。
84
86
  *
@@ -88,7 +90,7 @@ export const SCENE_MEMORY_NOTE = '**Memories for the current scene; where they c
88
90
  *
89
91
  * 预算按全量版预留(`sceneNoteBytes`),截断态这句更短,所以分叉不会挤掉任何条目。
90
92
  */
91
- export const SCENE_MEMORY_NOTE_PARTIAL = '**Memories for the current scene; where they conflict with what you observe or with what the user says in this conversation, trust that instead; bring them up only when relevant:**';
93
+ export const SCENE_MEMORY_NOTE_PARTIAL = '**Memories for the current scene; where they conflict with what you observe or with what the user says in this conversation, trust that instead; bring them up only when relevant.**';
92
94
  // ── bundle 与索引 ──────────────────────────────────────────────────────────
93
95
  // bundle 附件限制(body 走 HTTP JSON + base64,故比技能上传收紧一档)。
94
96
  export const MAX_ATTACH_ENTRY_BYTES = 8 << 20; // 单个附件 8 MiB
@@ -424,16 +424,16 @@ sceneOverride) {
424
424
  }
425
425
  if (buf !== '')
426
426
  chunks.push(buf);
427
- // 引导语只出现**一次**,放在板块层(第一个场景块之前)。
427
+ // 授权语只出现**一次**,放在板块层(全部场景块之后、`## Not injected` 尾注之前)。
428
428
  //
429
- // 为什么挪上来(用户 看到实际注入后要求):此前它跟着**每个场景块**各来一遍
430
- // —— 2 个场景就是 272 B ≈68 tok/轮,占记忆段整段的 22%;而且它夹在 `## Scene: X` 与条目
431
- // 之间,把"分组"和"内容"隔开了。它管的本来就是整段(授权语讲的是这一整段条目的效力,
432
- // 不是某个场景的),放在最前面才对得上。
429
+ // 位置(用户对照其他五域的版式定的):五个域的说明句现在都收在**正文之后** —— 模型先读
430
+ // 条目、紧接着读到"这些条目是什么、怎么用"。此前它在最前(更早还跟每个场景块各来一遍,
431
+ // 2 个场景就是 272 B ≈68 tok/轮),唯一要求是别夹在 `## Scene: X` 与条目之间把分组和
432
+ // 内容隔开 —— 收尾两全:板块级只出现一次,也不隔开任何东西。
433
433
  //
434
- // 板块标题还是 `##`、与场景分组平级,放顶层确实分不清它管谁;现在板块升成 `#` 一级、
435
- // 场景分组是 `##` 二级,放在两者之间就是明确的"板块级说明"。
436
- return `${note}\n\n${chunks.join('\n')}`;
434
+ // 句式随之从"引入"改"收束":原句以冒号结尾(`…this is the complete set:**:`)引出清单,
435
+ // 挪到后面就成了没着落的悬空引号 —— 改句号收尾(常量里一并改)。
436
+ return `${chunks.join('\n')}\n\n${note}`;
437
437
  };
438
438
  const sceneLabelOf = (scene) => sceneLabel(scene);
439
439
  /** 未注入清单 + 截断标记,在 `space` 字节内尽量列全(放不下的折叠为一行计数)。 */
package/lib/ops/compat.js CHANGED
@@ -9,7 +9,7 @@
9
9
  import { EXPECTED_MIN_HOST_VERSION, EXPECTED_PEER_RANGE, VERIFIED_HOST_VERSION, isSourceInstall, routeFor, summarize, } from '../compat/probe.js';
10
10
  import { INJECT_DOMAIN_KEYS } from '../context-inject.js';
11
11
  import { MCP_TOOL_PREFIX } from '../host-names.js';
12
- import { assessPresetReach } from '../compat/preset-reach.js';
12
+ import { assessPresetReach, readPatchCarrierPresence } from '../compat/preset-reach.js';
13
13
  import { runtimeNotes } from '../compat/runtime-notes.js';
14
14
  import { AGENTS_MD_REFRESH_PACKAGE } from '../compat/host-contracts.js';
15
15
  import { pluginLog } from '../skills/service.js';
@@ -138,9 +138,21 @@ export function buildCompatOps(deps) {
138
138
  mcpTools = undefined;
139
139
  }
140
140
  const settings = await deps.readInjectSettings();
141
+ // 载体行的 patch 第二来源:组合里缺席、patch 挂了就算挂着(与注入侧同一口径)。
142
+ // 读不到(读取器缺席 / 抛错)就不并 —— 矩阵按组合口径如实显示。
143
+ let patchCarriers = undefined;
144
+ if (deps.profilePatchText !== undefined) {
145
+ try {
146
+ patchCarriers = readPatchCarrierPresence(await deps.profilePatchText());
147
+ }
148
+ catch {
149
+ patchCarriers = undefined;
150
+ }
151
+ }
141
152
  const report = await assessPresetReach(deps.presetRoster(), {
142
153
  mcpTools,
143
154
  inject: { underSuppressingPresets: settings.underSuppressingPresets, domains: settings.domains },
155
+ ...(patchCarriers === undefined ? {} : { patchCarriers }),
144
156
  });
145
157
  return { ok: true, ...report };
146
158
  }
@@ -16,7 +16,7 @@
16
16
  import { MCP_TOOL_PREFIX } from '../host-names.js';
17
17
  import { serverNameCandidates } from '../host-names.js';
18
18
  import { presetRosterOf } from '../compat/preset-reach.js';
19
- import { injectionFactsOf, readCompositionFacts, readCompositionText } from '../compat/preset-reach.js';
19
+ import { combinePresence, injectionFactsOf, readCompositionFacts, readCompositionText, readPatchCarrierPresence } from '../compat/preset-reach.js';
20
20
  /**
21
21
  * 问 adapter 的等待上限。官方签名 `resolveModelInfo(provider, model, signal?)` 的 signal 是
22
22
  * "optional cancellation for adapter-owned asynchronous lookup",所以给一个上限 —— 界面那一格
@@ -157,7 +157,22 @@ export function createCandidates(deps) {
157
157
  return hit.value;
158
158
  try {
159
159
  const text = await readCompositionText(roster, presetId);
160
- const value = injectionFactsOf(readCompositionFacts(text));
160
+ let facts = readCompositionFacts(text);
161
+ // 载体行在组合里缺席时再看一眼 patch(`cordis.patch.yml`):官方载体挂在宿主平面时
162
+ // 组合里没有那一行,不并这一路的话本插件的兜底目录会盖到官方头上。只在缺席时读
163
+ // patch(两次文件读取),挂上了 / 读不到就维持组合口径。
164
+ if ((facts.toolSkill === 'absent' || facts.agentInstructions === 'absent') && deps.profilePatchText !== undefined) {
165
+ try {
166
+ const patch = readPatchCarrierPresence(await deps.profilePatchText());
167
+ facts = {
168
+ ...facts,
169
+ agentInstructions: combinePresence(facts.agentInstructions, patch.agentInstructions),
170
+ toolSkill: combinePresence(facts.toolSkill, patch.toolSkill),
171
+ };
172
+ }
173
+ catch { /* patch 读不到 = 维持组合口径 */ }
174
+ }
175
+ const value = injectionFactsOf(facts);
161
176
  presetFactsCache.set(presetId, { at: Date.now(), value });
162
177
  return value;
163
178
  }