dsh-plugin-tool-management 0.22.2 → 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.
- package/CHANGELOG.md +1395 -1341
- package/README.md +177 -176
- package/README_EN.md +177 -176
- package/docs/UPDATE.md +49 -47
- package/lib/catalog-caps.js +22 -0
- package/lib/client.js +4797 -4544
- package/lib/compat/host-contracts.js +18 -3
- package/lib/compat/preset-reach.js +69 -12
- package/lib/confirm-gate.js +49 -18
- package/lib/context-inject-contract.js +2 -1
- package/lib/context-inject-frame.js +100 -48
- package/lib/context-inject-select.js +28 -0
- package/lib/index.js +258 -73
- package/lib/legacy-tool-names.js +46 -0
- package/lib/mcp/manager.js +13 -1
- package/lib/mcp/secret-guard.js +27 -0
- package/lib/mcp/state-section.js +25 -11
- package/lib/memories/archive.js +44 -0
- package/lib/memories/constants.js +9 -7
- package/lib/memories/index-io.js +4 -1
- package/lib/memories/snapshot.js +8 -8
- package/lib/op-registry.js +5 -1
- package/lib/ops/compat.js +13 -1
- package/lib/ops/scene-capture.js +72 -0
- package/lib/scenes/candidates.js +17 -2
- package/lib/scope/scope-overrides.js +9 -2
- package/lib/settings-sidecars.js +9 -2
- package/lib/skills/catalog.js +46 -14
- package/lib/skills/provider-registration.js +41 -4
- package/lib/skills/service.js +4 -4
- package/lib/subagents/catalog.js +24 -10
- package/lib/subagents/run-provider.js +41 -10
- package/lib/subagents/tools.js +63 -7
- package/lib/tool-table-switch.js +41 -4
- package/lib/tools/control.js +158 -0
- package/lib/tools/deps.js +88 -0
- package/lib/tools/mcp.js +35 -10
- package/lib/tools/memory.js +9 -5
- package/lib/tools/prompt.js +7 -8
- package/lib/tools/remove.js +84 -65
- package/lib/tools/scene.js +179 -76
- package/lib/tools/skills.js +13 -8
- package/lib/tools/subagent.js +19 -10
- package/lib/tools/table.js +92 -57
- package/lib/trash-id.js +3 -2
- package/package.json +152 -152
|
@@ -241,16 +241,31 @@ export const HOST_BEHAVIOR_CONTRACTS = [
|
|
|
241
241
|
},
|
|
242
242
|
{
|
|
243
243
|
package: '@deepseek-ai/dsh-skill',
|
|
244
|
-
feature: '技能 provider
|
|
245
|
-
impact: '
|
|
244
|
+
feature: '技能 provider 注册、候选协议与按会话分层的清单',
|
|
245
|
+
impact: '技能启停、官方内置技能接管与技能目录会静默失效;技能清单会串到别的会话',
|
|
246
246
|
markers: [
|
|
247
247
|
{ needle: 'registerProvider', why: 'provider 注册入口(全局层与每个 agent 层各注册一份)' },
|
|
248
248
|
{ needle: 'invalidate', why: '注册生命周期里的失效通知(来源变化后重读候选)' },
|
|
249
249
|
{ needle: 'candidates', why: 'provider 候选观测的 candidates 字段' },
|
|
250
250
|
{ needle: 'complete', why: '候选观测的完成标记(未完成不缓存)' },
|
|
251
251
|
{ needle: 'locator', why: '候选上的发现定位符(get 时原样带回)' },
|
|
252
|
+
{ needle: 'scopeChainOf', why: '官方清单按查看方 agent 的 scope 链分层(清单按会话隔离的依据)' },
|
|
253
|
+
{ needle: 'provider.list(options)', why: 'provider 拿到含 scope 的同一份 options(provider 按会话收紧的依据)' },
|
|
252
254
|
],
|
|
253
|
-
manual: 'provider 的 list/get 返回形状与 control.signal / control.invalidate 的调用时序只能核对字符串:探测里真注册一个 provider 会进入技能目录并触发失效事件。',
|
|
255
|
+
manual: 'provider 的 list/get 返回形状与 control.signal / control.invalidate 的调用时序只能核对字符串:探测里真注册一个 provider 会进入技能目录并触发失效事件。scope 链的语义(查看方 agent 决定分层)同样只能核对字符串。',
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
package: '@deepseek-ai/dsh-api-session-controller',
|
|
259
|
+
feature: '会话侧技能清单的 scope 解析',
|
|
260
|
+
impact: '宿主 `/` 菜单的「技能」段与官方 skill 工具不再按会话区分:别的会话开着的技能会串过来',
|
|
261
|
+
// 与客户端 UI 契约那一份同包 —— 那边盯客户端 bundle,这边盯服务端 RPC 怎么取 scope。
|
|
262
|
+
// 同样按可选契约报:这个包缺席是部署形态,不是故障。
|
|
263
|
+
optional: true,
|
|
264
|
+
markers: [
|
|
265
|
+
{ needle: 'scope = live ?? lease?.key', why: '查看会话的 agent(活着就取它,否则取预设租约)当 scope 传给官方清单' },
|
|
266
|
+
{ needle: 'isUserInvocable', why: '官方清单只保留用户可调用的技能(被收紧的条目据此不再出现)' },
|
|
267
|
+
],
|
|
268
|
+
manual: 'scope 的取值链(活着的 agent → 预设租约 → 无)只能核对字符串:真正验证要开两个会话各开一条技能,看清单是否分开。',
|
|
254
269
|
},
|
|
255
270
|
{
|
|
256
271
|
package: '@deepseek-ai/dsh-host-plugin-inventory',
|
|
@@ -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
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
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:
|
|
358
|
-
toolSkill:
|
|
359
|
-
suppressing: isSuppressingPreset(
|
|
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
|
};
|
package/lib/confirm-gate.js
CHANGED
|
@@ -21,16 +21,13 @@
|
|
|
21
21
|
* 不在这张表里的工具仍走 `CONFIRM_LABELS` 的既有分支(无条件问,或按设置开关问)。
|
|
22
22
|
*/
|
|
23
23
|
export const ARG_CONDITIONAL_CONFIRM_TOOLS = new Set([
|
|
24
|
-
'
|
|
25
|
-
'skill_manager_remove',
|
|
26
|
-
'subagent_manager_remove',
|
|
27
|
-
'scene_manager_remove',
|
|
28
|
-
'prompt_manager_remove',
|
|
24
|
+
'plugin_manager_remove',
|
|
29
25
|
'prompt_manager_apply',
|
|
30
26
|
'mcp_manager_switch',
|
|
31
27
|
'memory_manager_switch',
|
|
32
28
|
'skill_manager_switch',
|
|
33
29
|
'subagent_manager_switch',
|
|
30
|
+
'tool_manager_tools',
|
|
34
31
|
]);
|
|
35
32
|
/** 取一个必填字符串参数;不是非空字符串就返回空串。 */
|
|
36
33
|
function text(value) {
|
|
@@ -40,18 +37,21 @@ function text(value) {
|
|
|
40
37
|
function machineWide(args, mode) {
|
|
41
38
|
return mode === 'global' || args.scope === 'global';
|
|
42
39
|
}
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
40
|
+
/**
|
|
41
|
+
* 删除类工具的域 → 卡上回显的名词。
|
|
42
|
+
*
|
|
43
|
+
* 删除是一条**跨域**工具(`plugin_manager_remove`),所以名词由 `domain` 参数决定,
|
|
44
|
+
* 不由工具名决定 —— 五个域合进一条之后,工具名不再携带是删什么。
|
|
45
|
+
*
|
|
46
|
+
* 域不认识(或没给)时返回 undefined:那种调用注定失败,问了也是一次无效审批。
|
|
47
|
+
*/
|
|
48
|
+
const REMOVE_SUBJECT = {
|
|
49
|
+
memory: 'memory',
|
|
50
|
+
skill: 'skill',
|
|
51
|
+
persona: 'persona',
|
|
52
|
+
preset: 'AGENTS.md preset',
|
|
53
|
+
scene: 'scene',
|
|
54
|
+
};
|
|
55
55
|
/**
|
|
56
56
|
* 这一次调用要不要问用户;要问就返回卡上那句理由,不问返回 `null`。
|
|
57
57
|
*
|
|
@@ -75,7 +75,10 @@ export function argConditionalConfirmReason(name, rawArgs, mode) {
|
|
|
75
75
|
// 缺 id 时工具自己会拒;先弹一张卡等于让用户批准一次注定失败的删除。
|
|
76
76
|
if (id === '')
|
|
77
77
|
return null;
|
|
78
|
-
|
|
78
|
+
const subject = REMOVE_SUBJECT[text(args.domain)];
|
|
79
|
+
if (subject === undefined)
|
|
80
|
+
return null;
|
|
81
|
+
return `Delete ${subject}「${id}」 — moved to the trash, restorable from the panel.`;
|
|
79
82
|
}
|
|
80
83
|
if (name === 'prompt_manager_apply') {
|
|
81
84
|
// apply=false 是撤销(回到本轮应用之前),可逆,不问。
|
|
@@ -130,5 +133,33 @@ export function argConditionalConfirmReason(name, rawArgs, mode) {
|
|
|
130
133
|
}
|
|
131
134
|
return `${args.prefer ? 'Make' : 'Stop preferring'} the copy of ${label}「${key}」 win its name collision, machine-wide.`;
|
|
132
135
|
}
|
|
136
|
+
if (name === 'tool_manager_tools') {
|
|
137
|
+
// 会话层自开不弹(只动管着这个对话的那一层,随时可退);隔离关掉时那一层就是全局,
|
|
138
|
+
// 动的是所有对话 —— 与三个 `_switch` 在全局粒度下的口径一致,要问。
|
|
139
|
+
// 修复类动作要问:它会把**已损坏的侧车改名留存**、按空表继续 —— 那是一次不可逆的
|
|
140
|
+
// 数据处置(原始文件还在,但插件从此不再读它),与「换个开关」不是一档。
|
|
141
|
+
if (action === 'repair') {
|
|
142
|
+
const target = text(args.target);
|
|
143
|
+
if (target === '')
|
|
144
|
+
return null;
|
|
145
|
+
const subject = target === 'memory-index' ? '记忆索引'
|
|
146
|
+
: target === 'scope' ? '作用域侧车'
|
|
147
|
+
: target === 'mcp-disabled' ? 'MCP 停用表'
|
|
148
|
+
: '';
|
|
149
|
+
if (subject === '')
|
|
150
|
+
return null;
|
|
151
|
+
return `Repair the ${subject} — the damaged file is renamed aside and the plugin continues with an empty table. Anything it held is no longer applied.`;
|
|
152
|
+
}
|
|
153
|
+
if (action !== 'enable' && action !== 'disable')
|
|
154
|
+
return null;
|
|
155
|
+
if (!machineWide(args, mode))
|
|
156
|
+
return null;
|
|
157
|
+
const names = Array.isArray(args.tools)
|
|
158
|
+
? args.tools.map((n) => text(n)).filter((n) => n !== '')
|
|
159
|
+
: [];
|
|
160
|
+
if (names.length === 0)
|
|
161
|
+
return null;
|
|
162
|
+
return `Turn ${action === 'enable' ? 'on' : 'off'} ${names.join(', ')} for every conversation (machine-wide tool table).`;
|
|
163
|
+
}
|
|
133
164
|
return null;
|
|
134
165
|
}
|
|
@@ -108,8 +108,9 @@ export const CARRIER_FACT_OF = {
|
|
|
108
108
|
prompt: 'carriesAgentsMd',
|
|
109
109
|
skills: 'carriesSkillCatalog',
|
|
110
110
|
};
|
|
111
|
-
/**
|
|
111
|
+
/** 出厂注入设置:六个域全开,目录上限全走出厂值,由用户或档案再收窄。 */
|
|
112
112
|
export const DEFAULT_INJECT_SETTINGS = {
|
|
113
113
|
underSuppressingPresets: false,
|
|
114
114
|
domains: { scene: true, memory: true, mcp: true, skills: true, subagents: true, prompt: true },
|
|
115
|
+
catalogCaps: {},
|
|
115
116
|
};
|
|
@@ -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 =
|
|
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
|
-
//
|
|
85
|
-
//
|
|
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
|
-
//
|
|
93
|
-
//
|
|
94
|
-
|
|
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)→ 两种信号都没有 →
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
-
//
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
//
|
|
162
|
-
//
|
|
163
|
-
how: ({
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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`
|
|
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
|
-
|
|
322
|
-
|
|
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('',
|
|
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
|
/**
|