dsh-subagent-default-model 2.2.2 → 2.2.6

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 CHANGED
@@ -1,5 +1,311 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.2.6 (2026-11-19)
4
+
5
+ ### Fixed
6
+
7
+ **故障转移的触发码集补上两个真实会发生的失败:`STREAM_CLOSED` 与 `ACCOUNT_QUOTA`。**
8
+
9
+ 这张清单是 2026-08 写 failover v1.0.0 时照着**当时**宿主会抛的码定的,之后宿主陆续加码,而**没有任何测试比对过两张表**。到 0.2.2-rc.5 为止,缺的两个恰好都是本功能存在的理由:
10
+
11
+ | 码 | 宿主在哪里抛 | 为什么该切换 |
12
+ | --- | --- | --- |
13
+ | `STREAM_CLOSED` | `dsh-llm-deepseek:2096`「stream ended before message_stop」、`dsh-llm-pi-ai:1688`「event stream ended without done/error」 | 流在响应中途断掉,是「这家坏了、换一家就好」的典型场景。此前插件把它原样放行,子代理直接以错误结束 |
14
+ | `ACCOUNT_QUOTA` | `dsh-llm-deepseek-account:87` —— 把账号余额耗尽的 `QUOTA` **改写**成这个码 | 与 `QUOTA`(清单里一直有)是同一件事,只是把「账号额度」与「单 key 额度」分开表达。结果唯一一个明说「这个账号没钱了」的码,恰恰是唯一不触发切换的码 |
15
+
16
+ 判据:**码集要对「宿主真的会抛什么」负责,不是对「当年常量表里写了什么」负责。**
17
+
18
+ 仍然**故意不切换**的码(理由已逐条写进测试文件):`CONTENT_REFUSED`(内容被拒,换一家也一样被拒)、`CONTEXT_WINDOW_EXCEEDED` / `IMAGE_OFFLOAD_REQUIRED` / `INVALID_REQUEST`(请求本身有问题)、`UNKNOWN_MODEL` / `MODEL_UNSUPPORTED`(切换会掩盖配置里的笔误)、`MALFORMED_RESPONSE`(可能是供应商坏了,也可能是适配器的恒定 bug,插件分不出来,赌错会烧光整池)。
19
+
20
+ ### Added
21
+
22
+ **护栏:码集与宿主词表的自动对齐(此前完全裸奔)。**
23
+
24
+ 新增 `plugin/test/failover-codes.test.mjs`,两层:
25
+
26
+ 1. **词表层(静态)** —— 从运行中的 `app.asar` 里解析宿主自己的 `LLM_FAILURE_CODES` 表,要求每个码要么在切换集里、要么在 `DELIBERATELY_ABSENT` 里写明理由。宿主下次加码时,**这条用例会红**,而不是等到几个月后有人手工发现。
27
+ 2. **行为层(动态)** —— 对每个码真实驱动插件自己的 `agent/request-error` 监听器,断言到底切不切。观察点是 `agent.model.select()` 是否被调用:在 0.2.2 上切换走这条路,瀑布的返回值**两种情况都是 `undefined`**,只看返回值等于什么都没断言。
28
+
29
+ 另有两条针对性回归:`STREAM_CLOSED` / `ACCOUNT_QUOTA` 必须切换;且必须走**连接类**路径而不是认证类(否则每次都要打一条误导性的「凭据被拒」warn)。
30
+
31
+ `FAILOVER_ELIGIBLE_CODES` 与 `FAILOVER_TRIGGER_CODE_SET` 改为导出常量(与 `volatileField` / `Config` 同类的测试接缝):测试直接读模块,**不再手抄一份清单**——抄一份的话,清单改了它照样绿,护栏就成了装饰。
32
+
33
+ ### Tests
34
+
35
+ `198 → 206`,`skip 0`。新增 8 条:
36
+
37
+ - 宿主词表可读(并校验解析结果的规模,防止解析退化成两三条让后续断言全部空转);
38
+ - 每个宿主码要么切换、要么有文档;
39
+ - 「故意不切」与「切换集」互斥;
40
+ - 「故意不切」里的码必须仍存在于宿主词表(防止过期决策变成噪音);
41
+ - 行为:切换集里的每个码真的会切;
42
+ - 行为:文档记为不切的每个码真的不切;
43
+ - 回归:`STREAM_CLOSED` / `ACCOUNT_QUOTA` 会切;
44
+ - 回归:两者走连接类路径,不打凭据 warn。
45
+
46
+ **变异验证 3/3 命中**:删 `STREAM_CLOSED` → 2 条红;删 `ACCOUNT_QUOTA` → 2 条红;把 `CONTENT_REFUSED` 误加进切换集 → 2 条红(互斥检查 + 行为检查)。
47
+
48
+ ### Changed
49
+
50
+ - 双语文档(根 `README` 与 `plugin/README` 各两份)的连接类触发码清单同步补上这两个码。
51
+
52
+
53
+ ## 2.2.5 (2026-11-19)
54
+
55
+ ### 兼容性核查:DSH Desktop 0.2.2-rc.3 → rc.4 → rc.5
56
+
57
+ 宿主由 `0.2.2-rc.2` 一路升到 **`0.2.2-rc.5`**(2026-11-18 安装)。**插件运行逻辑零改动**(`plugin/lib/index.js` / `plugin/lib/client.js` 未动一行)——本版只做核查与清单维护。
58
+
59
+ 两个区间分开记:rc.2 → rc.3 见下节(2.2.5 起草时核查过),rc.3 → rc.5 见本节。
60
+
61
+ #### rc.3 → rc.5:只有 10 个包有真实代码改动,全部在插件未触碰的面
62
+
63
+ | 包 | 改动 | 与本插件的关系 |
64
+ | --- | --- | --- |
65
+ | `dsh-web` / `dsh-tool-web` | 搜索提供方改为**按模型路由自动选择**:DeepSeek 模型走旧版 Messages 搜索(不按次收费),其余路由走 DeepSeek Search API;`WebSearchRequest` 新增 `llmProvider` | 与本插件无关(不碰 `ctx.web`) |
66
+ | `dsh-web-search-deepseek` / `dsh-web-deepseek-api` | 跟随上述改造 | 与本插件无关 |
67
+ | `dsh-client-ui-settings-web-search` | 「网页搜索提供方」菜单新增**自动选择** | 与本插件无关 |
68
+ | `dsh-bundle-base` | 组合不再固定 `web.searchProvider` | 与本插件无关 |
69
+ | `dsh-llm` | **新增失败码 `CONTENT_REFUSED`**(内容安全拒答,取代原来的 `MALFORMED_RESPONSE`) | 见下方「需要决定的一项」 |
70
+ | `dsh-llm-deepseek` | 拒答时先 `yield usage` 再抛错(已消耗的 token 照常计费);`stop_reason: "refusal"` 映射到 `CONTENT_REFUSED` | 同上 |
71
+ | `dsh-experimental-liveshare` | 隧道 worker 的 owner 凭据时限 | 与本插件无关 |
72
+ | `dsh-tool-cordis` | 内嵌的 `SERVICE_API` 目录:`ctx.web` 的搜索选择规则补上按路由分支,`WebSearchRequest` 增加 `llmProvider` | 纯文档字符串 |
73
+
74
+ **插件依赖的 8 个包在 rc.3 → rc.5 全程零改动**:`dsh-agent-loop`、`dsh-agent`、`dsh-session`、`dsh-subagent`、`dsh-tool-subagent`、`dsh-settings`、`dsh-app-boot`、`cordis`(逐文件比对,只有 `package.json` 版本号)。
75
+
76
+ #### 契约复核(`0.2.2-rc.5` 实测,与 rc.3 逐位相同)
77
+
78
+ | 检查项 | 结论 |
79
+ | --- | --- |
80
+ | 插件加载与注入 | ✅ 已挂载(`include:dsh-subagent-default-model`),`Config` 投影出全部 10 个 volatile 字段(`provider` / `model` / `models` / `strategy` / `failoverEnabled` / `injectRouteContext` / `reasoningEffort` / `applyToForkChildren` / `continueAfterFailover` / `maxAutoContinues`) |
81
+ | `preStep()` → `buildRequest()` 时序 | ✅ `:679` / `:1031`;`request/context` 仍在 `:1088` append |
82
+ | `inbox.claim()` 先抽干 | ✅ `:683`,仍在 `:698` 的 `agent/pre-step` 之前 |
83
+ | `agent/pre-step` / `agent/request-error` / `agent/request` | ✅ `:698` / `:942` / `:1007`,`agent/request` 仍未移除、仍派发 |
84
+ | `agent/request` 的硬校验 | ✅ 仍在 `:1013`——改了 `provider` / `model` / `reasoningEffort` 就抛错 |
85
+ | `agent/disposed` | ✅ `:1448` |
86
+ | `session.requestContext()` / `deriveMessages()` | ✅ `dsh-session` `:1708` / `:1753` |
87
+ | `agent.model.select()` | ✅ `dsh-agent` `model-selection.js:88`(2.2.3 的故障转移落点) |
88
+ | `agent.followup()` | ✅ `dsh-agent-loop` `:579`(2.2.3 的自动续跑) |
89
+ | 派发入口 | ✅ `startActivation(spec)`(`dsh-subagent` `:3018`),**spec 仍是扁平形状**,2.2.2 的形状自适应(探测键 `prompt`)继续正确 |
90
+ | `provider.capabilities.agentOptions` | ✅ spawn / fork 两个 in-process provider 都仍声明 `agentOptions: true` |
91
+ | `request/header` 的 `reason` | ✅ `initial` / `resume` / `change` / `series` 四种未变(`:1045` / `:1051` / `:1056`) |
92
+ | `Symbol.for("cordis.original")` | ✅ `cordis` `:39` |
93
+ | 客户端槽位 | ✅ `settings.section` 与 `settings.section.icon` 都有本插件 occupant 且 `active: true` |
94
+ | peer 区间覆盖 | ✅ `>=0.1.7-rc.1 <0.3.0-0` 放行 rc.3 / rc.4 / rc.5(`semver.satisfies` 实测 true),仍挡住 `0.3.0-rc.1` |
95
+
96
+ #### 升级指南这次终于跟上了
97
+
98
+ `docs/upgrade-guide/` 新增两个目录(此前最新是 `v0.2.2-rc.1`):
99
+
100
+ - `v0.2.2-rc.3/deepseek-refusal-code` —— 拒答错误码从 `MALFORMED_RESPONSE` 改为 `CONTENT_REFUSED`;
101
+ - `v0.2.2-rc.4/web-search-deepseek-model-default` —— DeepSeek 模型上的搜索默认改用旧版 Messages 搜索。
102
+
103
+ 两条**都落在插件未触碰的面上**,无需迁移。`0.2.2-rc.2`(扁平化 `SubagentActivationSpec`)依旧没有指南,那条只能靠逐包比对发现。
104
+
105
+ #### rc.2 → rc.3:11 个包有真实代码改动
106
+
107
+ | 包 | 改动 | 与本插件的关系 |
108
+ | --- | --- | --- |
109
+ | `dsh-client-ui-sidebar` | 新增 `sidebar.session.action` HOC 槽 | 插件只注册 `settings.section` / `settings.section.icon`,不碰侧栏会话行 |
110
+ | `dsh-client-ui-workspace` | Workspace picker 重整为 `WorkspacePickerFactory` | 与本插件无关 |
111
+ | `dsh-client-ui-directory-picker-browse` / `-native` | 跟随上述 picker 改造 | 与本插件无关 |
112
+ | `dsh-client-ui-primitives` | 新增 `IconUploadOutline{Regular,Medium}` | 纯新增;插件只用到 `Toast` 与 `IconChevronDown*`,全部仍在 |
113
+ | `dsh-deepseek-chat-import` | **新包**:DeepSeek 聊天记录导入为 Session | 与本插件无关;rc.3 唯一新增的 bundle |
114
+ | `dsh-session-log-export` | 归档导出容错:单个附件读不出来时记入 `missing` 继续导出 | 与本插件无关 |
115
+ | `dsh-cordis-client-runner` | 内嵌 `CLIENT_SLOT_API` 行号引用 | 纯文档字符串 |
116
+ | `dsh-tool-cordis` | 内嵌 `SERVICE_API` 新增 `deepseekChatImport.limits` | 纯文档字符串 |
117
+ | `dsh-agent-preset` | `dsh-doc` skill 的 `references/packages.md` 增一行 | 纯文档 |
118
+ | `dsh-official-bundles` | 把 `@deepseek-ai/dsh-deepseek-chat-import` 列入三个 bundle 清单 | 与本插件无关 |
119
+
120
+ #### rc.2 → rc.3 的契约复核(行号与 rc.2 逐位相同)
121
+
122
+ `core` / `subagent` / `llm` / `settings` / `session` / `boot` 六组共 57 个文件**全部只是 `package.json` 版本号**。当时逐项复核的结论与上面的 rc.5 表一致,唯一的差别是失败码词表当时还只有 `RATE_LIMIT` / `QUOTA` / `EMPTY_RESPONSE` / `CONTEXT_WINDOW_EXCEEDED` 等;`CONTENT_REFUSED` 是 rc.4 才加进来的。
123
+
124
+ ### Fixed
125
+
126
+ - **「应当通过」的宿主版本清单第六次滞后**:清单停在 `0.2.2-rc.3`。2.1.8 加的自检用例照例直接失败:
127
+
128
+ ```text
129
+ ✖ the running host 0.2.2-rc.5 must be listed in ADMITTED_HOST_VERSIONS
130
+ ```
131
+
132
+ 补 `0.2.2-rc.4` **与** `0.2.2-rc.5`:跨版本升级必须把跳过的版本一并列上,否则一台仍停在 rc.4 的机器上跑同一份已评审清单会失败。
133
+
134
+ 变异验证(**注意只有一半测得出来**):删掉 `0.2.2-rc.5` → `fail 1`;删掉 `0.2.2-rc.4` → **仍然 `fail 0`**,因为这台机器装的是 rc.5,而该用例只断言本机那一个版本。这是「清单记录的是已评审集合,不是本机版本」那条判据的实证——**rc.4 那一行没有任何测试替你守着**,只能靠人记得补。
135
+
136
+ > 这道自检只覆盖**版本号漏列**,不覆盖**契约变化**。rc.2 那次扁平化 spec 的破坏性变更正是它看不见的——那次是靠逐包 diff 发布物找到的。
137
+
138
+ ### Docs
139
+
140
+ `DEVELOPMENT.md`:
141
+
142
+ 1. 「宿主升级流程」第 1 步换成可直接粘贴的一行命令(asar 内不能 `ls`/`cat`,但能 `node` 读),新增第 4 步「逐包比对发布物」,并把 `skipped` 必须为 0 写进判据。
143
+ 2. 契约行号表:表头 `rc.3` / `rc.5` 改为全称 `0.2.1-rc.3` / `0.2.1-rc.5`(与 `0.2.2-rc.3` 撞名,核对时极易看错列),新增 `0.2.2-rc.3` 与 `0.2.2-rc.5` 两列(两者行号完全相同)。
144
+ 3. 新增一张「2.2.3 / 2.2.4 之后额外依赖的契约」表:`agent.model.select()`、`agent.followup()`、`session.deriveMessages()`、`agent.disposed`、失败码词表、`cordis.original`。
145
+ 4. 「逐包比对」一节补 rc.2 → rc.3 与 rc.3 → rc.5 的实操结论,并新增判据:**关键词零命中不等于契约没了**(失败码在 `dsh-llm`、`cordis.original` 定义在 `cordis`,搜错包会得出反结论)。
146
+
147
+ > 升级指南从 rc.3 起补上了(见上),但 `0.2.2-rc.2` 仍然缺席。发布物比对依旧是发现契约变化的唯一可靠手段。
148
+
149
+ ### Tests
150
+
151
+ 全量:`tests 198 / pass 198 / fail 0 / skipped 0`(用例数与 2.2.4 相同,本版未新增用例)。
152
+
153
+ ### 需要决定的一项(尚未改动,等你定)
154
+
155
+ 核对失败码时发现插件**当前切换的码集与实际会发生的失败对不上**。这不是本次升级引入的,是 8 月底 failover v1.0.0 写定码集后、宿主陆续加码造成的。下表是**实测**——用插件真实的 `agent/request-error` 监听器跑出来的,不是读常量:
156
+
157
+ | 失败码 | 宿主会不会抛 | 插件是否切换 |
158
+ | --- | --- | --- |
159
+ | `RATE_LIMIT` / `QUOTA` / `SERVER` / `TIMEOUT` / `TRANSPORT` / `EMPTY_RESPONSE` | 会 | ✅ 切换 |
160
+ | `AUTH` / `INVALID_CREDENTIAL` | 会 | ✅ 切换 |
161
+ | `STREAM_CLOSED` | **会**(`dsh-llm-deepseek:2096`、`dsh-llm-pi-ai:1688`:流在 `message_stop` 前断掉) | ❌ **不切换** |
162
+ | `ACCOUNT_QUOTA` | **会**(`dsh-llm-deepseek-account:87`,账号额度耗尽时把 `QUOTA` 改写成它) | ❌ **不切换** |
163
+ | `MALFORMED_RESPONSE` | 会(SSE 坏帧) | ❌ 不切换(宿主自己标了 `retryChoice`,但换一家未必还会坏) |
164
+ | `CONTENT_REFUSED` | 会(内容拒答) | ❌ 不切换(**正确**:换一家也会被拒) |
165
+
166
+ 前两条是实质缺口:**流被中断**和**账号额度耗尽**恰好都是换一家供应商很可能成功的场景,却直接放行错误、结束子代理。`docs/per-model-retry-design.md` 的原始需求是「连接类失败就换」,`STREAM_CLOSED` 正属于连接类。
167
+
168
+ 另有一处文档不一致:2.1.10 的核查表把 `ACCOUNT_QUOTA` 列为「已核对」的失败码,但插件源码里从来没有它。
169
+
170
+ **没有动它**,因为这是行为变更(会让上面两种失败从此触发切换),不属于「升级跟进」的范围。要修的话单独起一版。
171
+
172
+ ## 2.2.4 (2026-11-13)
173
+
174
+ ### Changed
175
+
176
+ **上下文注入改成真正的「宿主看得见」的注入行;主代理也开始收到一条。**
177
+
178
+ 用户指出的问题很具体:注入行此前只是本插件**自绘的修饰**,宿主并不知道它的存在。
179
+
180
+ - **`form` 从 `"route-context"` 改为 `"notice"`。** 这是根因。宿主 `dsh-client-ui-chat` 只认识
181
+ `instructions / catalog / snapshot / notice / relay / recall` 六个 form
182
+ (`KNOWN_FORMS`),别的值一律 `contextForm() === null` 并被丢给 `OpaqueBody`
183
+ ——于是那一行既没有摘要、展开也只有一坨原始 JSON。改用它认识的 `notice`
184
+ 并补上 `source.summary`(`provider/model`),宿主自己的
185
+ `ContextInjectionRow` 才会画出「上下文注入 · dsh-subagent-default-model · minmax/MiniMax-M3.1-Flash」。
186
+ - **删掉自绘的对话行。** `chat-subagent-model-notice` 节点 kind、`SubagentModelNoticeRow`
187
+ 渲染器、`conversation.chat.node` 注册与整套样式全部移除。它存在的理由是
188
+ DSH 0.1.7 的 `isVisibleChatNode()` 会硬排除 `node.kind === "context"`;当前宿主
189
+ (0.2.2)只排除 `system-prompt`。而只要注入是真注入(落进 session 的
190
+ `user/message`),宿主**必然**自己画一行——再自绘一条就是两行「上下文注入」。
191
+ - **主代理现在也收到一行。** 内容是设置里的默认派发模型(多模型时带策略),
192
+ 因为这份设置在主代理的上下文里读不到,「你的子代理跑在哪个模型上」原本无从回答。
193
+ 它报的是**派发目标**,不是主代理自己的 provider/model。这一行不推进轮换游标:
194
+ 它只是报告,看一眼不该改变下一次派发拿到哪条路由。
195
+
196
+ - **跨重启去重。** 内存里的「本行已注入」记录随进程消失,而主对话能活过很多次重启,
197
+ 每次重启追加一行就会像 `dsh-ldvh` 那样在一个会话里堆出三四条相同通知
198
+ (实测该插件会话中 `ldvh=3` / `ldvh=4`)。现在除内存记录外,还会读
199
+ `session.deriveMessages()`——会话自己的派生历史折叠(即发给模型的那份)——判断同一行
200
+ 是否已存在。读取器不存在时(旧宿主 / 精简 fixture)退回内存记录,不会让瀑布报错。
201
+
202
+ ### Removed
203
+
204
+ - `chat-subagent-model` 会话视图定义、`SubagentModelNoticeRow` 渲染器、
205
+ `CHAT_MODEL_NODE_KIND` 常量、`row.chatModelInitial` / `row.chatModelChange` /
206
+ `row.chatModelResume` / `row.noticeLabel` 四条 locale 词条与 `.dsm-notice-*` 样式。
207
+ 轨迹视图(`trajectory-subagent-model`)保留:它渲染的是 `request/context` 帧,
208
+ 宿主不会自己呈现。
209
+
210
+ ## 2.2.3 (2026-11-13)
211
+
212
+ ### Added
213
+
214
+ **切换后自动续跑:故障转移选中的健康路由,现在真的会被用上。**
215
+
216
+ 2.2.2 修好了「在 0.2.2 上不再抛错」,但只做到一半。`agent.model.select()` 的结果要到**下一步**的准备阶段才被读取,而一次性 `subagent` 没有下一步——于是选中的健康路由**从未被使用**,任务照样以 `error` 结束。
217
+
218
+ 实机复现(池里 `minmax` 已耗尽额度、`dsh-opencode-go` 健康):子代理被派到 `minmax`,返回
219
+ `429 … 已达到 Token Plan 用量上限`,失败转移把下一条路由选好了,会话却只有 **1 个 turn** 就结束;再手动发一条消息,同一个子代理立刻在 `dsh-opencode-go` 上跑完。**切换是自动的,续跑不是**——这就是缺口。
220
+
221
+ 现在失败转移在 `select()` 真正落地之后,通过 `agent.followup()` 唤醒子代理一轮,让新路由被用到:
222
+
223
+ - **只在真的切换成功时唤醒**。唤醒由失败转移路径直接回调触发(不是在同一个瀑布上再加一个监听器),所以池耗尽、或宿主拒绝了 `select()` 时都不会唤醒——那种情况下下一轮只会撞同一个错误,白烧一次请求。`failoverView` 还会按 `provider+model+effort` 去重,因为重复路由会让 `model.select()` 静默变成空操作。
224
+ - **唤醒消息的 `source.kind` 是 `plugin:dsh-subagent-default-model`,不是 `user`**。否则转录会把它渲染成人自己敲的消息:用户没说过这句话,也无从分辨。
225
+ - **不唤醒 fork 子代理**。判据是 `header.isSeeded === true`——header 没有 `backend` 字段,这是「带 fork 继承前缀」唯一的持久证据。它那 14 万 token 的继承前缀换到新供应商要全额重算,正是本插件在 `applyToForkChildren` 上已经拒绝付的代价。
226
+ - **不唤醒主代理**,同所有其他功能的 `origin === "subagent"` 门禁。
227
+ - **排队时机是这套机制的关键**,同时受两条硬约束夹击:
228
+ - **不能太早**:`failureAt`(由紧随其后的 `agent/error` 置位)会让宿主的收敛判断短路成 `"ready"`,排进去的消息连同收件箱一起被清掉。
229
+ - **不能太晚**:宿主判定 `"ready"` 后立刻销毁 agent,任何定时器醒来时对象都已不在。
230
+ - **不能在 `turn/end` 里排**:`session/event` 监听器是在 `Session.append()` **内部**同步调用的,此时存储仍标记该条目为「发布中」,任何嵌套 append 都会被拒——实测报错 `session append cannot reenter while another append is being published`,于是唤醒抛异常、被日志吞掉、续跑全部消失。(这一版曾用 `setImmediate` 侥幸绕开,那依赖持久化刷盘时的 I/O 让出,不是排序保证。)
231
+ - **正确时机是 `agent/status` 变为 `idle`**:`setPhase()` 在 `kick()` 的 `finally` 里同步发出它,此时候选的 `turn/end` 已提交(`failureAt` 已清除)、且不在任何 append 期间、又早于管理器的收敛检查。在此时排入收件箱,既不会被清除,也不会被销毁。
232
+ - **不重复唤醒**:判据是**收件箱**(`inbox.nextTurn` 是否已有排队),而不是 `agent.status`——后者在失败瞬间恒为 `running`,用它把关会拦掉每一次唤醒。
233
+ - **有上限**:`maxAutoContinues`(默认 2,0 关闭)。真实边界仍是池子大小(N 条最多切 N-1 次);这个上限只为「运行中改配置」这种极端情况兜底。
234
+
235
+ ### Configuration
236
+
237
+ 两个新键:
238
+
239
+ | 键 | 默认 | 含义 |
240
+ | --- | --- | --- |
241
+ | `continueAfterFailover` | `true` | 切换后是否唤醒子代理再跑一轮。设 `false` 恢复 2.2.2 的行为(只切不续) |
242
+ | `maxAutoContinues` | `2` | 单个子代理运行最多连续自动续跑几次;`0` 等于关闭 |
243
+
244
+ ### Fixed
245
+
246
+ **`strategy: "random"` 会把刚失败的那条路由再抽一次,导致整条切换链静默失效。**
247
+
248
+ 随机分支原来是一句朴素的
249
+
250
+ ```js
251
+ return Math.floor(Math.random() * entries.length);
252
+ ```
253
+
254
+ 它既不查 `tried`,也不排除**刚刚失败的那条**。抽中死路由时,`model.select()` 把「新选择」与当前选择一比,相等,于是直接返回、**不写 `model/selection`**——切换等于没发生:续跑的那一轮仍请求同一条死路由,子代理再次失败。
255
+
256
+ 实机诊断把两种结果并排拍了下来:
257
+
258
+ ```
259
+ selecting minmax/MiniMax-M3.1-Flash (before=minmax/MiniMax-M3.1-Flash)
260
+ after select, current() 未变, seq 未变 ← 判等跳过,切换白做
261
+
262
+ selecting dsh-opencode-go/deepseek-v4.1-flash (before=minmax/MiniMax-M3.1-Flash)
263
+ after select, current() 已变, seq 33→34 ← 真正写入,切换生效
264
+ ```
265
+
266
+ 修法:随机也只在**真正可用**的候选里抽——先剔除本次运行已试过的,再剔除当前正在服务(即刚失败)的那条;都剔完了才退回朴素随机,让调用方自己的池耗尽判断如实报错。
267
+
268
+ 同时补了 3 项回归测试:两条路线的池重复 200 次不得抽回死路由、三条路线的池重复 100 次同理,并把原有的随机用例从「不查重」改成「不得重选」。
269
+
270
+ ### Fixed(代码审查发现,均已补回归测试)
271
+
272
+ 1. **`random` 仍会抽回已经失败过的路由。** `tried` 只记录「切换到的」索引,最初失败的那条从未进入。于是从第二次切换起,它既不是 `served`、也不在 `tried`,又能被抽中——实测三条路线的池:**300 次第二次切换里有 136 次回到最初那条死路由**,而 `entries.length - 1` 的上限使第三条路线**从未被尝试**。修法:切换前把「刚失败的那条」也记入 `tried`(新旧宿主两条路径都修)。
273
+ 2. **`installAutoContinue` 被安装两次。** 重构(定时器改为回调)留下的旧调用还在 `installFailover` 末尾,导致两套引擎、两套监听器,且第一个引擎的返回值被丢弃。已删除。
274
+ 3. **唤醒时机改为订阅 `agent/status` 的 `idle` 转换。** 原先的 `setImmediate` 能成功,靠的是「管理器在 `flushFinalState()` 里 await 持久化刷盘、因此让出一次 I/O」——这是持久化层的副作用,不是排序保证。中途曾改成订阅 `turn/end`,但那**更糟**:`session/event` 监听器运行在 `Session.append()` 内部,`agent.followup()` 的嵌套 append 被存储的重入守卫直接拒绝(实测 `session append cannot reenter while another append is being published`),唤醒抛异常后被日志吞掉,续跑全部消失——而在测试夹具里这个错误完全看不见。`agent/status` 是唯一同时满足「`turn/end` 已提交」「不在 append 期间」「早于收敛检查」的时机。
275
+ 4. **`maxAutoContinues` 实际是每 turn 而非每 run。** 引擎原本在每个 `agent/pre-step` 删除计数器,而续跑的一轮必然从这个钩子开始,等于每轮重置预算:`maxAutoContinues: 1` 仍会排第二次续跑。已改为只在 `agent/disposed` 释放。
276
+ 5. **重复路由的池会让 `select()` 静默失效。** 池里两条解析出同一个 provider/model 时(如 `["a","a"]`),宿主比较相等后不写 `model/selection`,插件却仍记一次切换并唤醒。已在 `failoverView` 按 provider+model+effort 去重。
277
+ 10. **续跑轮无法再次切换(本轮引入又修复)。** 失败转移的分步守卫只比较 `step`、不比较 `turn`,而续跑的一轮从 `step 1` 重新开始——于是新一轮的首个失败被当成「这一 step 已经切过」而被拒,**一次性子代理因此最多只能切一次**,池里第三条路线永远用不到。实测三条路线只切到第二条;守卫改为同时比较 `turn` 与 `step` 后恢复正常(四条池可依次切到第三、第四条)。
278
+ 9. **仅 effort 不同的池会选中它当前所在的那一条。** `session.requestContext()` 不带 `reasoningEffort`,只按 provider+model 定位服务路由会指到错误的条目,于是选回子代理已经在用的 effort——宿主比较 effort,判等后静默跳过。改为用 `agent.model.current()`(含 effort)定位。
279
+ 6. **唤醒消息曾断言「你现在跑在不同且健康的供应商上」**——当选择是空操作、或目标立刻也失败时,这句话是假的。已改为不声称健康状况。
280
+ 7. **英文 README 未同步**:`continueAfterFailover` / `maxAutoContinues` 与续跑说明只写进了中文版。已补齐。
281
+ 8. **测试大面积空转**:多个「不会唤醒」的用例在延迟回调执行前就断言,把守卫删掉仍然全绿;池耗尽用例三次派发都在同一步,根本没走到耗尽分支。已全部修正,并对每个守卫做了变异验证(删掉即红)。
282
+
283
+ ### End-to-end verification (live, 2026-11-13)
284
+
285
+ 池中 `minmax/MiniMax-M3.1-Flash` 已耗尽额度、`dsh-opencode-go/deepseek-v4.1-flash` 健康。一次派发三个子代理(`strategy: random`),三者呈现完全相同的预期轨迹:
286
+
287
+ ```
288
+ turn 1 -> error (命中 minmax,429 用量上限)
289
+ turn 2 -> completed (自动切到 dsh-opencode-go 并跑完)
290
+ ```
291
+
292
+ 会话日志逐帧核对:
293
+
294
+ | 帧 | 路由 |
295
+ | --- | --- |
296
+ | `request/header` seq 13 | `minmax/MiniMax-M3.1-Flash` |
297
+ | `request/context` seq 14 | `minmax/MiniMax-M3.1-Flash` |
298
+ | `model/selection` seq 33 | `dsh-opencode-go/deepseek-v4.1-flash` |
299
+ | `request/header` seq 43 | `dsh-opencode-go/deepseek-v4.1-flash` |
300
+ | `request/context` seq 44 | `dsh-opencode-go/deepseek-v4.1-flash` |
301
+ | `assistant/message` seq 45 | 由 `dsh-opencode-go/deepseek-v4.1-flash` 生成 |
302
+
303
+ **全程没有任何人工干预**:第 2 轮由插件自己唤醒,切换由插件自己完成。这就是「一个代理不能用时切到另一个并继续工作」的完整闭环。
304
+
305
+ ### Verified
306
+
307
+ 206 项测试全绿,其中约 15 项覆盖续跑:正常唤醒、池耗尽不唤醒、主代理不唤醒、fork 不唤醒、开关关闭、失败码不合格、已在排队的收件箱不重复排队、上限为 0。
308
+
3
309
  ## 2.2.2 (2026-11-13)
