@chaoset/adaptive-perf 0.4.0 → 0.6.0
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/README.md +85 -14
- package/client/client.cjs +58 -0
- package/cordis.patch.yml +12 -2
- package/lib/index.mjs +780 -46
- package/package.json +8 -3
package/lib/index.mjs
CHANGED
|
@@ -7,32 +7,46 @@
|
|
|
7
7
|
* "Current runtime context" 快照(文件策略 / 审批策略等动态段);
|
|
8
8
|
* 2. 工具目录极小(只有 bash + str_replace_editor)—— 每个请求的
|
|
9
9
|
* tool schema 与(PTC 的)SDK 参考段都随之变小;
|
|
10
|
-
* 3. persona 为 complete 固定提示,无其它全局 prompt
|
|
10
|
+
* 3. persona 为 complete 固定提示,无其它全局 prompt 段;
|
|
11
|
+
* 4. 不挂 skill 目录提醒(~9KB)与 AGENTS.md 摘要注入。
|
|
11
12
|
*
|
|
12
|
-
*
|
|
13
|
+
* 本插件在多个维度上做"动态自适应"(而不是静态裁剪),全部参照
|
|
14
|
+
* dsh-anchored-standard(https://github.com/xiaobright/dsh-anchored-standard)
|
|
15
|
+
* 的实测结论:
|
|
13
16
|
* A. 运行时上下文抑制:对目标 preset 的会话调用
|
|
14
17
|
* agent.ctx.systemPrompt.suppressRuntimeContext()(与极简模式同一机制),
|
|
15
18
|
* 每次请求省掉快照文本,零功能损失。
|
|
16
|
-
* B.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
19
|
+
* B. 真实 Minimal 工具对(bootstrap.realPair,0.5.0 新增):首轮"轨迹"
|
|
20
|
+
* (模型思维链风格)由请求 #1 可见的**工具 schema** 决定,且只有与
|
|
21
|
+
* Minimal 逐字相同的 schema 才能锚定(issue #11:真实工具对 5/5 锚定,
|
|
22
|
+
* 任何 standard 系 schema——包括 sandboxed bash/read——11/11 落入
|
|
23
|
+
* standard-like)。仅收窄目录不够:standard/code preset 根本没有
|
|
24
|
+
* str_replace_editor,其 bash 也是 sandboxed schema。因此本插件把
|
|
25
|
+
* Minimal 的**真实工具对**(持久 PTY bash + str_replace_editor,官方
|
|
26
|
+
* minimal preset 同一批插件、同一份描述)挂进 agent 作用域工具层
|
|
27
|
+
* (scoped registration 按名阴影继承工具),首轮目录 = 真实工具对;
|
|
28
|
+
* PTC 的 SDK 参考段同样按可见目录渲染,同步缩小。
|
|
29
|
+
* C. 首轮锚定(bootstrap):请求 #1 只暴露真实工具对,剥离自动注入上下文
|
|
30
|
+
* (技能目录提醒 skill-catalog、AGENTS.md 摘要 agent-instructions;
|
|
31
|
+
* 用户主动的技能手势不过滤);首个**持久**晋升信号(首个 tool/call 或
|
|
32
|
+
* assistant/message,promoteOn 可选 either/tool-call/assistant-message)
|
|
33
|
+
* 后进入 **resident 目录**:工具对 + 常驻发现工具(dev_tool_search /
|
|
34
|
+
* skill_search / skill_load)+ 已解锁工具,而不是一次性 dump 完整
|
|
35
|
+
* Standard 目录(避免 post-promotion regression);阶段从持久会话事件
|
|
36
|
+
* 推导,resume/reload 不丢状态;compaction/end 之后回到受控目录
|
|
37
|
+
* (工具对 + compactionTools)直到新的晋升信号(纪元感知);
|
|
38
|
+
* bootstrap.maxTokens(可选)给请求 #1 封顶输出预算,晋升后剥离。
|
|
39
|
+
* D. 常驻上下文抑制(suppressInjectedContext,0.5.0 新增):技能目录提醒
|
|
40
|
+
* 与 AGENTS.md 摘要**不再在晋升后恢复**——参考实现实测它们即使在后置
|
|
41
|
+
* 阶段也扰动轨迹且每个请求多耗数千 token。替代品:
|
|
42
|
+
* - skill_search / skill_load:按需发现并注入单个技能的完整说明
|
|
43
|
+
* (晋升后常驻,替代 ~9KB 的 <available_skills> 注入);
|
|
44
|
+
* - instruction-hint:晋升后只注入**一次**的短提示——"这些指令文件
|
|
45
|
+
* 存在,需要时自己读",而不是每请求 dump 全文(文件探测走宿主 fs,
|
|
46
|
+
* 探测失败不注入,绝不抛错)。
|
|
47
|
+
* E. 工具目录自适应精简:会话启动时按"工具族"默认隐藏高开销低频工具
|
|
33
48
|
* (子代理 / 工作流 / ralph / goal 等编排类),只保留核心编码工具,
|
|
34
|
-
*
|
|
35
|
-
* 在会话内"单调升级"放行对应工具族(只升不降,限制请求缓存失效次数):
|
|
49
|
+
* 随后根据两类信号在会话内"单调升级"放行对应工具族(只升不降):
|
|
36
50
|
* - 关键词信号:用户消息命中某工具族的触发词(如"子代理")→ 放行该族;
|
|
37
51
|
* - 失败信号:PTC 的 run_code 程序调用被隐藏工具报 UNKNOWN_TOOL
|
|
38
52
|
* (tools/result 失败文本含工具名)→ 放行该族,下次程序即可调用。
|
|
@@ -40,24 +54,28 @@
|
|
|
40
54
|
* 实现全部使用 dsh 公开服务契约(Inspect 确认):
|
|
41
55
|
* - ctx.agentPresets.composedPreset(agent.ctx) 读取会话所属 preset
|
|
42
56
|
* - agent.ctx.systemPrompt.suppressRuntimeContext() 抑制上下文快照
|
|
57
|
+
* - agent.ctx.systemPrompt.section() 按名阴影 prompt 段(persona/引导段)
|
|
43
58
|
* - agent.ctx.tools.schemas(agent) 读取该 agent 当前可见工具(限制交集)
|
|
44
59
|
* - agent.ctx.tools.restrict({ deny }) 按 agent 作用域裁剪继承工具
|
|
45
|
-
* -
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
60
|
+
* - agent.ctx.tools.register() 在 agent 作用域注册工具(按名阴影继承工具,
|
|
61
|
+
* 自身层注册不受 restrict 影响——view() 对 own layer 豁免)
|
|
62
|
+
* - agent.ctx.plugin() 挂载官方 minimal preset 同款插件(持久 bash /
|
|
63
|
+
* str_replace_editor / 其依赖的 terminals 与本地 fs)
|
|
64
|
+
* - agent/pre-step(waterfall) 剥离自动注入上下文 + 注入 instruction-hint
|
|
49
65
|
* - agent/request(waterfall) 首轮输出预算封顶
|
|
50
66
|
* - session/event 增量喂入持久事件(晋升 / compaction 纪元)
|
|
51
67
|
* - agent/created、agent/disposed、agent/inbox/inserted、tools/result 事件
|
|
52
68
|
* 监听器都注册在 host 根作用域(与 dsh-agent-presets 自身同款用法),事件按
|
|
53
|
-
* scope
|
|
69
|
+
* scope 过滤分发,子作用域派发的事件根监听器可收到;两个 waterfall 均以
|
|
54
70
|
* prepend 注册保证"最外层"(剥离是最后一道变换)。
|
|
55
71
|
*
|
|
56
72
|
* 配置:cordis.patch.yml 的 config(安装默认)与
|
|
57
73
|
* ~/.dsh/plugins/adaptive-perf/config.json(设置页 UI,权威)合并,
|
|
58
74
|
* 保存后热生效(新会话立即生效;已运行会话按新配置重算限制)。
|
|
59
75
|
*
|
|
60
|
-
*
|
|
76
|
+
* 依赖:真实工具对需要官方插件包(@deepseek-ai/dsh-terminal 等,声明为
|
|
77
|
+
* optionalDependencies)。它们不可用时本插件自动降级(告警 + 退回旧行为:
|
|
78
|
+
* 只收窄目录、不替换 schema),绝不拖垮 harness。
|
|
61
79
|
*/
|
|
62
80
|
|
|
63
81
|
import { createConfigStore } from './config-store.mjs';
|
|
@@ -71,6 +89,14 @@ try {
|
|
|
71
89
|
console.warn('adaptive-perf: settings gateway unavailable: ' + (error && error.message || error));
|
|
72
90
|
}
|
|
73
91
|
|
|
92
|
+
// 宿主 settings 体系的 schema 库(dsh-settings 0.1.0-rc.7+ 用 schemastery)。
|
|
93
|
+
// DSH profile 的 hoisted node_modules 直接解析;仓库测试环境无此包时为
|
|
94
|
+
// null,settings namespace 注册段静默跳过(fail-safe)。
|
|
95
|
+
let Schema = null;
|
|
96
|
+
try {
|
|
97
|
+
({ default: Schema } = await import('@deepseek-ai/schemastery'));
|
|
98
|
+
} catch {}
|
|
99
|
+
|
|
74
100
|
export const name = 'adaptive-perf';
|
|
75
101
|
|
|
76
102
|
/**
|
|
@@ -91,14 +117,34 @@ export const DEFAULT_CONFIG = {
|
|
|
91
117
|
enabled: true,
|
|
92
118
|
/** 应用自适应的 agent preset 列表(composedPreset 返回值)。 */
|
|
93
119
|
presets: ['standard', 'code'],
|
|
120
|
+
/**
|
|
121
|
+
* 默认策略(0.6.0):功能优先,全部优化 opt-in。旧版把下列机制默认
|
|
122
|
+
* 开启,导致 standard/PTC 模式功能缺失(工具族从目录删除 → PTC 程序
|
|
123
|
+
* 调用直接 UNKNOWN_TOOL;技能目录/指令摘要被剥离;官方引导段被屏蔽;
|
|
124
|
+
* 首轮只剩两个工具)。这些机制的收益本质是"砍上下文换 token",没有
|
|
125
|
+
* 无损形态,因此默认全部关闭,保持官方 preset 的完整功能;需要省
|
|
126
|
+
* token 时按需开启(设置页或 config.json),开启即接受相应的功能
|
|
127
|
+
* 约束(关键词/失败信号放行、skill_search 按需发现等补偿机制仍在)。
|
|
128
|
+
*/
|
|
94
129
|
/** 抑制运行时上下文快照(等同极简模式的 includeRuntimeContext: false)。 */
|
|
95
|
-
suppressRuntimeContext:
|
|
130
|
+
suppressRuntimeContext: false,
|
|
96
131
|
/** 会话启动时默认隐藏编排类工具族(核心编码工具始终保留)。 */
|
|
97
|
-
leanByDefault:
|
|
132
|
+
leanByDefault: false,
|
|
98
133
|
/** 用户消息命中工具族触发词时自动放行该族(会话内单调)。 */
|
|
99
134
|
escalateOnKeyword: true,
|
|
100
135
|
/** 工具调用失败(UNKNOWN_TOOL 文本含隐藏工具名)时自动放行该族。 */
|
|
101
136
|
escalateOnUnknownTool: true,
|
|
137
|
+
/**
|
|
138
|
+
* 常驻上下文抑制(0.5.0):true = 整个会话剥离自动注入上下文
|
|
139
|
+
* (skill-catalog 技能目录提醒、agent-instructions AGENTS.md 摘要),
|
|
140
|
+
* 不再像旧版那样在晋升后恢复——替代品是 skill_search/skill_load 按需发现
|
|
141
|
+
* 与 instruction-hint 一次性提示。false = 只在 bootstrap(请求 #1)剥离。
|
|
142
|
+
*/
|
|
143
|
+
suppressInjectedContext: false,
|
|
144
|
+
/** 晋升后常驻 skill_search / skill_load 两个按需技能发现工具。 */
|
|
145
|
+
skillDiscovery: true,
|
|
146
|
+
/** 晋升后注入一次"指令文件存在,需要时自读"的短提示(替代全文注入)。 */
|
|
147
|
+
instructionHint: true,
|
|
102
148
|
/** 核心编码工具(不进入任何限制族;此处仅作文档展示)。 */
|
|
103
149
|
coreTools: [
|
|
104
150
|
'bash', 'read', 'write', 'edit', 'glob', 'grep', 'read_image',
|
|
@@ -131,7 +177,14 @@ export const DEFAULT_CONFIG = {
|
|
|
131
177
|
/** 首轮锚定(参照 dsh-anchored-standard)。 */
|
|
132
178
|
bootstrap: {
|
|
133
179
|
/** 是否启用首轮锚定。 */
|
|
134
|
-
enabled:
|
|
180
|
+
enabled: false,
|
|
181
|
+
/**
|
|
182
|
+
* 是否挂载真实 Minimal 工具对(0.5.0):把官方 minimal preset 的持久
|
|
183
|
+
* PTY bash + str_replace_editor 挂进 agent 作用域(按名阴影 standard 的
|
|
184
|
+
* sandboxed bash),使请求 #1 的 schema 与 Minimal 逐字相同。依赖
|
|
185
|
+
* @deepseek-ai 官方插件包,不可用时自动降级为旧行为(仅收窄目录)。
|
|
186
|
+
*/
|
|
187
|
+
realPair: true,
|
|
135
188
|
/** 请求 #1 可见的工具(真实 Minimal 工具对)。 */
|
|
136
189
|
tools: ['bash', 'str_replace_editor'],
|
|
137
190
|
/** 晋升触发:either(默认)/ tool-call / assistant-message。 */
|
|
@@ -140,6 +193,8 @@ export const DEFAULT_CONFIG = {
|
|
|
140
193
|
suppressedContextSources: ['skill-catalog', 'agent-instructions'],
|
|
141
194
|
/** compaction/end 之后、再次晋升前可用的额外核心工作集。 */
|
|
142
195
|
compactionTools: ['read', 'write', 'edit', 'glob', 'grep', 'todo_write', 'ask_user_question'],
|
|
196
|
+
/** 晋升后常驻的按需发现工具(dsh-anchored-standard 的 resident discovery set)。 */
|
|
197
|
+
discoveryTools: ['dev_tool_search', 'skill_search', 'skill_load'],
|
|
143
198
|
/** 请求 #1 的输出预算封顶(token);0 = 不封顶(opt-in)。 */
|
|
144
199
|
maxTokens: 0,
|
|
145
200
|
},
|
|
@@ -158,7 +213,7 @@ export const DEFAULT_CONFIG = {
|
|
|
158
213
|
*/
|
|
159
214
|
minimalPrompt: {
|
|
160
215
|
/** 是否启用极简提示词层。 */
|
|
161
|
-
enabled:
|
|
216
|
+
enabled: false,
|
|
162
217
|
/** 替换后的 persona 文本;与极简模式相同可完全对齐语域。留空不替换。 */
|
|
163
218
|
persona: 'You are a helpful software engineer assistant.',
|
|
164
219
|
/** 屏蔽全局引导段(identity / source / web-surface)。 */
|
|
@@ -218,10 +273,12 @@ export function normalizeConfig(source, defaults = DEFAULT_CONFIG) {
|
|
|
218
273
|
const maxTokens = Number.isSafeInteger(maxTokensRaw) && maxTokensRaw > 0 ? maxTokensRaw : 0;
|
|
219
274
|
const bootstrap = {
|
|
220
275
|
enabled: boolValue(rawBootstrap.enabled, db.enabled),
|
|
276
|
+
realPair: boolValue(rawBootstrap.realPair, db.realPair),
|
|
221
277
|
tools: stringList(rawBootstrap.tools, db.tools),
|
|
222
278
|
promoteOn,
|
|
223
279
|
suppressedContextSources: stringListOrEmpty(rawBootstrap.suppressedContextSources, db.suppressedContextSources),
|
|
224
280
|
compactionTools: stringListOrEmpty(rawBootstrap.compactionTools, db.compactionTools),
|
|
281
|
+
discoveryTools: stringListOrEmpty(rawBootstrap.discoveryTools, db.discoveryTools),
|
|
225
282
|
maxTokens,
|
|
226
283
|
};
|
|
227
284
|
const rawMP = raw.minimalPrompt !== null && typeof raw.minimalPrompt === 'object' && !Array.isArray(raw.minimalPrompt)
|
|
@@ -240,6 +297,9 @@ export function normalizeConfig(source, defaults = DEFAULT_CONFIG) {
|
|
|
240
297
|
leanByDefault: boolValue(merged.leanByDefault, defaults.leanByDefault),
|
|
241
298
|
escalateOnKeyword: boolValue(merged.escalateOnKeyword, defaults.escalateOnKeyword),
|
|
242
299
|
escalateOnUnknownTool: boolValue(merged.escalateOnUnknownTool, defaults.escalateOnUnknownTool),
|
|
300
|
+
suppressInjectedContext: boolValue(merged.suppressInjectedContext, defaults.suppressInjectedContext),
|
|
301
|
+
skillDiscovery: boolValue(merged.skillDiscovery, defaults.skillDiscovery),
|
|
302
|
+
instructionHint: boolValue(merged.instructionHint, defaults.instructionHint),
|
|
243
303
|
coreTools: stringList(merged.coreTools, defaults.coreTools),
|
|
244
304
|
families,
|
|
245
305
|
bootstrap,
|
|
@@ -252,7 +312,8 @@ export function validateConfig(partial) {
|
|
|
252
312
|
if (partial === null || typeof partial !== 'object' || Array.isArray(partial)) {
|
|
253
313
|
throw new TypeError('adaptive-perf config must be a plain object');
|
|
254
314
|
}
|
|
255
|
-
const boolFields = ['enabled', 'suppressRuntimeContext', 'leanByDefault', 'escalateOnKeyword', 'escalateOnUnknownTool'
|
|
315
|
+
const boolFields = ['enabled', 'suppressRuntimeContext', 'leanByDefault', 'escalateOnKeyword', 'escalateOnUnknownTool',
|
|
316
|
+
'suppressInjectedContext', 'skillDiscovery', 'instructionHint'];
|
|
256
317
|
for (const key of boolFields) {
|
|
257
318
|
if (partial[key] !== void 0 && typeof partial[key] !== 'boolean') {
|
|
258
319
|
throw new TypeError(`adaptive-perf config field "${key}" must be a boolean`);
|
|
@@ -289,13 +350,16 @@ export function validateConfig(partial) {
|
|
|
289
350
|
if (b.enabled !== void 0 && typeof b.enabled !== 'boolean') {
|
|
290
351
|
throw new TypeError('adaptive-perf config field "bootstrap.enabled" must be a boolean');
|
|
291
352
|
}
|
|
353
|
+
if (b.realPair !== void 0 && typeof b.realPair !== 'boolean') {
|
|
354
|
+
throw new TypeError('adaptive-perf config field "bootstrap.realPair" must be a boolean');
|
|
355
|
+
}
|
|
292
356
|
if (b.promoteOn !== void 0 && !['either', 'tool-call', 'assistant-message'].includes(b.promoteOn)) {
|
|
293
357
|
throw new TypeError('adaptive-perf config field "bootstrap.promoteOn" must be "either" | "tool-call" | "assistant-message"');
|
|
294
358
|
}
|
|
295
359
|
if (b.maxTokens !== void 0 && !(Number.isSafeInteger(b.maxTokens) && b.maxTokens >= 0)) {
|
|
296
360
|
throw new TypeError('adaptive-perf config field "bootstrap.maxTokens" must be a non-negative safe integer');
|
|
297
361
|
}
|
|
298
|
-
for (const key of ['tools', 'suppressedContextSources', 'compactionTools']) {
|
|
362
|
+
for (const key of ['tools', 'suppressedContextSources', 'compactionTools', 'discoveryTools']) {
|
|
299
363
|
if (b[key] !== void 0 && !(Array.isArray(b[key]) && b[key].every((v) => typeof v === 'string'))) {
|
|
300
364
|
throw new TypeError(`adaptive-perf config field "bootstrap.${key}" must be an array of strings`);
|
|
301
365
|
}
|
|
@@ -371,6 +435,416 @@ export function collectFailureText(result) {
|
|
|
371
435
|
return parts.join('\n');
|
|
372
436
|
}
|
|
373
437
|
|
|
438
|
+
// ── 真实 Minimal 工具对(0.5.0,参照 dsh-anchored-standard issue #11)──────
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* 官方 minimal preset 的持久 bash 工具描述,逐字一致。schema(参数)由
|
|
442
|
+
* @deepseek-ai/dsh-tool-bash-persistent 提供,与 minimal preset 挂的是同一
|
|
443
|
+
* 个包;描述在这里显式传入,保证与 minimal 的 agent.cordis.yml 完全一致。
|
|
444
|
+
*/
|
|
445
|
+
export const MINIMAL_BASH_DESCRIPTION = [
|
|
446
|
+
'Run commands in a bash shell',
|
|
447
|
+
'* When invoking this tool, the contents of the "command" parameter does NOT need to be XML-escaped.',
|
|
448
|
+
"* You don't have access to the internet via this tool.",
|
|
449
|
+
'* You do have access to a mirror of common linux and python packages via apt and pip.',
|
|
450
|
+
'* State is persistent across command calls and discussions with the user.',
|
|
451
|
+
"* To inspect a particular line range of a file, e.g. lines 10-25, try 'sed -n 10,25p /path/to/the/file'.",
|
|
452
|
+
'* Please avoid commands that may produce a very large amount of output.',
|
|
453
|
+
"* Please run long lived commands in the background, e.g. 'sleep 10 &' or start a server in the background.",
|
|
454
|
+
].join('\n');
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* 被真实工具对按名阴影的工具引导段:standard 的 sandboxed bash 注册了
|
|
458
|
+
* `tool:bash`(order 105)引导段,挂载真实工具对后该文本已与可见工具不符,
|
|
459
|
+
* 按名阴影为空段(装配时丢弃)。
|
|
460
|
+
*/
|
|
461
|
+
export const TOOL_GUIDANCE_SHADOWS = [
|
|
462
|
+
['tool:bash', 105],
|
|
463
|
+
];
|
|
464
|
+
|
|
465
|
+
/** 真实工具对挂载所需的官方插件包说明符(声明在 optionalDependencies)。 */
|
|
466
|
+
export const REAL_PAIR_SPECS = {
|
|
467
|
+
terminal: '@deepseek-ai/dsh-terminal',
|
|
468
|
+
terminalBash: '@deepseek-ai/dsh-terminal-bash',
|
|
469
|
+
bashPersistent: '@deepseek-ai/dsh-tool-bash-persistent',
|
|
470
|
+
fsLocal: '@deepseek-ai/dsh-fs-local',
|
|
471
|
+
strReplaceEditor: '@deepseek-ai/dsh-tool-str-replace-editor',
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* 加载真实 Minimal 工具对所需模块。任一包不可用即整体返回 null(调用方
|
|
476
|
+
* 降级为旧行为),绝不抛出。
|
|
477
|
+
* @param importFn - 测试可注入的 import 实现(默认动态 import)。
|
|
478
|
+
*/
|
|
479
|
+
export async function loadRealPairModules(importFn) {
|
|
480
|
+
const dynamicImport = importFn ?? ((spec) => import(spec));
|
|
481
|
+
const modules = {};
|
|
482
|
+
for (const [key, spec] of Object.entries(REAL_PAIR_SPECS)) {
|
|
483
|
+
try {
|
|
484
|
+
const mod = await dynamicImport(spec);
|
|
485
|
+
modules[key] = mod?.default ?? mod;
|
|
486
|
+
} catch {
|
|
487
|
+
modules[key] = null;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
if (Object.keys(REAL_PAIR_SPECS).some((key) => modules[key] === null)) return null;
|
|
491
|
+
return modules;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* 计算真实工具对的挂载清单(纯函数,便于测试):
|
|
496
|
+
* 顺序 = 依赖在前(terminals → backend → bash;fs → editor)。
|
|
497
|
+
* @param modules - loadRealPairModules 的结果。
|
|
498
|
+
* @param cwd - str_replace_editor 本地 fs 的工作目录(会话 cwd)。
|
|
499
|
+
*/
|
|
500
|
+
export function realPairMounts(modules, cwd) {
|
|
501
|
+
if (modules === null || modules === void 0) return [];
|
|
502
|
+
const resolvedCwd = typeof cwd === 'string' && cwd.length > 0
|
|
503
|
+
? cwd
|
|
504
|
+
: (process.env.DSH_CWD && process.env.DSH_CWD.trim().length > 0 ? process.env.DSH_CWD : process.cwd());
|
|
505
|
+
return [
|
|
506
|
+
{ module: modules.terminal, config: {} },
|
|
507
|
+
{ module: modules.terminalBash, config: { timeoutMs: 300000 } },
|
|
508
|
+
{ module: modules.bashPersistent, config: { timeoutMs: 300000, description: MINIMAL_BASH_DESCRIPTION } },
|
|
509
|
+
{ module: modules.fsLocal, config: { cwd: resolvedCwd } },
|
|
510
|
+
{ module: modules.strReplaceEditor, config: { maxOutputChars: 16000 } },
|
|
511
|
+
];
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* 在 agent 作用域挂载真实工具对(scoped registration 按名阴影继承工具)。
|
|
516
|
+
* 每个挂载是一个独立 fiber,dispose 时全部副作用(工具/schema/服务)撤销。
|
|
517
|
+
* @param agent - 目标 agent(其 ctx 必须带 scope 标签)。
|
|
518
|
+
* @param mounts - realPairMounts 的结果。
|
|
519
|
+
* @param warn - 日志回调。
|
|
520
|
+
* @returns 可释放的 disposer 列表。
|
|
521
|
+
*/
|
|
522
|
+
export function mountRealPair(agent, mounts, warn) {
|
|
523
|
+
const disposers = [];
|
|
524
|
+
if (agent === null || typeof agent !== 'object' || typeof agent.ctx?.plugin !== 'function') return disposers;
|
|
525
|
+
for (const mount of mounts) {
|
|
526
|
+
if (mount?.module === null || mount?.module === void 0) continue;
|
|
527
|
+
try {
|
|
528
|
+
const fiber = agent.ctx.plugin(mount.module, mount.config ?? {});
|
|
529
|
+
disposers.push(() => {
|
|
530
|
+
try { fiber.dispose(); } catch {}
|
|
531
|
+
});
|
|
532
|
+
} catch (error) {
|
|
533
|
+
warn?.(`mountRealPair failed for ${String(mount.module?.name ?? 'module')}: ${String((error && error.message) || error)}`);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return disposers;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// ── instruction-hint(0.5.0,参照 dsh-anchored-standard)──────────────────
|
|
540
|
+
|
|
541
|
+
/** 项目链候选指令文件名(探测顺序)与用户全局候选。 */
|
|
542
|
+
export const INSTRUCTION_PROJECT_CANDIDATES = ['AGENTS.md', 'CLAUDE.md', 'AGENTS.local.md', 'CLAUDE.local.md'];
|
|
543
|
+
export const INSTRUCTION_USER_CANDIDATE = 'AGENTS.md';
|
|
544
|
+
|
|
545
|
+
/** 平台无关的路径拼接(与参考实现一致)。 */
|
|
546
|
+
export function joinPath(dir, segment) {
|
|
547
|
+
if (dir.endsWith('/') || dir.endsWith('\\')) return dir + segment;
|
|
548
|
+
const sep = dir.includes('\\') ? '\\' : '/';
|
|
549
|
+
return dir + sep + segment;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/** 绝对 POSIX/Windows 路径的父目录。 */
|
|
553
|
+
export function parentPath(path) {
|
|
554
|
+
const idx = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\'));
|
|
555
|
+
if (idx <= 0) return path;
|
|
556
|
+
const parent = path.slice(0, idx);
|
|
557
|
+
return parent.length === 0 ? path : parent;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/** 从 cwd 向上找项目根(含 .git/.hg/.svn 标记的最近祖先)。 */
|
|
561
|
+
export async function findProjectRoot(fs, cwd, signal) {
|
|
562
|
+
let current = cwd;
|
|
563
|
+
for (;;) {
|
|
564
|
+
for (const marker of ['.git', '.hg', '.svn']) {
|
|
565
|
+
try {
|
|
566
|
+
const target = await fs.resolve(joinPath(current, marker), { cwd, signal });
|
|
567
|
+
const info = await fs.stat(target, signal);
|
|
568
|
+
if (info !== void 0) return current;
|
|
569
|
+
} catch {
|
|
570
|
+
// 探测失败 = 标记不存在,继续。
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
const parent = parentPath(current);
|
|
574
|
+
if (parent === current || parent.length === 0) return cwd;
|
|
575
|
+
current = parent;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/** 列出某目录下存在的候选指令文件。 */
|
|
580
|
+
export async function presentInDir(fs, dir, candidates, signal) {
|
|
581
|
+
const found = [];
|
|
582
|
+
for (const candidate of candidates) {
|
|
583
|
+
try {
|
|
584
|
+
const target = await fs.resolve(joinPath(dir, candidate), { cwd: dir, signal });
|
|
585
|
+
const info = await fs.stat(target, signal);
|
|
586
|
+
if (info !== void 0 && info.type === 'file') found.push(candidate);
|
|
587
|
+
} catch {
|
|
588
|
+
// 不存在/不可读——跳过。
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
return found;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* 探测会话的指令文件(项目链 + $DSH_HOME/AGENTS.md)。任何失败都返回
|
|
596
|
+
* null/空集——提示注入绝不能让会话受损。
|
|
597
|
+
* @returns { projectFiles, root, userGlobalFiles } 或 null(无 fs / 无 cwd)。
|
|
598
|
+
*/
|
|
599
|
+
export async function probeInstructionFiles(fs, cwd, dshHome, signal) {
|
|
600
|
+
if (fs === null || fs === void 0 || typeof cwd !== 'string' || cwd.length === 0) return null;
|
|
601
|
+
const projectFiles = [];
|
|
602
|
+
let root = cwd;
|
|
603
|
+
try {
|
|
604
|
+
root = await findProjectRoot(fs, cwd, signal);
|
|
605
|
+
projectFiles.push(...await presentInDir(fs, root, INSTRUCTION_PROJECT_CANDIDATES, signal));
|
|
606
|
+
} catch {
|
|
607
|
+
// 项目链探测失败——忽略,仍报告用户全局文件。
|
|
608
|
+
}
|
|
609
|
+
const userGlobalFiles = [];
|
|
610
|
+
if (typeof dshHome === 'string' && dshHome.length > 0) {
|
|
611
|
+
try {
|
|
612
|
+
userGlobalFiles.push(...await presentInDir(fs, dshHome, [INSTRUCTION_USER_CANDIDATE], signal));
|
|
613
|
+
} catch {
|
|
614
|
+
// 不可读——忽略。
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
if (projectFiles.length === 0 && userGlobalFiles.length === 0) return null;
|
|
618
|
+
return { projectFiles, root, userGlobalFiles };
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// ── 按需发现工具(resident discovery set,参照 dsh-anchored-standard)─────
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* 从 agent/pre-step 的 decision.messages 剥离指定 source.kind 的消息。
|
|
625
|
+
* 保留原数组引用(未变化时)便于调用方判断。
|
|
626
|
+
*/
|
|
627
|
+
export function stripSuppressedMessages(messages, suppressedSources) {
|
|
628
|
+
if (!Array.isArray(messages) || suppressedSources.size === 0) return messages;
|
|
629
|
+
const kept = messages.filter((message) => {
|
|
630
|
+
const kind = message?.source?.kind;
|
|
631
|
+
return typeof kind !== 'string' || !suppressedSources.has(kind);
|
|
632
|
+
});
|
|
633
|
+
return kept.length === messages.length ? messages : kept;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* dev_tool_search:搜索完整可见目录并按名解锁工具(解锁结果下一请求生效,
|
|
638
|
+
* 经 syncBootstrap 重算 deny 集;解锁记录写入 a.unlocked,resume-safe 由
|
|
639
|
+
* loadUnlockedFromEvents 从持久事件恢复)。
|
|
640
|
+
*/
|
|
641
|
+
export function createDevToolSearch({ schemasOf, onUnlock, catalogHint }) {
|
|
642
|
+
const hint = catalogHint ?? [
|
|
643
|
+
'This session starts with a minimal resident set: bash, str_replace_editor.',
|
|
644
|
+
'Everything else is unlocked on demand through this tool.',
|
|
645
|
+
].join('\n');
|
|
646
|
+
return {
|
|
647
|
+
name: 'dev_tool_search',
|
|
648
|
+
description: [
|
|
649
|
+
'Discover and unlock tools that are NOT currently available.',
|
|
650
|
+
'',
|
|
651
|
+
hint,
|
|
652
|
+
'',
|
|
653
|
+
'If the current task needs internet, delegation, workflows, goals, images, background jobs, or multi-agent coordination, call dev_tool_search FIRST — do not try to work around them with bash.',
|
|
654
|
+
'',
|
|
655
|
+
'Usage: pass `query` to search the catalog (returns matching tool names + descriptions), then pass `toolNames` with exact names to unlock them. Unlocked tools appear from the next request on and stay unlocked for the session.',
|
|
656
|
+
].join('\n'),
|
|
657
|
+
parameters: {
|
|
658
|
+
type: 'object',
|
|
659
|
+
properties: {
|
|
660
|
+
query: { type: 'string', description: 'search keywords (e.g. "web", "subagent")' },
|
|
661
|
+
toolNames: { type: 'array', description: 'exact tool names to unlock', items: { type: 'string' } },
|
|
662
|
+
},
|
|
663
|
+
required: [],
|
|
664
|
+
additionalProperties: false,
|
|
665
|
+
},
|
|
666
|
+
output: {
|
|
667
|
+
schema: { type: 'object', additionalProperties: false, properties: { text: { type: 'string' } }, required: ['text'] },
|
|
668
|
+
render: (_a, value) => [{ type: 'text', text: value.text }],
|
|
669
|
+
},
|
|
670
|
+
async execute(args, exec) {
|
|
671
|
+
const query = args !== null && typeof args === 'object' && typeof args.query === 'string' ? args.query.trim() : '';
|
|
672
|
+
const unlock = args !== null && typeof args === 'object' && Array.isArray(args.toolNames)
|
|
673
|
+
? args.toolNames.filter((name) => typeof name === 'string' && name.length > 0)
|
|
674
|
+
: [];
|
|
675
|
+
const lines = [];
|
|
676
|
+
if (unlock.length > 0) {
|
|
677
|
+
let available = new Set();
|
|
678
|
+
try {
|
|
679
|
+
const schemas = typeof schemasOf === 'function' ? (schemasOf(exec) ?? []) : [];
|
|
680
|
+
for (const schema of schemas) {
|
|
681
|
+
if (schema !== null && typeof schema === 'object' && typeof schema.name === 'string') available.add(schema.name);
|
|
682
|
+
}
|
|
683
|
+
} catch {}
|
|
684
|
+
const ok = unlock.filter((name) => available.has(name));
|
|
685
|
+
if (ok.length > 0 && typeof onUnlock === 'function') {
|
|
686
|
+
try { await onUnlock(ok, exec); } catch {}
|
|
687
|
+
}
|
|
688
|
+
if (ok.length > 0) lines.push(`Unlocked for the next request: ${ok.join(', ')}`);
|
|
689
|
+
const missing = unlock.filter((name) => !available.has(name));
|
|
690
|
+
if (missing.length > 0) lines.push(`Not found in catalog: ${missing.join(', ')}`);
|
|
691
|
+
}
|
|
692
|
+
if (query.length === 0 && unlock.length === 0) {
|
|
693
|
+
lines.push('Provide `query` to search the catalog, or `toolNames` to unlock tools.');
|
|
694
|
+
return { text: lines.join('\n') };
|
|
695
|
+
}
|
|
696
|
+
if (query.length === 0) {
|
|
697
|
+
return { text: lines.join('\n') || 'Nothing to do.' };
|
|
698
|
+
}
|
|
699
|
+
try {
|
|
700
|
+
const schemas = typeof schemasOf === 'function' ? (schemasOf(exec) ?? []) : [];
|
|
701
|
+
const wanted = query.toLowerCase().split(/[^a-z0-9_]+/).filter(Boolean);
|
|
702
|
+
const matches = schemas
|
|
703
|
+
.filter((schema) => {
|
|
704
|
+
if (schema === null || typeof schema !== 'object') return false;
|
|
705
|
+
const haystack = `${schema.name || ''} ${schema.description || ''}`.toLowerCase();
|
|
706
|
+
return wanted.every((token) => haystack.includes(token));
|
|
707
|
+
})
|
|
708
|
+
.slice(0, 25);
|
|
709
|
+
if (matches.length === 0) {
|
|
710
|
+
lines.push(`No tools match "${query}".`);
|
|
711
|
+
} else {
|
|
712
|
+
lines.push(`Matching tools (${matches.length}):`);
|
|
713
|
+
for (const schema of matches) {
|
|
714
|
+
const desc = String(schema.description || '').split('\n')[0].slice(0, 90);
|
|
715
|
+
lines.push(`- ${schema.name}: ${desc}`);
|
|
716
|
+
}
|
|
717
|
+
lines.push('Unlock with dev_tool_search({"toolNames": ["<exact name>"]}).');
|
|
718
|
+
}
|
|
719
|
+
} catch (error) {
|
|
720
|
+
lines.push(`catalog search unavailable: ${String((error && error.message) || error)}`);
|
|
721
|
+
}
|
|
722
|
+
return { text: lines.join('\n') };
|
|
723
|
+
},
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* skill_search:按关键词搜索可用技能(仅摘要,替代 ~9KB 目录注入)。
|
|
729
|
+
* skillsOf 返回宿主 skills 服务(调用期解析)。
|
|
730
|
+
*/
|
|
731
|
+
export function createSkillSearch({ skillsOf }) {
|
|
732
|
+
const tokens = (text) => (text || '').toLowerCase().split(/[^a-z0-9_-]+/).filter(Boolean);
|
|
733
|
+
return {
|
|
734
|
+
name: 'skill_search',
|
|
735
|
+
description: 'Search the available skills by keyword and return matching skill names with short descriptions. This session keeps NO skill catalog in the prompt — if a task looks like it matches a skill (document conversion, image processing, game reviews, markdown, PDF, spreadsheets, …), call skill_search FIRST to find it, then skill_load to activate it. Do NOT assume skill names from memory.',
|
|
736
|
+
parameters: {
|
|
737
|
+
type: 'object',
|
|
738
|
+
properties: { query: { type: 'string', description: 'search keywords (e.g. "pdf", "obsidian", "game review")' } },
|
|
739
|
+
required: ['query'],
|
|
740
|
+
additionalProperties: false,
|
|
741
|
+
},
|
|
742
|
+
output: {
|
|
743
|
+
schema: { type: 'object', additionalProperties: false, properties: { text: { type: 'string' } }, required: ['text'] },
|
|
744
|
+
render: (_a, value) => [{ type: 'text', text: value.text }],
|
|
745
|
+
},
|
|
746
|
+
async execute(args, exec) {
|
|
747
|
+
const wanted = tokens(args?.query);
|
|
748
|
+
try {
|
|
749
|
+
const skills = skillsOf();
|
|
750
|
+
if (skills === void 0 || typeof skills.list !== 'function') {
|
|
751
|
+
return { text: 'skill_search unavailable: skills service is not mounted.' };
|
|
752
|
+
}
|
|
753
|
+
const agent = exec?.agent;
|
|
754
|
+
const lookup = {
|
|
755
|
+
scope: agent,
|
|
756
|
+
cwd: agent?.session?.header?.cwd,
|
|
757
|
+
signal: exec?.signal,
|
|
758
|
+
};
|
|
759
|
+
const all = await skills.list(lookup);
|
|
760
|
+
const matches = (Array.isArray(all) ? all : []).filter((skill) => {
|
|
761
|
+
if (wanted.length === 0) return true;
|
|
762
|
+
const haystack = tokens(`${skill?.name ?? ''} ${skill?.description ?? ''} ${skill?.whenToUse ?? ''}`).join(' ');
|
|
763
|
+
return wanted.every((token) => haystack.includes(token));
|
|
764
|
+
});
|
|
765
|
+
const head = matches.slice(0, 20);
|
|
766
|
+
const lines = head.map((skill) => {
|
|
767
|
+
const desc = String(skill?.description || '').split('\n')[0];
|
|
768
|
+
return `- ${skill?.name}: ${desc}`;
|
|
769
|
+
});
|
|
770
|
+
if (lines.length === 0) return { text: `No skills match "${args?.query}". Use skill_search with other keywords.` };
|
|
771
|
+
const extra = matches.length > 20 ? `\n…(${matches.length - 20} more)` : '';
|
|
772
|
+
return { text: `Matching skills (${matches.length}):\n${lines.join('\n')}${extra}\n\nLoad one with skill_load (exact name).` };
|
|
773
|
+
} catch (error) {
|
|
774
|
+
return { text: `skill_search unavailable: ${String((error && error.message) || error)}` };
|
|
775
|
+
}
|
|
776
|
+
},
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* skill_load:按精确名加载单个技能的完整说明,经 agent.inject 作为
|
|
782
|
+
* source.kind='skill-invocation' 的下一条上下文消息注入(用户主动技能手势
|
|
783
|
+
* 同款来源,绝不被默认抑制集剥离)。
|
|
784
|
+
*/
|
|
785
|
+
export function createSkillLoad({ skillsOf }) {
|
|
786
|
+
return {
|
|
787
|
+
name: 'skill_load',
|
|
788
|
+
description: 'Load the full instructions of ONE skill by its exact name (from skill_search results) and inject them for the next request. Call this before acting on a task that matches the skill.',
|
|
789
|
+
parameters: {
|
|
790
|
+
type: 'object',
|
|
791
|
+
properties: { name: { type: 'string', description: 'exact skill name (kebab-case, from skill_search)' } },
|
|
792
|
+
required: ['name'],
|
|
793
|
+
additionalProperties: false,
|
|
794
|
+
},
|
|
795
|
+
output: {
|
|
796
|
+
schema: { type: 'object', additionalProperties: false, properties: { text: { type: 'string' } }, required: ['text'] },
|
|
797
|
+
render: (_a, value) => [{ type: 'text', text: value.text }],
|
|
798
|
+
},
|
|
799
|
+
async execute(args, exec) {
|
|
800
|
+
try {
|
|
801
|
+
const agent = exec?.agent;
|
|
802
|
+
if (agent === void 0) return { text: 'skill_load requires an agent context.' };
|
|
803
|
+
const skills = skillsOf();
|
|
804
|
+
if (skills === void 0 || typeof skills.get !== 'function') {
|
|
805
|
+
return { text: 'skill_load unavailable: skills service is not mounted.' };
|
|
806
|
+
}
|
|
807
|
+
const name = typeof args?.name === 'string' ? args.name.trim() : '';
|
|
808
|
+
if (name.length === 0) return { text: 'skill_load requires a skill name.' };
|
|
809
|
+
const skill = await skills.get(name, {
|
|
810
|
+
scope: agent,
|
|
811
|
+
cwd: agent.session?.header?.cwd,
|
|
812
|
+
signal: exec?.signal,
|
|
813
|
+
});
|
|
814
|
+
if (skill === void 0) {
|
|
815
|
+
return { text: `No skill named "${name}". Run skill_search to list available skills.` };
|
|
816
|
+
}
|
|
817
|
+
const body = extractSkillBody(skill);
|
|
818
|
+
if (body.length === 0) {
|
|
819
|
+
return { text: `Skill "${name}" has no loadable body.` };
|
|
820
|
+
}
|
|
821
|
+
if (typeof agent.inject !== 'function') {
|
|
822
|
+
return { text: `Skill "${name}" found, but injection is unavailable in this agent.` };
|
|
823
|
+
}
|
|
824
|
+
agent.inject({
|
|
825
|
+
id: `skill-load-${name}-${Date.now()}`,
|
|
826
|
+
role: 'user',
|
|
827
|
+
content: [{ type: 'text', text: body }],
|
|
828
|
+
source: { kind: 'skill-invocation', name, form: 'instructions' },
|
|
829
|
+
});
|
|
830
|
+
return { text: `Skill "${name}" loaded; its instructions will be injected for the next request.` };
|
|
831
|
+
} catch (error) {
|
|
832
|
+
return { text: `skill_load failed: ${String((error && error.message) || error)}` };
|
|
833
|
+
}
|
|
834
|
+
},
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/** 提取已加载技能定义的模型可见正文(与参考实现一致)。 */
|
|
839
|
+
export function extractSkillBody(skill) {
|
|
840
|
+
const content = skill?.content ?? skill?.instructions ?? skill?.body;
|
|
841
|
+
if (typeof content === 'string') return content;
|
|
842
|
+
if (Array.isArray(content)) {
|
|
843
|
+
return content.map((part) => (typeof part === 'string' ? part : JSON.stringify(part))).join('\n');
|
|
844
|
+
}
|
|
845
|
+
return '';
|
|
846
|
+
}
|
|
847
|
+
|
|
374
848
|
// ── bootstrap 锚定(参照 dsh-anchored-standard 的实测结论)──────────────
|
|
375
849
|
|
|
376
850
|
/** promoteOn 配置 → 晋升的持久事件类型集合。 */
|
|
@@ -456,7 +930,35 @@ export function applyBootstrapBudget(config, promoted, maxTokens) {
|
|
|
456
930
|
|
|
457
931
|
// ── host 插件 ────────────────────────────────────────────────────────────
|
|
458
932
|
|
|
459
|
-
|
|
933
|
+
/** 把配置 namespace 注册进宿主 settings 体系(dsh-settings 0.1.0-rc.7+)。
|
|
934
|
+
* 设置页 describe() 只枚举 settings.register 注册过的 namespace;本插件
|
|
935
|
+
* 的卡片读写不经过宿主 settings 文档,注册只为让卡片出现在设置页。
|
|
936
|
+
* options.base 必传当前生效配置快照:宿主 resolve = schema(mergeLayers(base,
|
|
937
|
+
* section)),schema 无默认值时 base 缺失会让 describe() 的 value 为
|
|
938
|
+
* undefined,而设置页 wire 校验要求 value 非空(invalid_type: nonoptional),
|
|
939
|
+
* 一项失败会拖垮整个设置页。本插件的 any() schema 完全依赖 base。
|
|
940
|
+
* fail-safe(schema 库/服务缺失静默跳过)+ 幂等(重复注册忽略)。
|
|
941
|
+
* 导出以便测试注入 Schema stub。 */
|
|
942
|
+
export function registerSettingsNamespace(ctx, ns, schemaLib, buildSchema, options) {
|
|
943
|
+
if (schemaLib === null || schemaLib === undefined) return false;
|
|
944
|
+
if (ctx === null || typeof ctx !== 'object' || typeof ctx.inject !== 'function') return false;
|
|
945
|
+
try {
|
|
946
|
+
ctx.inject(['settings'], (settingsCtx) => {
|
|
947
|
+
try {
|
|
948
|
+
settingsCtx.settings.register(ns, buildSchema(schemaLib), options);
|
|
949
|
+
} catch (error) {
|
|
950
|
+
const message = String(error && error.message || error);
|
|
951
|
+
if (!message.includes('already registered')) throw error;
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
return true;
|
|
955
|
+
} catch (error) {
|
|
956
|
+
try { ctx.logger?.warn?.(`adaptive-perf: settings namespace registration skipped: ${error && error.message || error}`); } catch {}
|
|
957
|
+
return false;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
export async function apply(ctx, config, options = {}) {
|
|
460
962
|
// fail-safe:初始化失败只记录,绝不让本插件拖垮 harness(host 层挂载时
|
|
461
963
|
// entry 异常会导致进程启动失败)。
|
|
462
964
|
try {
|
|
@@ -477,6 +979,41 @@ export function apply(ctx, config) {
|
|
|
477
979
|
/** 当前生效配置(热更新;后续 store 创建后以 config.json 权威合并结果覆盖)。 */
|
|
478
980
|
let cfg = normalizeConfig(patchConfig);
|
|
479
981
|
|
|
982
|
+
/** 真实 Minimal 工具对模块(0.5.0)。加载失败 = null = 降级旧行为。
|
|
983
|
+
* options.realPairModules 仅供测试注入。 */
|
|
984
|
+
const realPairModules = options.realPairModules === void 0
|
|
985
|
+
? (cfg.bootstrap.enabled && cfg.bootstrap.realPair ? await loadRealPairModules() : null)
|
|
986
|
+
: options.realPairModules;
|
|
987
|
+
/** 是否已尝试加载过真实工具对模块(避免配置热更新时反复重试)。 */
|
|
988
|
+
let realPairModulesTried = options.realPairModules !== void 0 || (cfg.bootstrap.enabled && cfg.bootstrap.realPair);
|
|
989
|
+
if (cfg.bootstrap.enabled && cfg.bootstrap.realPair && realPairModules === null) {
|
|
990
|
+
try {
|
|
991
|
+
ctx.logger?.warn?.('adaptive-perf: real Minimal tool pair modules unavailable (optional @deepseek-ai deps missing?); falling back to catalog-only bootstrap');
|
|
992
|
+
} catch {}
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
/** 已注入过 instruction-hint 的会话(内存去重,与参考实现一致)。 */
|
|
996
|
+
const hintedSessions = new Set();
|
|
997
|
+
|
|
998
|
+
/**
|
|
999
|
+
* 配置热更新把 realPair 从关闭切到开启时补加载官方模块(初始未启用时
|
|
1000
|
+
* 不加载)。加载成功后对已接管会话补挂。
|
|
1001
|
+
*/
|
|
1002
|
+
function ensureRealPairModules() {
|
|
1003
|
+
if (realPairModulesTried || cfg.bootstrap.enabled === false || cfg.bootstrap.realPair === false) return;
|
|
1004
|
+
realPairModulesTried = true;
|
|
1005
|
+
loadRealPairModules().then((mods) => {
|
|
1006
|
+
if (mods === null) return;
|
|
1007
|
+
realPairModules = mods;
|
|
1008
|
+
info('real Minimal tool pair modules loaded; mounting for live agents');
|
|
1009
|
+
for (const a of agents.values()) {
|
|
1010
|
+
syncRealPair(a);
|
|
1011
|
+
applyMinimalPrompt(a);
|
|
1012
|
+
syncBootstrap(a);
|
|
1013
|
+
}
|
|
1014
|
+
}).catch(() => {});
|
|
1015
|
+
}
|
|
1016
|
+
|
|
480
1017
|
/** agentId -> 会话自适应状态。 */
|
|
481
1018
|
const agents = new Map();
|
|
482
1019
|
|
|
@@ -517,7 +1054,8 @@ export function apply(ctx, config) {
|
|
|
517
1054
|
}
|
|
518
1055
|
}
|
|
519
1056
|
|
|
520
|
-
/** 应用/更新极简提示词层(persona 阴影 +
|
|
1057
|
+
/** 应用/更新极简提示词层(persona 阴影 + 全局引导段屏蔽 +
|
|
1058
|
+
* 真实工具对替换后的 tool 引导段阴影)。 */
|
|
521
1059
|
function applyMinimalPrompt(a) {
|
|
522
1060
|
for (const disposer of a.promptDisposers) {
|
|
523
1061
|
try { disposer(); } catch {}
|
|
@@ -531,6 +1069,11 @@ export function apply(ctx, config) {
|
|
|
531
1069
|
a.promptDisposers.push(sp.section({ name, order, text: '' }));
|
|
532
1070
|
}
|
|
533
1071
|
}
|
|
1072
|
+
if (a.realPairActive) {
|
|
1073
|
+
for (const [name, order] of TOOL_GUIDANCE_SHADOWS) {
|
|
1074
|
+
a.promptDisposers.push(sp.section({ name, order, text: '' }));
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
534
1077
|
const persona = cfg.minimalPrompt.persona.trim();
|
|
535
1078
|
if (persona.length > 0) {
|
|
536
1079
|
a.promptDisposers.push(sp.section({ name: PERSONA_SECTION_NAME, order: PERSONA_SECTION_ORDER, text: persona }));
|
|
@@ -595,6 +1138,111 @@ export function apply(ctx, config) {
|
|
|
595
1138
|
info(`agent ${a.agent.id}: escalated family "${familyId}" (${trigger})`);
|
|
596
1139
|
}
|
|
597
1140
|
|
|
1141
|
+
/** 从持久事件恢复 dev_tool_search 已解锁的工具(resume-safe)。 */
|
|
1142
|
+
function loadUnlockedFromEvents(a) {
|
|
1143
|
+
const events = a.agent.session && Array.isArray(a.agent.session.events) ? a.agent.session.events : [];
|
|
1144
|
+
for (const event of events) {
|
|
1145
|
+
if (event === null || typeof event !== 'object' || event.type !== 'tool/call') continue;
|
|
1146
|
+
if (event.data === null || typeof event.data !== 'object' || event.data.name !== 'dev_tool_search') continue;
|
|
1147
|
+
let args = event.data.arguments;
|
|
1148
|
+
if (typeof args === 'string') {
|
|
1149
|
+
try { args = JSON.parse(args); } catch { continue; }
|
|
1150
|
+
}
|
|
1151
|
+
if (args === null || typeof args !== 'object' || Array.isArray(args)) continue;
|
|
1152
|
+
if (Array.isArray(args.toolNames)) {
|
|
1153
|
+
for (const name of args.toolNames) {
|
|
1154
|
+
if (typeof name === 'string' && name.length > 0) a.unlocked.add(name);
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
/**
|
|
1161
|
+
* 挂载/卸载真实 Minimal 工具对(0.5.0):把官方 minimal preset 同款插件
|
|
1162
|
+
* (持久 PTY bash + str_replace_editor 及其依赖的 terminals/本地 fs)
|
|
1163
|
+
* 挂进 agent 作用域。scoped registration 按名阴影 standard 的 sandboxed
|
|
1164
|
+
* bash,且自身层注册不受 restrict 影响(view() 对 own layer 豁免)——
|
|
1165
|
+
* 首轮目录因此是"真实工具对 + 被 deny 的其他继承工具"。
|
|
1166
|
+
* 依赖模块缺失(realPairModules === null)或 Windows(PTY 仅 linux/darwin)
|
|
1167
|
+
* 时静默降级:不挂载,退回旧行为(仅收窄目录)。
|
|
1168
|
+
*/
|
|
1169
|
+
function syncRealPair(a) {
|
|
1170
|
+
for (const dispose of a.realPairDisposers) {
|
|
1171
|
+
try { dispose(); } catch {}
|
|
1172
|
+
}
|
|
1173
|
+
a.realPairDisposers = [];
|
|
1174
|
+
const active = cfg.enabled && cfg.bootstrap.enabled && cfg.bootstrap.realPair
|
|
1175
|
+
&& realPairModules !== null && process.platform !== 'win32';
|
|
1176
|
+
if (active) {
|
|
1177
|
+
const mounts = realPairMounts(realPairModules, a.agent.session?.header?.cwd);
|
|
1178
|
+
a.realPairDisposers = mountRealPair(a.agent, mounts, warn);
|
|
1179
|
+
if (a.realPairDisposers.length > 0) {
|
|
1180
|
+
info(`agent ${a.agent.id}: real Minimal tool pair mounted (${mounts.length} plugins)`);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
a.realPairActive = a.realPairDisposers.length > 0;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
/**
|
|
1187
|
+
* 给目标 agent 注册 on-demand 发现工具(dsh-anchored-standard 的 resident
|
|
1188
|
+
* discovery pattern):晋升后常驻 bootstrap.discoveryTools 列出的工具——
|
|
1189
|
+
* dev_tool_search(搜索完整目录并按名解锁,解锁结果下一请求生效,写入
|
|
1190
|
+
* a.unlocked 后 syncBootstrap 重算 deny 集)+ skill_search / skill_load
|
|
1191
|
+
* (常驻上下文抑制的替代品:按需发现/加载技能)。
|
|
1192
|
+
* 已存在的同名工具(preset 自带)不重复注册。
|
|
1193
|
+
*/
|
|
1194
|
+
function syncDiscoveryTools(a, enabled) {
|
|
1195
|
+
const want = enabled ? cfg.bootstrap.discoveryTools : [];
|
|
1196
|
+
for (const [name, disposer] of a.toolDisposers) {
|
|
1197
|
+
if (!want.includes(name)) {
|
|
1198
|
+
try { disposer(); } catch {}
|
|
1199
|
+
a.toolDisposers.delete(name);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
if (!enabled) return;
|
|
1203
|
+
const scopedTools = a.agent.ctx && a.agent.ctx.tools;
|
|
1204
|
+
if (scopedTools === void 0 || typeof scopedTools.register !== 'function') return;
|
|
1205
|
+
for (const name of want) {
|
|
1206
|
+
if (a.toolDisposers.has(name)) continue;
|
|
1207
|
+
if (a.visibleNames.has(name)) continue; // preset/宿主已提供同名工具
|
|
1208
|
+
const def = discoveryToolDef(a, name);
|
|
1209
|
+
if (def === null) continue;
|
|
1210
|
+
try {
|
|
1211
|
+
const disposer = scopedTools.register(def);
|
|
1212
|
+
if (typeof disposer === 'function') a.toolDisposers.set(name, disposer);
|
|
1213
|
+
} catch (error) {
|
|
1214
|
+
warn(`register ${name} failed for agent ${a.agent.id}: ${error && error.message || error}`);
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
/** 构造一个发现工具定义;未知名称返回 null。 */
|
|
1220
|
+
function discoveryToolDef(a, name) {
|
|
1221
|
+
if (name === 'dev_tool_search') {
|
|
1222
|
+
return createDevToolSearch({
|
|
1223
|
+
schemasOf: (exec) => {
|
|
1224
|
+
const agent = exec !== null && typeof exec === 'object' ? exec.agent : void 0;
|
|
1225
|
+
return agent === void 0 ? [] : tools.schemas(agent);
|
|
1226
|
+
},
|
|
1227
|
+
onUnlock: async (names, exec) => {
|
|
1228
|
+
const agent = exec !== null && typeof exec === 'object' ? exec.agent : void 0;
|
|
1229
|
+
const state = agent === void 0 ? void 0 : agents.get(agent.id);
|
|
1230
|
+
if (state === void 0) return;
|
|
1231
|
+
for (const name of names) state.unlocked.add(name);
|
|
1232
|
+
syncBootstrap(state);
|
|
1233
|
+
},
|
|
1234
|
+
catalogHint: 'This session starts with a minimal resident set: bash, str_replace_editor, skill_search, skill_load. Everything else is unlocked on demand through this tool.',
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
if (name === 'skill_search' && cfg.skillDiscovery) {
|
|
1238
|
+
return createSkillSearch({ skillsOf: () => ctx.get('skills') });
|
|
1239
|
+
}
|
|
1240
|
+
if (name === 'skill_load' && cfg.skillDiscovery) {
|
|
1241
|
+
return createSkillLoad({ skillsOf: () => ctx.get('skills') });
|
|
1242
|
+
}
|
|
1243
|
+
return null;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
598
1246
|
/** 完整接管一个 agent(幂等)。 */
|
|
599
1247
|
function handleAgent(agent) {
|
|
600
1248
|
if (agents.has(agent.id)) return;
|
|
@@ -608,6 +1256,10 @@ export function apply(ctx, config) {
|
|
|
608
1256
|
bootstrapKey: null,
|
|
609
1257
|
escalated: new Set(),
|
|
610
1258
|
visibleNames: new Set(),
|
|
1259
|
+
unlocked: new Set(),
|
|
1260
|
+
toolDisposers: new Map(),
|
|
1261
|
+
realPairDisposers: [],
|
|
1262
|
+
realPairActive: false,
|
|
611
1263
|
};
|
|
612
1264
|
// 记录当前可见目录(限制前);仅记录真实存在的工具,后续 restrict 与
|
|
613
1265
|
// 实际目录取交集,preset 升级改名/删除工具不会让本插件崩溃。
|
|
@@ -620,8 +1272,10 @@ export function apply(ctx, config) {
|
|
|
620
1272
|
} catch (error) {
|
|
621
1273
|
warn(`schemas lookup failed for agent ${agent.id}: ${error && error.message || error}`);
|
|
622
1274
|
}
|
|
1275
|
+
loadUnlockedFromEvents(a);
|
|
623
1276
|
agents.set(agent.id, a);
|
|
624
1277
|
applySuppression(a);
|
|
1278
|
+
syncRealPair(a);
|
|
625
1279
|
applyMinimalPrompt(a);
|
|
626
1280
|
applyFamilies(a);
|
|
627
1281
|
syncBootstrap(a);
|
|
@@ -641,6 +1295,14 @@ export function apply(ctx, config) {
|
|
|
641
1295
|
try { disposer(); } catch {}
|
|
642
1296
|
}
|
|
643
1297
|
a.promptDisposers = [];
|
|
1298
|
+
for (const disposer of a.toolDisposers.values()) {
|
|
1299
|
+
try { disposer(); } catch {}
|
|
1300
|
+
}
|
|
1301
|
+
a.toolDisposers.clear();
|
|
1302
|
+
for (const dispose of a.realPairDisposers) {
|
|
1303
|
+
try { dispose(); } catch {}
|
|
1304
|
+
}
|
|
1305
|
+
a.realPairDisposers = [];
|
|
644
1306
|
if (a.bootstrapDisposer !== null) {
|
|
645
1307
|
try { a.bootstrapDisposer(); } catch {}
|
|
646
1308
|
}
|
|
@@ -731,8 +1393,12 @@ export function apply(ctx, config) {
|
|
|
731
1393
|
}
|
|
732
1394
|
|
|
733
1395
|
/**
|
|
734
|
-
* bootstrap 阶段的保留工具集:
|
|
735
|
-
*
|
|
1396
|
+
* bootstrap 阶段的保留工具集:
|
|
1397
|
+
* - 未晋升:bootstrap 工具对 + PTC 的直接调用工具(run_code)+
|
|
1398
|
+
* compaction 后恢复期的工作集;
|
|
1399
|
+
* - 已晋升:bootstrap 工具对 + resident discovery 工具 +
|
|
1400
|
+
* dev_tool_search 已解锁工具 + 已升级工具族(dsh-anchored-standard 的
|
|
1401
|
+
* resident catalog,避免晋升后一次性 dump 完整 Standard 目录)。
|
|
736
1402
|
*
|
|
737
1403
|
* 注意:不能靠过滤 system-prompt/assemble 的 assembly.tools 来实现——
|
|
738
1404
|
* PTC 模式下 assembly.tools 只有 [run_code],Minimal 工具对不在其中,
|
|
@@ -741,17 +1407,32 @@ export function apply(ctx, config) {
|
|
|
741
1407
|
* SDK 参考段,且天然保留 run_code(不在 deny 里)。
|
|
742
1408
|
*/
|
|
743
1409
|
function bootstrapKeepSet(a) {
|
|
1410
|
+
if (!cfg.enabled || !cfg.bootstrap.enabled) return null;
|
|
1411
|
+
const session = a.agent.session;
|
|
1412
|
+
if (session === void 0) return null; // 无会话信息时保持既有行为(测试/未知场景)
|
|
744
1413
|
const phase = bootstrapPhaseOf(a.agent);
|
|
745
|
-
if (phase.promoted) return null;
|
|
746
1414
|
const keep = new Set(cfg.bootstrap.tools);
|
|
747
1415
|
if (a.visibleNames.has('run_code')) keep.add('run_code');
|
|
1416
|
+
if (phase.promoted) {
|
|
1417
|
+
for (const name of cfg.bootstrap.discoveryTools) keep.add(name);
|
|
1418
|
+
for (const name of a.unlocked) keep.add(name);
|
|
1419
|
+
for (const [id, family] of Object.entries(cfg.families)) {
|
|
1420
|
+
if (a.escalated.has(id)) {
|
|
1421
|
+
for (const name of familyDeny(a, family)) keep.add(name);
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
return keep;
|
|
1425
|
+
}
|
|
748
1426
|
if (phase.boundary >= 0) for (const name of cfg.bootstrap.compactionTools) keep.add(name);
|
|
749
1427
|
return keep;
|
|
750
1428
|
}
|
|
751
1429
|
|
|
752
1430
|
/** 按当前阶段同步 bootstrap 的临时 restrict(幂等;仅阶段/配置变化时重挂)。 */
|
|
753
1431
|
function syncBootstrap(a) {
|
|
1432
|
+
const phase = bootstrapPhaseOf(a.agent);
|
|
754
1433
|
const keep = bootstrapKeepSet(a);
|
|
1434
|
+
// discovery 工具只在晋升后的 resident 阶段注册;bootstrap/compaction 阶段隐藏。
|
|
1435
|
+
syncDiscoveryTools(a, keep !== null && phase.promoted);
|
|
755
1436
|
const key = keep === null ? null : [...keep].sort().join(',');
|
|
756
1437
|
if (key === a.bootstrapKey) return;
|
|
757
1438
|
if (a.bootstrapDisposer !== null) {
|
|
@@ -785,18 +1466,59 @@ export function apply(ctx, config) {
|
|
|
785
1466
|
}
|
|
786
1467
|
});
|
|
787
1468
|
|
|
788
|
-
//
|
|
789
|
-
//
|
|
790
|
-
|
|
1469
|
+
// 上下文剥离 + instruction-hint。prepend + 根作用域注册保证是最后一道
|
|
1470
|
+
// 变换(后注册的注入者无法再补回)。两个职责同在一个监听器里,顺序天然
|
|
1471
|
+
// 正确:先剥离被抑制来源,再(晋升后一次性)追加指令文件提示。
|
|
1472
|
+
// 剥离与 bootstrap 开关正交:常驻抑制(suppressInjectedContext)在
|
|
1473
|
+
// bootstrap 关闭时也生效;instruction-hint 依赖晋升阶段(bootstrap 机制)。
|
|
1474
|
+
ctx.on('agent/pre-step', async ({ agent, signal }, next) => {
|
|
791
1475
|
const decision = await next();
|
|
792
1476
|
if (decision === null || typeof decision !== 'object' || decision.kind === 'reject') return decision;
|
|
793
1477
|
try {
|
|
794
|
-
if (!
|
|
1478
|
+
if (!cfg.enabled || !isTarget(agent)) return decision;
|
|
795
1479
|
const phase = bootstrapPhaseOf(agent);
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
1480
|
+
const suppressed = new Set(cfg.bootstrap.suppressedContextSources);
|
|
1481
|
+
let out = decision;
|
|
1482
|
+
// 剥离条件:bootstrap 未晋升(旧行为)或常驻抑制开启(0.5.0 默认:
|
|
1483
|
+
// 整个会话不再注入技能目录与 AGENTS.md 摘要,替代品是按需发现工具)。
|
|
1484
|
+
const stripActive = (cfg.bootstrap.enabled && !phase.promoted) || cfg.suppressInjectedContext;
|
|
1485
|
+
if (suppressed.size > 0 && stripActive && Array.isArray(out.messages)) {
|
|
1486
|
+
const kept = stripSuppressedMessages(out.messages, suppressed);
|
|
1487
|
+
out = kept === out.messages ? out : { ...out, messages: kept };
|
|
1488
|
+
}
|
|
1489
|
+
// instruction-hint:晋升后一次性注入"指令文件存在,需要时自读"。
|
|
1490
|
+
if (cfg.bootstrap.enabled && cfg.instructionHint && phase.promoted && Array.isArray(out.messages)) {
|
|
1491
|
+
const session = agent.session;
|
|
1492
|
+
if (session !== null && typeof session === 'object' && typeof session.id === 'string' && !hintedSessions.has(session.id)) {
|
|
1493
|
+
hintedSessions.add(session.id);
|
|
1494
|
+
const fs = ctx.get('fs');
|
|
1495
|
+
const dshHome = process.env.DSH_HOME?.trim() || `${process.env.HOME || process.env.USERPROFILE || ''}/.dsh`;
|
|
1496
|
+
const probe = await probeInstructionFiles(fs, session.header?.cwd, dshHome, signal);
|
|
1497
|
+
if (probe !== null) {
|
|
1498
|
+
const sections = [];
|
|
1499
|
+
if (probe.projectFiles.length > 0) {
|
|
1500
|
+
sections.push(`Workspace instruction files exist: ${probe.projectFiles.join(', ')} (project root: ${probe.root}).`);
|
|
1501
|
+
}
|
|
1502
|
+
if (probe.userGlobalFiles.length > 0) {
|
|
1503
|
+
sections.push(`A user-global instruction file exists: ${INSTRUCTION_USER_CANDIDATE}.`);
|
|
1504
|
+
}
|
|
1505
|
+
const text = [
|
|
1506
|
+
...sections,
|
|
1507
|
+
'Do NOT assume their content. When a task touches this workspace, read the relevant instruction files first and follow them.',
|
|
1508
|
+
].join(' ');
|
|
1509
|
+
out = {
|
|
1510
|
+
...out,
|
|
1511
|
+
messages: [...out.messages, {
|
|
1512
|
+
id: `instruction-hint-${session.id}`,
|
|
1513
|
+
role: 'user',
|
|
1514
|
+
content: [{ type: 'text', text }],
|
|
1515
|
+
source: { kind: 'instruction-hint', form: 'hint' },
|
|
1516
|
+
}],
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
return out;
|
|
800
1522
|
} catch (error) {
|
|
801
1523
|
// 过滤失败绝不吞掉用户的上下文:原样放行。
|
|
802
1524
|
warnBootstrapOnce(`bootstrap context filter failed, keeping injected context: ${String((error && error.message) || error)}`);
|
|
@@ -839,6 +1561,8 @@ export function apply(ctx, config) {
|
|
|
839
1561
|
onUpdate: (merged) => {
|
|
840
1562
|
cfg = normalizeConfig({ ...patchConfig, ...merged });
|
|
841
1563
|
info('config hot-updated; recomputing restrictions for live agents');
|
|
1564
|
+
// realPair 从关闭切到开启:补加载官方模块(首次尝试失败不反复重试)。
|
|
1565
|
+
ensureRealPairModules();
|
|
842
1566
|
// 补挂此前创建的会话(例如插件从 disabled 切换为 enabled,或新增了
|
|
843
1567
|
// 目标 preset):新符合条件的 agent 立即接管(handleAgent 已应用全部
|
|
844
1568
|
// 层,下面的重算只针对此前已接管的 agent,避免同一 onUpdate 内重复)。
|
|
@@ -854,6 +1578,7 @@ export function apply(ctx, config) {
|
|
|
854
1578
|
const a = agents.get(agentId);
|
|
855
1579
|
if (a === void 0) continue;
|
|
856
1580
|
applySuppression(a);
|
|
1581
|
+
syncRealPair(a);
|
|
857
1582
|
applyMinimalPrompt(a);
|
|
858
1583
|
applyFamilies(a);
|
|
859
1584
|
syncBootstrap(a);
|
|
@@ -867,6 +1592,15 @@ export function apply(ctx, config) {
|
|
|
867
1592
|
ctx.plugin(PluginConfigGateway, { store, serviceKey: 'adaptivePerfConfig' });
|
|
868
1593
|
}
|
|
869
1594
|
|
|
1595
|
+
// 注册进宿主 settings 体系(可见性):设置页用 settings.describe() 枚举
|
|
1596
|
+
// registrations,未注册的 namespace 即使卡片带正确的 key 也不渲染。
|
|
1597
|
+
// 卡片的实际读写仍走上面的 config gateway(config.json 权威、热更新)。
|
|
1598
|
+
// 配置为多层嵌套结构(families/bootstrap/minimalPrompt…),schema 用 any
|
|
1599
|
+
// 透传——describe 元数据只服务于可见性,卡片不读取它。any() 无默认值,
|
|
1600
|
+
// 必须传 base(当前生效配置快照),否则 describe() 的 value 为 undefined,
|
|
1601
|
+
// 设置页 wire 校验(nonoptional)会整体失败。
|
|
1602
|
+
registerSettingsNamespace(ctx, 'adaptivePerfConfig', Schema, (z) => z.any(), { base: cfg });
|
|
1603
|
+
|
|
870
1604
|
// 卸载清理:释放全部会话副作用与监听。
|
|
871
1605
|
ctx.effect(() => () => {
|
|
872
1606
|
for (const agentId of [...agents.keys()]) releaseAgent(agentId);
|