dsh-subagent-default-model 2.2.0 → 2.2.1
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 +55 -0
- package/lib/client.js +2 -2
- package/lib/index.js +42 -27
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,60 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.2.1 (2026-11-10)
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
**注入的路由行晚了一步,两步以内结束的子代理根本看不到。**
|
|
8
|
+
|
|
9
|
+
实机验证时,四个子代理里只有两个「更正」了自己的路由;其余在本应回答时答「未知」。查宿主源码后确认不是它们偷懒,而是投递时机错了:
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
// dsh-agent-loop / preStep()
|
|
13
|
+
const claimed = this.inbox.claim(target, position.turn); // ← 先把 next-step 抽干
|
|
14
|
+
const decision = await this.dispatch.waterfall("agent/pre-step", { messages: claimed, ... });
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`claim()` 在 waterfall **之前**就把 `next-step` 清空了。旧实现是在 waterfall 里 `agent.inbox.prepend("next-step", …)`,所以那行只能被**下一次** `preStep()` 认领——它必然晚一步到达模型。一步结束的子代理永远看不到;两步的也是到最后才看到。
|
|
18
|
+
|
|
19
|
+
这直接违背了这一功能的原始承诺(「子代理因此能回答自己跑在哪个模型上」)。
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
注入改为写进 `decision.messages`:
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
return { ...decision, messages: [...decision.messages, message] };
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
这样一次投递同时得到两个效果:
|
|
30
|
+
|
|
31
|
+
1. **当前步就能看到**——`decision.messages` 正是 `step()` 要发送的消息列表;
|
|
32
|
+
2. **持久进历史**——`step()` 会把每一条 append 成 `user/message`,所以后续步骤无需重复注入也能看到。
|
|
33
|
+
|
|
34
|
+
因此 inbox 不再参与投递,去掉了「清理未认领副本」的逻辑,并删除随之成为孤儿的 `isRouteContextMessage`。
|
|
35
|
+
|
|
36
|
+
### 仍然存在、且无法通过实现消除的限制
|
|
37
|
+
|
|
38
|
+
路由要等**当前步的请求**发出后才知道(`request/context`),而 `preStep()` 在它之前运行。所以:
|
|
39
|
+
|
|
40
|
+
- 第 1 步没有可信的路由可报——用 `agent.options` 的派发时种子去猜,正是本项目早已修过的 bug(子代理实际跑在 `ds41`,却被标成 `glm`);
|
|
41
|
+
- 因此这一行**从第 2 步起**才可见;**一步就结束的子代理仍然看不到**。这是时序决定的,不是遗漏。
|
|
42
|
+
- 附带代价:注入使该步消息非空,于是「本来要收尾的轮次」会多跑一步(循环只在 `turnEnds && messages.length === 0` 时结束)。去重保证每个路由最多一次,所以一定收敛——旧实现同样如此,只是它把行又推迟了一步。
|
|
43
|
+
|
|
44
|
+
README(中英)与设置页开关说明都已改成如实描述:「从第 2 步起」。
|
|
45
|
+
|
|
46
|
+
### Tests
|
|
47
|
+
|
|
48
|
+
`183/183`(180 → 183),`skip 0`。新增三条守卫:
|
|
49
|
+
|
|
50
|
+
- 路由一确定就在**同一步**投递(断言 inbox 里不留残余),这条正是旧实现的失败点;
|
|
51
|
+
- 投递一次即持久:后续两步不重复注入,历史里恰好一份;
|
|
52
|
+
- 路由中途变化时投递新值,同一路由永不重复投递。
|
|
53
|
+
|
|
54
|
+
夹具也做了对应改造:`dispatchPreStep` 现在模拟 `step()` 把 `decision.messages` 写入历史,并区分「正常步」与「收尾空步」——原来默认传空列表,在新语义下等于收尾步。
|
|
55
|
+
|
|
56
|
+
变异验证 4/4 命中:改回 inbox 投递、去掉去重、前置而非追加、丢弃循环自带消息。
|
|
57
|
+
|
|
3
58
|
## 2.2.0 (2026-11-06)
|
|
4
59
|
|
|
5
60
|
**次版本号升级**:这一版把插件的配置界面从「插件市场详情页的卡片」整体搬到**设置面板左侧导航的独立页面**,是一次用户可见的入口变更,因此走 `2.2.0` 而不是补丁号。同时撤销了 2.1.15 的详情页短简介机制。
|
package/lib/client.js
CHANGED
|
@@ -100,7 +100,7 @@ window.__ModuleLoader__.load({
|
|
|
100
100
|
"row.failoverEnabled": "连接失败时按队列与策略切换模型",
|
|
101
101
|
"row.failoverHint": "(需配置 ≥2 个 Provider,切换才会生效)。",
|
|
102
102
|
"row.injectRouteContext": "把当前模型与供应商写进子代理上下文",
|
|
103
|
-
"row.injectRouteContextHint": "
|
|
103
|
+
"row.injectRouteContextHint": "(子代理从第 2 步起能回答自己跑在哪个模型上;这是一行真实提示词,不是界面显示)。",
|
|
104
104
|
"row.applyToForkChildren": "让 subagent_fork 子代理也使用这里设定的模型",
|
|
105
105
|
"row.applyToForkChildrenHint": "(默认关闭。fork 子代理会继承父会话的完整对话,宿主因此让它留在父路由上,好让这段前缀能复用缓存;开启后它会改用这里的模型,代价是那段继承的上下文要在新模型上重新算一次)。",
|
|
106
106
|
"row.trajectoryModel": "当前供应商/模型",
|
|
@@ -147,7 +147,7 @@ window.__ModuleLoader__.load({
|
|
|
147
147
|
"row.failoverEnabled": "Switch models by queue and strategy on connection failure",
|
|
148
148
|
"row.failoverHint": "(requires at least 2 configured providers).",
|
|
149
149
|
"row.injectRouteContext": "Tell subagents which model and provider they run on",
|
|
150
|
-
"row.injectRouteContextHint": "(
|
|
150
|
+
"row.injectRouteContextHint": "(from step 2 a subagent can answer which model it is; a real prompt line, not a display row).",
|
|
151
151
|
"row.applyToForkChildren": "Also apply these models to subagent_fork children",
|
|
152
152
|
"row.applyToForkChildrenHint": "(off by default. A fork child inherits the parent's full conversation, so the host keeps it on the parent's route to preserve cache reuse of that prefix; turning this on moves it to the configured model and re-runs the inherited context once on the new model).",
|
|
153
153
|
"row.trajectoryModel": "Current provider/model",
|
package/lib/index.js
CHANGED
|
@@ -644,11 +644,6 @@ function routeContextText(provider, model) {
|
|
|
644
644
|
+ "This line is system-provided context about the runtime, not a user instruction.";
|
|
645
645
|
}
|
|
646
646
|
|
|
647
|
-
/** True when a message is this plugin's injected route line. */
|
|
648
|
-
function isRouteContextMessage(message) {
|
|
649
|
-
return message?.source?.kind === ROUTE_CONTEXT_SOURCE && message.source.form === ROUTE_CONTEXT_FORM;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
647
|
/**
|
|
653
648
|
* Has this agent built a request yet in the CURRENT run?
|
|
654
649
|
*
|
|
@@ -765,50 +760,70 @@ function installRouteContextInjector(ctx, state) {
|
|
|
765
760
|
// Inject on the pre-step, where the message list for the step about to run
|
|
766
761
|
// is still mutable and the agent's own route is already known.
|
|
767
762
|
//
|
|
768
|
-
//
|
|
769
|
-
//
|
|
770
|
-
//
|
|
771
|
-
//
|
|
772
|
-
//
|
|
773
|
-
//
|
|
774
|
-
//
|
|
775
|
-
//
|
|
776
|
-
//
|
|
777
|
-
//
|
|
763
|
+
// THE LINE MUST GO INTO `decision.messages`, NOT THE INBOX.
|
|
764
|
+
// `preStep()` claims (`inbox.claim()`) at its TOP, BEFORE this waterfall, and
|
|
765
|
+
// `claim()` DRAINS `next-step`. So a line prepended into the inbox here can
|
|
766
|
+
// only be claimed by the NEXT `preStep()`: it reached the model one step
|
|
767
|
+
// late. A subagent that finished in a single step therefore NEVER saw it —
|
|
768
|
+
// which broke this feature's whole promise ("the subagent can tell you which
|
|
769
|
+
// model it runs on"), and the pending line also kept the turn alive for one
|
|
770
|
+
// extra, pointless step.
|
|
771
|
+
//
|
|
772
|
+
// `decision.messages` is what `step()` sends, and `step()` appends every
|
|
773
|
+
// entry to the session as a `user/message`, so a line placed there is BOTH
|
|
774
|
+
// visible in the step it belongs to AND persisted into history for every
|
|
775
|
+
// later step. One delivery, both effects.
|
|
776
|
+
//
|
|
777
|
+
// WHAT THIS CANNOT DO: PUT THE LINE ON STEP 1.
|
|
778
|
+
// The route is only known after the step's request commits (`request/context`),
|
|
779
|
+
// and `preStep()` runs BEFORE that request — so on step 1 there is nothing
|
|
780
|
+
// trustworthy to report, and guessing from the dispatch-time `agent.options`
|
|
781
|
+
// is exactly the bug this file already fixed once (a subagent really on `ds41`
|
|
782
|
+
// was labelled `glm`). The line therefore lands on the first `preStep()` whose
|
|
783
|
+
// route is KNOWN, normally step 2. A subagent that finishes inside one step
|
|
784
|
+
// still gets no line — structurally, not by oversight.
|
|
785
|
+
//
|
|
786
|
+
// COST: because an injected message makes that step's list non-empty, a turn
|
|
787
|
+
// that was already finishing runs one more step (the loop breaks only on
|
|
788
|
+
// `turnEnds && decision.messages.length === 0`). The dedupe below makes that
|
|
789
|
+
// happen at most once per route, so it terminates — and this is what the
|
|
790
|
+
// previous inbox-based delivery already did, it just also delayed the line by
|
|
791
|
+
// one further step and never showed it to two-step subagents at all.
|
|
792
|
+
//
|
|
793
|
+
// DEDUPE IS STILL OUT-OF-BAND. The claimed list is drained by `claim()` before
|
|
794
|
+
// this runs, so "is a copy still pending?" is structurally always false; an
|
|
795
|
+
// earlier build asked exactly that and re-injected on EVERY step (a real
|
|
796
|
+
// 29-step subagent collected 28 identical lines). Track what was last injected
|
|
797
|
+
// for this agent instead.
|
|
778
798
|
const injectedRoute = new Map();
|
|
779
799
|
|
|
780
|
-
const disposePreStep = ctx.on("agent/pre-step", async ({ agent
|
|
800
|
+
const disposePreStep = ctx.on("agent/pre-step", async ({ agent }, next) => {
|
|
781
801
|
const decision = await next();
|
|
782
802
|
if (decision === void 0 || decision === null || decision.kind === "reject") return decision;
|
|
783
803
|
if (state.getSection()?.injectRouteContext === false) return decision;
|
|
784
804
|
if (!isSubagentAgent(agent)) return decision;
|
|
785
805
|
|
|
806
|
+
if (!Array.isArray(decision.messages)) return decision;
|
|
807
|
+
|
|
786
808
|
// The live session route wins; see `routeForInjection` for why the
|
|
787
809
|
// dispatch-time `agent.options` must NOT be preferred.
|
|
788
810
|
const route = routeForInjection(agent, resolvedRoute);
|
|
789
811
|
if (route === void 0) return decision;
|
|
790
|
-
// Defensive: only the loop's live Agent exposes an inbox. A test double
|
|
791
|
-
// or a future agent shape without one must not break the step.
|
|
792
|
-
if (agent.inbox === void 0 || !Array.isArray(agent.inbox.nextStep)) return decision;
|
|
793
812
|
|
|
794
813
|
const wanted = routeContextText(route.provider, route.model);
|
|
795
814
|
// Same route as last time => the line already placed in this session is
|
|
796
815
|
// still accurate; inject nothing (no duplicate, no churn).
|
|
797
816
|
if (injectedRoute.get(agent.id)?.text === wanted) return decision;
|
|
798
817
|
|
|
799
|
-
// Route moved (failover / config change): drop any not-yet-claimed copy so
|
|
800
|
-
// the stale route does not linger beside the fresh one.
|
|
801
|
-
for (const message of agent.inbox.nextStep.filter(isRouteContextMessage)) {
|
|
802
|
-
agent.inbox.remove(message.id);
|
|
803
|
-
}
|
|
804
|
-
|
|
805
818
|
const message = createUserMessage({
|
|
806
819
|
content: [{ type: "text", text: wanted }],
|
|
807
820
|
source: { kind: ROUTE_CONTEXT_SOURCE, form: ROUTE_CONTEXT_FORM }
|
|
808
821
|
});
|
|
809
|
-
agent.inbox.prepend("next-step", message);
|
|
810
822
|
injectedRoute.set(agent.id, { text: wanted });
|
|
811
|
-
|
|
823
|
+
// A new array, not a push: the decision object belongs to the loop, and a
|
|
824
|
+
// reader comparing identities should see a change rather than a surprise
|
|
825
|
+
// mutation of what it already handed over.
|
|
826
|
+
return { ...decision, messages: [...decision.messages, message] };
|
|
812
827
|
});
|
|
813
828
|
|
|
814
829
|
const disposeDisposed = ctx.on("agent/disposed", ({ agent }) => {
|
package/package.json
CHANGED