4
310
 
5
311
  ### Fixed
package/README.en.md CHANGED
@@ -27,7 +27,7 @@ With `failoverEnabled` (on by default), when a subagent hits a **connection-clas
27
27
 
28
28
  - **Provider-agnostic** — candidates come from the whole `models` list, so failover works **across providers**. If `deepseek-official/deepseek-v4-pro` dies, the subagent can fail over to a *different vendor's* model in the list — not merely another model ID from the same vendor.
29
29
  - **Two classes of trigger code** —
30
- - **Connection-class**: `RATE_LIMIT`, `QUOTA`, `SERVER`, `TIMEOUT`, `TRANSPORT`, `EMPTY_RESPONSE`.
30
+ - **Connection-class**: `RATE_LIMIT`, `QUOTA`, `ACCOUNT_QUOTA`, `SERVER`, `TIMEOUT`, `TRANSPORT`, `EMPTY_RESPONSE`, `STREAM_CLOSED`.
31
31
  - **Auth-class**: `AUTH`, `INVALID_CREDENTIAL` (HTTP 401/403 — an invalid, expired, or unauthorised key).
32
32
  - Auth-class failures **do** switch: when each provider holds its own credentials, one bad key must not kill the whole delegation while healthy providers sit unused.
33
33
  - **But an auth switch always emits a warning** naming the provider whose key was refused. That is deliberate: switching buys resilience, and the **log line** is what keeps the misconfiguration from being silently hidden.
