dsh-plugin-tool-management 0.22.1 → 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.
@@ -56,11 +56,51 @@ export function injectionFactsOf(facts) {
56
56
  carriesSkillCatalog: facts.toolSkill === 'mounted',
57
57
  };
58
58
  }
59
+ /**
60
+ * 两路在场性合并:`mounted` > `conditional` > `absent`(任一路明确挂着就算挂着)。
61
+ *
62
+ * 用于组合文本与宿主平面 patch 的并集 —— patch 挂了官方载体、组合里没有那一行时,
63
+ * 只看组合会把「官方在送」误判成「缺席」,本插件的兜底目录就会盖到官方那份上面。
64
+ */
65
+ export function combinePresence(a, b) {
66
+ if (a === 'mounted' || b === 'mounted')
67
+ return 'mounted';
68
+ if (a === 'conditional' || b === 'conditional')
69
+ return 'conditional';
70
+ return 'absent';
71
+ }
72
+ /**
73
+ * 从宿主平面 patch 文本(`cordis.patch.yml`,全局与 profile 两份都算)里解析两条官方
74
+ * 载体行(`dsh-agent-instructions` / `dsh-tool-skill`)的在场性 —— 组合文本里缺席时的
75
+ * **第二来源**。
76
+ *
77
+ * 为什么必须有它:{@link readCompositionFacts} 只读**预设自己的组合文本**,而 patch 是
78
+ * 另一条挂载路 —— 用户把载体行写进 `cordis.patch.yml` 时它对所有预设生效,组合文本里
79
+ * 却没有那一行。patch 的行形状与组合一致(条目也是 `id` / `name` / `disabled`),所以
80
+ * 同一套行扫描直接适用。patch 方言目前只有 `insert` 操作块(官方 presets 与实际部署都是),
81
+ * 行扫描不做块级区分;扫描失败按两路都缺席处理 —— 与"读不到组合"同一条保守口径。
82
+ */
83
+ export function readPatchCarrierPresence(text) {
84
+ try {
85
+ const lines = String(text ?? '').split(/\r?\n/);
86
+ return {
87
+ agentInstructions: presenceOf(lines, AGENT_INSTRUCTIONS_MODULE),
88
+ toolSkill: presenceOf(lines, TOOL_SKILL_MODULE),
89
+ };
90
+ }
91
+ catch {
92
+ return { agentInstructions: 'absent', toolSkill: 'absent' };
93
+ }
94
+ }
59
95
  /** 这几个模块挂没挂,直接决定可达性。 */
60
96
  const PERSONA_MODULE = '@deepseek-ai/dsh-persona';
61
97
  const AGENT_INSTRUCTIONS_MODULE = '@deepseek-ai/dsh-agent-instructions';
62
98
  const TOOL_SKILL_MODULE = '@deepseek-ai/dsh-tool-skill';