@@ -35,6 +35,13 @@ With `failoverEnabled` (on by default), when a subagent hits a **connection-clas
35
35
  - **Inherited reasoning strength is dropped** — after switching, the new provider/model is not sent the previous route's `reasoningEffort`; it resolves its own default. Otherwise a target that rejects that level can fail every request and burn through all remaining candidates.
36
36
  - **Sticky within a run** — after a switch, later steps of that same subagent stay on the new model instead of flip-flopping every step.
37
37
  - **Exhaustion passes the real error through** — once every candidate in the list has been tried, the real error surfaces; there is no infinite retry.
38
+ - **Automatic continuation after a switch** — once the new route is chosen, the plugin **wakes the subagent for one more turn** so that route is actually used, instead of being selected and never read.
39
+ - **Why this step is needed**: DSH 0.2.2+ fixes the route during each step's preparation, so `agent.model.select()` only takes effect on the **next** step. A one-shot `subagent` never starts one, so the healthy route would be **selected and never used** and the task would still end in an error (measured: the switch had selected `dsh-opencode-go` while the subagent still ended after a single turn).
40
+ - **Only wakes after a switch really landed**: not when the pool is exhausted, and not when the host refused the selection — another turn would just hit the same error.
41
+ - **Never wakes `fork` children**: they carry the parent's inherited prefix, which a provider change would re-bill in full; the test is `header.isSeeded`.
42
+ - **Never wakes the main agent**, and **never stacks a duplicate wake** — the test is whether the inbox already holds a runnable next turn, not `agent.status`.
43
+ - **The timing matters**: the wake must be queued once the failed turn has fully retired and **outside any session write** — the moment `agent/status` becomes `idle`. Queuing synchronously lets the host's settlement check clear the inbox along with the message; a timer of any length is far too late, because the agent is already disposed; and queuing inside a `turn/end` listener is rejected by the store's reentrancy guard (a nested append throws).
44
+ - Controlled by `continueAfterFailover` (on by default) and `maxAutoContinues` (default 2).
38
45
  - **Requires 2+ routes**, and **applies to subagents only** — the main agent loop is never touched.
39
46
 
40
47
  ### Capability 3 — Route visibility: you can see it, and so can the subagent
@@ -221,6 +228,8 @@ To pin a **single** model, use `model` instead of `models` (never both in the sa
221
228
  | `models` | array | `[]` | List of model entries (string or `{provider, model, reasoningEffort?}` pair). Only meaningful for Capabilities 1 and 2 with 2+ entries. |
222
229
  | `strategy` | string | `round-robin` | Capability 1's distribution strategy: `round-robin` (sequential) or `random`. |
223
230
  | `failoverEnabled` | boolean | `true` | Capability 2: switch models **across providers** inside the `models` list when a subagent hits a connection failure (subagents only). |
231
+ | `continueAfterFailover` | boolean | `true` | Capability 2: wake the subagent for one more turn after a switch, so the selected healthy route is actually used. |
232
+ | `maxAutoContinues` | number | `2` | Capability 2: maximum consecutive automatic continuations per subagent run; `0` disables it. |
224
233
  | `injectRouteContext` | boolean | `true` | Capability 3 channel 2: inject a real one-line prompt stating the live provider/model into each subagent’s **own context** (subagents only). |
225
234
  | `reasoningEffort` | string | — | Optional reasoning strength for a model entry (e.g. `high`, `max`). |
226
235
 
@@ -243,7 +252,7 @@ CI runs the same suite on `ubuntu-latest`, `windows-latest`, and `macos-latest`,
243
252
  With `failoverEnabled` on (the default), when a subagent's own loop hits a connection-class failure, the plugin automatically switches models inside the `models` list and retries, following `strategy`. See [Capability 2](#capability-2--cross-provider-failover-if-one-provider-is-down-run-on-another-providers-model) above for the full account; the key points:
244
253
 
245
254
  - **Cross-provider** — candidates are the whole `models` list, so it can fail over to a model from another provider, not just another model ID from the same vendor.
246
- - **Trigger codes** — connection-class: `RATE_LIMIT`, `QUOTA`, `SERVER`, `TIMEOUT`, `TRANSPORT`, `EMPTY_RESPONSE`; auth-class: `AUTH`, `INVALID_CREDENTIAL` (invalid/expired key — switches, with a warning). Other codes do not switch.
255
+ - **Trigger codes** — connection-class: `RATE_LIMIT`, `QUOTA`, `ACCOUNT_QUOTA`, `SERVER`, `TIMEOUT`, `TRANSPORT`, `EMPTY_RESPONSE`, `STREAM_CLOSED`; auth-class: `AUTH`, `INVALID_CREDENTIAL` (invalid/expired key — switches, with a warning). Other codes do not switch.
247
256
  - `round-robin`: advance to the next model in the list (the queue).
248
257
  - `random`: pick any model (without checking whether it was used before).
249
258
  - **Needs ≥ 2 models** — with fewer than 2 entries in `models`, the feature is inactive.
@@ -259,12 +268,14 @@ Capability 3 has **two independent channels**. See [Capability 3](#capability-3-
259
268
 
260
269
  ### Channel 1: UI rows (for the user)
261
270
 
262
- | View | What it shows | Source frame |
271
+ | View | What it shows | Source |
263
272
  | --- | --- | --- |
264
- | Trajectory | A row "Current provider/model: `provider/model`" | official `request/context` |
265
- | Conversation | One of "Current provider/model" / "Switched to" / "Currently using" | official `request/header` (by `reason`: `initial` / `change` / `resume`) |
273
+ | Conversation | The Host's own "Context injection · dsh-subagent-default-model · `provider/model`" | the injected message's `source.summary`, rendered natively by `ContextInjectionRow` |
274
+ | Trajectory | A row "Current provider/model: `provider/model`" | the plugin's own `trajectory-subagent-model` definition (over the official `request/context` frame) |
266
275
 
267
- Both registrations live inside `ctx.effect`, and the node `kind` values are plugin-owned (`trajectory-subagent-model` for the trajectory, `chat-subagent-model-notice` for the conversation) rather than reusing the Host's built-in `context` kind — the latter is filtered out by the Host's visibility rules.
276
+ > **The conversation row is drawn by the Host, not by this plugin.**
277
+ >
278
+ > Older versions hand-drew it with a plugin-owned node kind (`chat-subagent-model-notice`) plus a `conversation.chat.node` renderer. That workaround existed because DSH 0.1.7's `isVisibleChatNode()` hard-excluded `node.kind === "context"`; the current Host (0.2.2) only excludes `system-prompt`, so `context` is visible. And once an injection is a **real** injection (a `user/message` persisted into the session), the Host draws its native row for it — hand-drawing a second one would show the user two identical "context injection" rows. That whole hand-drawn path has therefore been removed.
268
279
 
269
280
  ### Channel 2: Prompt injection (for the subagent)
270
281
 
@@ -275,9 +286,17 @@ See the full description and sample text above. Implementation:
275
286
  | Value source | the `{provider, model}` returned by the `agent/request` waterfall **after** it settles (including a failover swap) |
276
287
  | Injection point | the following `agent/pre-step`, where that step's message list is still mutable |
277
288
  | Dedupe | an unchanged route injects nothing; a changed route replaces the stale line |
278
- | Scope | `origin === "subagent"` only; the main agent is never touched |
289
+ | Scope | a subagent reports **the route it is actually running on**; the main agent reports **the model its delegations will use** (see below) |
279
290
  | Setting | `injectRouteContext`, on by default |
280
- | Message source | `plugin:dsh-subagent-default-model` + `form: "route-context"` (the v4 session format requires a producer-owned `source.kind`) |
291
+ | Message source | `plugin:dsh-subagent-default-model` + `form: "notice"` + `summary` (v4 requires a producer-owned `source.kind`; the `form` must be one the Host knows or the row renders as a raw JSON dump) |
292
+
293
+ #### The main agent is told its DELEGATION target, not its own route
294
+
295
+ The main agent cannot read this plugin's settings, so "which model do your subagents run on?" has no answer in its context. It therefore receives one line describing the configured pool (with the strategy when there are several, e.g. `a/x / b/y (round-robin)`). It deliberately does **not** report the main agent's own provider/model — the main agent is not the one being routed, and repeating it would be noise.
296
+
297
+ That line is injected only when its content changes, and it **does not advance the round-robin cursor**: it is a report, and looking at it must not change which route the next delegation gets.
298
+
299
+ Dedupe survives restarts: besides the in-run memory record, it reads `session.deriveMessages()` — the session's own derived-history fold, i.e. what the model is sent — to see whether the same line is already there. In-memory tracking alone is not enough: a main conversation outlives many restarts, and appending a row on each one would pile up three or four identical notices in a single session (the failure `dsh-ldvh` shows in the wild).
281
300
 
282
301
  > **The line only appears once the route is known.**
283
302
  >
package/README.md CHANGED
@@ -27,7 +27,7 @@
27
27
 
28
28
  - **不区分供应商** —— 候选来自整个 `models` 列表,**跨 provider 生效**。主选 `deepseek-official/deepseek-v4-pro` 挂了,可以切到列表里另一个供应商的模型,而不只是在同一家换个型号。
29
29
  - **触发码分两类** ——
30
- - **连接类**:`RATE_LIMIT`、`QUOTA`、`SERVER`、`TIMEOUT`、`TRANSPORT`、`EMPTY_RESPONSE`。
30
+ - **连接类**:`RATE_LIMIT`、`QUOTA`、`ACCOUNT_QUOTA`、`SERVER`、`TIMEOUT`、`TRANSPORT`、`EMPTY_RESPONSE`、`STREAM_CLOSED`。
31
31
  - **认证类**:`AUTH`、`INVALID_CREDENTIAL`(HTTP 401/403,密钥无效/过期/无权限)。
32
32
  - 认证类**也会切换**:当各家供应商密钥各自独立时,其中一家密钥失效不应该让整个任务死掉、而健康的供应商却在闲置。
33
33
  - **但切换时一定会打 warn 日志**,明确指出「该供应商的密钥可能无效」——这是刻意设计:允许切换是为了可用性,而**日志**保证这个配置问题不会被静默掩盖。
@@ -35,6 +35,13 @@
35
35
  - **切换时丢弃继承的推理强度** —— 换到新 provider/model 后不沿用旧路由的 `reasoningEffort`,按目标自己的默认档位请求;否则目标模型可能因「不支持该强度」而直接拒绝请求,导致把剩余候选全部烧光。
36
36
  - **同一次运行内粘住** —— 切换后该子代理后续步骤继续跑在新模型上,不会每步来回跳。
37
37
  - **耗尽即放行** —— 列表内全部候选都试过仍失败,就抛出真实错误,不做无限重试。
38
+ - **切换后自动续跑** —— 换好路由之后,插件会**唤醒子代理再跑一轮**,让新路由真正被用上,而不是「切好了却没人用」。
39
+ - **为什么需要这一步**:宿主 0.2.2+ 把路由锁死在每个 step 的准备阶段,`agent.model.select()` 的结果要到**下一步**才被读取;一次性 `subagent` 没有下一步,于是选中的健康路由会**从未被使用**、任务照样以错误结束(实测:切换已选中 `dsh-opencode-go`,子代理仍只有 1 个 turn 就失败)。
40
+ - **只在真的切换成功时唤醒**:池耗尽、或宿主拒绝选择时不唤醒——那种情况下一轮只会撞同一个错误。
41
+ - **不唤醒 `fork` 子代理**:它带着父会话的继承前缀,换供应商要全额重算;判据是 `header.isSeeded`。
42
+ - **不唤醒主代理**,也**不会重复排队**——判据是收件箱里是否已有待执行的下一轮,而不是 `agent.status`。
43
+ - **排队时机很讲究**:必须等失败的 turn 完全退役、且**不在任何 session 写入期间**——即 `agent/status` 变为 `idle` 的那一刻。同步排队会被宿主的收敛判断连同收件箱一起清掉;延迟若干毫秒则 agent 早已被销毁;而在 `turn/end` 监听器里排队会被存储的重入守卫拒绝(嵌套 append 会抛错)。
44
+ - 由 `continueAfterFailover`(默认开)与 `maxAutoContinues`(默认 2)控制。
38
45
  - **需要 ≥ 2 条路由**,且**仅对子代理生效** —— 主代理循环不受影响。
39
46
 
40
47
  ### 功能三:当前路由可见 —— 界面看得见,子代理也知道
@@ -235,6 +242,8 @@ CI 在 `ubuntu-latest`、`windows-latest`、`macos-latest` 三个平台上同时
235
242
  | `models` | array | `[]` | 模型条目列表(string 或 `{provider, model, reasoningEffort?}` 对)。≥2 项时功能一、二才有意义。 |
236
243
  | `strategy` | string | `round-robin` | 功能一的分配策略:`round-robin`(顺序轮换)或 `random`(随机)。 |
237
244
  | `failoverEnabled` | boolean | `true` | 功能二:子代理连接类失败时在 `models` 列表内**跨供应商**切换模型(仅 subagent)。 |
245
+ | `continueAfterFailover` | boolean | `true` | 功能二:切换后唤醒子代理再跑一轮,让选中的健康路由真正被用上。 |
246
+ | `maxAutoContinues` | number | `2` | 功能二:单个子代理运行最多连续自动续跑几次;`0` 等于关闭。 |
238
247
  | `injectRouteContext` | boolean | `true` | 功能三通路二:向子代理**自己的上下文**注入一行「当前 provider/model」的真实提示词(仅 subagent)。 |
239
248
  | `reasoningEffort` | string | — | 可选推理强度(如 `high`、`max`)。 |
240
249
 
@@ -243,7 +252,7 @@ CI 在 `ubuntu-latest`、`windows-latest`、`macos-latest` 三个平台上同时
243
252
  开启 `failoverEnabled`(默认开启)后,子代理自身的循环遇到连接类失败时,插件会在 `models` 列表内按 `strategy` 自动切换模型并重试。完整说明见上文「[功能二:跨供应商故障转移](#功能二跨供应商故障转移--这条通了那条不通就换另一个供应商的模型)」,要点复述:
244
253
 
245
254
  - **跨供应商** —— 候选是整个 `models` 列表,可以切到另一个 provider 的模型,不限于同一家换型号。
246
- - **触发码** —— 连接类:`RATE_LIMIT`、`QUOTA`、`SERVER`、`TIMEOUT`、`TRANSPORT`、`EMPTY_RESPONSE`;认证类:`AUTH`、`INVALID_CREDENTIAL`(密钥无效/过期,会切换并打 warn 日志)。其余码不切换。
255
+ - **触发码** —— 连接类:`RATE_LIMIT`、`QUOTA`、`ACCOUNT_QUOTA`、`SERVER`、`TIMEOUT`、`TRANSPORT`、`EMPTY_RESPONSE`、`STREAM_CLOSED`;认证类:`AUTH`、`INVALID_CREDENTIAL`(密钥无效/过期,会切换并打 warn 日志)。其余码不切换。
247
256
  - `round-robin`:按列表顺序切到下一个模型(队列)。
248
257
  - `random`:随机挑一个模型(不判断之前是否用过)。
249
258
  - **需要 ≥ 2 个模型** —— 当 `models` 少于 2 项时本功能不生效。
@@ -259,12 +268,19 @@ CI 在 `ubuntu-latest`、`windows-latest`、`macos-latest` 三个平台上同时
259
268
 
260
269
  ### 通路一:界面行(给用户)
261
270
 
262
- | 视图 | 呈现内容 | 依据帧 |
271
+ | 视图 | 呈现内容 | 依据 |
263
272
  | --- | --- | --- |
264
- | 轨迹视图 | 一行「当前供应商/模型:`provider/model`」 | 官方 `request/context` |
265
- | 对话视图 | 「当前供应商/模型」/「已切换到」/「当前使用」三类文案行 | 官方 `request/header`(按 `reason` 区分 `initial` / `change` / `resume`) |
273
+ | 对话视图 | 宿主自己画的「上下文注入 · dsh-subagent-default-model · `provider/model`」 | 注入消息的 `source.summary`,由 `ContextInjectionRow` 原生渲染 |
274
+ | 轨迹视图 | 一行「当前供应商/模型:`provider/model`」 | 插件自有定义 `trajectory-subagent-model`(依据官方 `request/context` 帧) |
266
275
 
267
- 两个视图都在 `ctx.effect` 内注册,且节点 `kind` 使用插件自有值(轨迹侧 `trajectory-subagent-model`,对话侧 `chat-subagent-model-notice`),不占用宿主内置 `context` kind —— 后者会被宿主的可见性规则过滤掉。
276
+ > **对话视图那一行是宿主画的,不是本插件画的。**
277
+ >
278
+ > 旧版本用一本自有节点 kind(`chat-subagent-model-notice`)+ 一个
279
+ > `conversation.chat.node` 渲染器自绘对话行。这个绕过的前提是 DSH 0.1.7 的
280
+ > `isVisibleChatNode()` 会硬排除 `node.kind === "context"`;当前宿主(0.2.2)
281
+ > 只排除 `system-prompt`,`context` 本身可见。而只要注入是**真注入**(落进
282
+ > session 的 `user/message`),宿主就会为它画原生行——再自绘一条,用户会看到
283
+ > 两条一模一样的「上下文注入」。所以自绘那一套已整段删除。
268
284
 
269
285
  ### 通路二:提示词注入(给子代理)
270
286
 
@@ -275,9 +291,17 @@ CI 在 `ubuntu-latest`、`windows-latest`、`macos-latest` 三个平台上同时
275
291
  | 取值来源 | `agent/request` 瀑布**结算后**返回的 `{provider, model}`(含故障转移切换结果) |
276
292
  | 注入时机 | 下一步的 `agent/pre-step`,此时该步消息列表仍可修改 |
277
293
  | 去重 | 路由不变则不重复注入;路由变化则替换旧行 |
278
- | 作用域 | 仅 `origin === "subagent"`;主代理不碰 |
294
+ | 作用域 | 子代理报**自己实际在跑的路由**;主代理报**子代理会被派发到的默认模型**(见下) |
279
295
  | 开关 | `injectRouteContext`,默认开启 |
280
- | 消息来源 | `plugin:dsh-subagent-default-model` + `form: "route-context"`(v4 会话格式要求生产者自有 `source.kind`) |
296
+ | 消息来源 | `plugin:dsh-subagent-default-model` + `form: "notice"` + `summary`(v4 要求生产者自有 `source.kind`;`form` 必须是宿主认识的值,否则只渲染一坨原始 JSON) |
297
+
298
+ #### 主代理收到的是「派发目标」,不是它自己的路由
299
+
300
+ 主代理读不到本插件的设置,所以「你的子代理跑在哪个模型上」这个问题在它的上下文里没有答案。为此主代理会收到一行说明,内容来自设置里的模型池(多模型时连策略一起列出,如 `a/x / b/y (round-robin)`)。它**不会**报主代理自己的 provider/model——主代理不是被路由的那一方,重复一遍只是噪音。
301
+
302
+ 这一行同样只在这行内容变化时注入,且**不推进轮换游标**:它是一份报告,读一眼不应该改变下一次派发拿到哪条路由。
303
+
304
+ 去重是**跨重启**的:除了本轮内存里的记录,还会读 `session.deriveMessages()`(会话自己的派生历史折叠,也就是发给模型的那份)判断同一行是否已经存在。只靠内存记录不够——主对话能活过很多次重启,每次重启都追加一行,就会像 `dsh-ldvh` 那样在一个会话里堆出三四条一模一样的通知。
281
305
 
282
306
  > **注入是有前提的:路由已知才会注入。**
283
307
  >