63
- const NAME_LINE = /^(\s*)name:\s*(['"]?)([^'"\s#]+)\2\s*(?:#.*)?$/;
99
+ // `name:` 行两种写法都要认:`- id: x` 后另起一行的 `name: y`(官方组合与 patch 都这么写),
100
+ // 以及 `- name: y` 同行写法 —— loader 的条目 id **可省**(`cordis-plugin-loader` 缺 id 时自己
101
+ // 生成随机 id),所以 `- name: y` 是合法行。只认前一种时,这种行整个看不见 → 载体被判成
102
+ // 缺席 → 本插件的兜底目录与官方那份同时进上下文(同一份技能清单发两遍)。
103
+ const NAME_LINE = /^(\s*)(?:-\s+)?name:\s*(['"]?)([^'"\s#]+)\2\s*(?:#.*)?$/;
64
104
  const ENTRY_LINE = /^(\s*)-\s/;
65
105
  const DISABLED_LINE = /^\s*disabled:\s*(.+?)\s*(?:#.*)?$/;
66
106
  const COMPLETE_LINE = /^\s*complete:\s*(true|false)\s*(?:#.*)?$/;
@@ -75,15 +115,22 @@ function indentOf(line) {
75
115
  *
76
116
  * 行从 `name:` 上方最近、缩进更浅的条目 bullet 开始(`cordis:group` 里的嵌套行仍拿到自己的
77
117
  * 块),到下一个缩进不深于该 bullet 的条目为止。
118
+ *
119
+ * ⚠️ `name:` 与条目 bullet **同行**(`- name: y`)时,块从它**自己**开始:不另找上方的
120
+ * bullet —— 那会越过 `- insert:` 找到整个 insert 组,于是组内**别的条目**的 `disabled:`
121
+ * 被算到这一行头上(载体被误判成缺席)。
78
122
  */
79
123
  function rowBlockAround(lines, nameIndex) {
80
124
  const nameIndent = indentOf(lines[nameIndex]);
81
125
  let start = nameIndex;
82
- for (let i = nameIndex - 1; i >= 0; i -= 1) {
83
- const entry = ENTRY_LINE.exec(lines[i]);
84
- if (entry !== null && entry[1].length < nameIndent) {
85
- start = i;
86
- break;
126
+ // `name:` 行自己就是条目 bullet(`- name: y` 写法)→ 块从这一行开始。
127
+ if (ENTRY_LINE.exec(lines[nameIndex]) === null) {
128
+ for (let i = nameIndex - 1; i >= 0; i -= 1) {
129
+ const entry = ENTRY_LINE.exec(lines[i]);
130
+ if (entry !== null && entry[1].length < nameIndent) {
131
+ start = i;
132
+ break;
133
+ }
87
134
  }
88
135
  }
89
136
  const entryIndent = indentOf(lines[start]);
@@ -236,8 +283,10 @@ export function deriveReach(facts, ctx) {
236
283
  // (注入侧对读不到的预设保守跳过兜底域)→ 如实报"判断不了"。
237
284
  if (personaUnknown)
238
285
  return 'unknown';
239
- // 官方行"可能挂着"(有条件启用)同样判断不了:注入侧对本插件兜底域的门槛是"官方明确没挂"
240
- // (`carrier !== false`),所以这种预设下兜底根本不会发,官方挂不挂只有挂载期才知道。
286
+ // 官方行"可能挂着"(有条件启用)时如实报"判断不了":`!!js` 表达式只有挂载后才有答案。
287
+ // 注意注入侧(`injectionFactsOf`)对 conditional 的口径是**按缺席兜底**(`=== 'mounted'`
288
+ // 才算官方在送)—— 宁可多一条兜底目录,也不让模型两手空空;与这里"报 unknown"并不冲突:
289
+ // 一个是给用户的矩阵口径(不猜),一个是给模型的动作口径(宁多勿缺)。
241
290
  if (carrier === 'conditional')
242
291
  return 'unknown';
243
292
  if (domainOff(domainKey))
@@ -349,14 +398,22 @@ async function composeRow(roster, meta, ctx) {
349
398
  };
350
399
  }
351
400
  const facts = readCompositionFacts(text);
352
- const reach = deriveReach(facts, ctx);
401
+ // 载体行并上 patch 第二来源:组合里缺席、patch 挂了的行按挂着算(与注入侧同一口径)。
402
+ // persona 事实只在组合里,patch 不参与。
403
+ const patch = ctx?.patchCarriers;
404
+ const merged = patch === undefined ? facts : {
405
+ ...facts,
406
+ agentInstructions: combinePresence(facts.agentInstructions, patch.agentInstructions),
407
+ toolSkill: combinePresence(facts.toolSkill, patch.toolSkill),
408
+ };
409
+ const reach = deriveReach(merged, ctx);
353
410
  return {
354
411
  ...base,
355
412
  personaComplete: facts.personaComplete,
356
413
  personaMounted: facts.personaMounted,
357
- agentInstructions: facts.agentInstructions,
358
- toolSkill: facts.toolSkill,
359
- suppressing: isSuppressingPreset(facts),
414
+ agentInstructions: merged.agentInstructions,
415
+ toolSkill: merged.toolSkill,
416
+ suppressing: isSuppressingPreset(merged),
360
417
  ...reach,
361
418
  ...(facts.parseFailure === undefined ? {} : { reason: `解析组合失败:${facts.parseFailure}` }),
362
419
  };