dsh-subagent-default-model 2.2.0 → 2.2.2

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,103 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.2.2 (2026-11-13)
4
+
5
+ ### Fixed
6
+
7
+ **宿主 0.2.2-rc.2 把 `startActivation(spec)` 的 spec 扁平化了,默认模型注入因此静默失效。**
8
+
9
+ rc.2 起 `SubagentActivationSpec` 不再嵌套 `request`,而是直接继承 `SubagentStartRequest`:
10
+
11
+ ```ts
12
+ // <= 0.2.2-rc.1
13
+ { provider, label, signal, delivery, request: { prompt, parent, agentOptions, … } }
14
+ // >= 0.2.2-rc.2
15
+ { provider, label, signal, delivery, prompt, parent, agentOptions, … }
16
+ ```
17
+
18
+ 插件包装的正是这个方法,而它只读 `spec.request`。在 rc.2 上拿到 `undefined` 后,`applyDefaultModelFor` 首行原样返回,**spec 原封不动透传给宿主**——子代理退回继承父路由,两处池配置一条都没生效。
19
+
20
+ **为什么没被测试拦住**:夹具只造嵌套形状,`183/183` 全绿;这个缺陷也没有升级指南(`docs/upgrade-guide/` 里没有 `v0.2.2-rc.2` 目录),只能靠逐包 `npm pack` + `diff` 发布物发现。
21
+
22
+ **为什么在界面上看不出来**:`injectRouteContext` 仍然工作,它读的是会话自己的 `request/context`,所以「当前供应商/模型」照常渲染——只是显示的永远是父路由。两个功能一个坏一个正常,反而更像「配置没写对」。
23
+
24
+ 实机证据(升级后立即复现):子代理会话的派发描述符为
25
+ `{"provider":"spawn","agentProvider":"workbuddy","agentModel":"deepseek-v4.1-flash"}`,
26
+ 而 `workbuddy` 是父会话路由,配置池里只有 `minmax/MiniMax-M3.1-Flash` 与 `dsh-opencode-go/deepseek-v4.1-flash`。升级前的同类描述符是正确的 `minmax/MiniMax-M3.1-Flash`。
27
+
28
+ ### Changed
29
+
30
+ 注入改为**形状自适应**,一个构建同时服务新旧宿主:
31
+
32
+ - 读:`activationRequestOf(spec)` 探测键用 `prompt`(`SubagentStartRequest` 里的必填字段),顶层有它就是扁平;有嵌套 `request` 则优先用它。
33
+ - 写:`withActivationRequest()` 按原形状还原——扁平宿主拿到的是注入后的对象本身,嵌套宿主拿到 `{ ...spec, request }`。
34
+ - 不注入时仍返回**原 spec 引用**:宿主会比较 spec/request 的身份,无谓的拷贝是静默的行为变更。
35
+
36
+ ### Tests
37
+
38
+ `188/188`(183 → 188),`skip 0`。新增 5 条扁平 spec 用例:注入 / 显式路由优先 / 空配置继承 / fork 默认不注入 / fork 打开 `applyToForkChildren` 后跟随池。
39
+
40
+ 变异验证 2/2 命中:把读法改回 `spec.request`、或回写时不还原扁平形状,都会让其中 2 条失败。
41
+
42
+ `ADMITTED_HOST_VERSIONS` 补入 `0.2.2-rc.2`,并**删除从未存在过的 `0.2.5-rc.1`**(npm 上没有任何 `@deepseek-ai/dsh*` 发布过该版本;它一直匹配 peer 区间,所以从未报错,只是虚增了「已评审版本」集合)。
43
+
44
+ `peer-range` 的「running host must be admitted」用例在修复前按预期失败:`the running host 0.2.2-rc.2 must be listed in ADMITTED_HOST_VERSIONS`——这条护栏第五次发挥作用的记录在 `DEVELOPMENT.md`。
45
+
46
+ ## 2.2.1 (2026-11-10)
47
+
48
+ ### Fixed
49
+
50
+ **注入的路由行晚了一步,两步以内结束的子代理根本看不到。**
51
+
52
+ 实机验证时,四个子代理里只有两个「更正」了自己的路由;其余在本应回答时答「未知」。查宿主源码后确认不是它们偷懒,而是投递时机错了:
53
+
54
+ ```js
55
+ // dsh-agent-loop / preStep()
56
+ const claimed = this.inbox.claim(target, position.turn); // ← 先把 next-step 抽干
57
+ const decision = await this.dispatch.waterfall("agent/pre-step", { messages: claimed, ... });
58
+ ```
59
+
60
+ `claim()` 在 waterfall **之前**就把 `next-step` 清空了。旧实现是在 waterfall 里 `agent.inbox.prepend("next-step", …)`,所以那行只能被**下一次** `preStep()` 认领——它必然晚一步到达模型。一步结束的子代理永远看不到;两步的也是到最后才看到。
61
+
62
+ 这直接违背了这一功能的原始承诺(「子代理因此能回答自己跑在哪个模型上」)。
63
+
64
+ ### Changed
65
+
66
+ 注入改为写进 `decision.messages`:
67
+
68
+ ```js
69
+ return { ...decision, messages: [...decision.messages, message] };
70
+ ```
71
+
72
+ 这样一次投递同时得到两个效果:
73
+
74
+ 1. **当前步就能看到**——`decision.messages` 正是 `step()` 要发送的消息列表;
75
+ 2. **持久进历史**——`step()` 会把每一条 append 成 `user/message`,所以后续步骤无需重复注入也能看到。
76
+
77
+ 因此 inbox 不再参与投递,去掉了「清理未认领副本」的逻辑,并删除随之成为孤儿的 `isRouteContextMessage`。
78
+
79
+ ### 仍然存在、且无法通过实现消除的限制
80
+
81
+ 路由要等**当前步的请求**发出后才知道(`request/context`),而 `preStep()` 在它之前运行。所以:
82
+
83
+ - 第 1 步没有可信的路由可报——用 `agent.options` 的派发时种子去猜,正是本项目早已修过的 bug(子代理实际跑在 `ds41`,却被标成 `glm`);
84
+ - 因此这一行**从第 2 步起**才可见;**一步就结束的子代理仍然看不到**。这是时序决定的,不是遗漏。
85
+ - 附带代价:注入使该步消息非空,于是「本来要收尾的轮次」会多跑一步(循环只在 `turnEnds && messages.length === 0` 时结束)。去重保证每个路由最多一次,所以一定收敛——旧实现同样如此,只是它把行又推迟了一步。
86
+
87
+ README(中英)与设置页开关说明都已改成如实描述:「从第 2 步起」。
88
+
89
+ ### Tests
90
+
91
+ `183/183`(180 → 183),`skip 0`。新增三条守卫:
92
+
93
+ - 路由一确定就在**同一步**投递(断言 inbox 里不留残余),这条正是旧实现的失败点;
94
+ - 投递一次即持久:后续两步不重复注入,历史里恰好一份;
95
+ - 路由中途变化时投递新值,同一路由永不重复投递。
96
+
97
+ 夹具也做了对应改造:`dispatchPreStep` 现在模拟 `step()` 把 `decision.messages` 写入历史,并区分「正常步」与「收尾空步」——原来默认传空列表,在新语义下等于收尾步。
98
+
99
+ 变异验证 4/4 命中:改回 inbox 投递、去掉去重、前置而非追加、丢弃循环自带消息。
100
+
3
101
  ## 2.2.0 (2026-11-06)
4
102
 
5
103
  **次版本号升级**:这一版把插件的配置界面从「插件市场详情页的卡片」整体搬到**设置面板左侧导航的独立页面**,是一次用户可见的入口变更,因此走 `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": "(so a subagent can answer which model it is; this is a real prompt line, not a display row).",
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
- // DEDUPE MUST BE OUT-OF-BAND, NOT "is a copy still pending?".
769
- // The loop calls `inbox.claim()` at the TOP of `preStep()` — BEFORE this
770
- // waterfall — and `claim()` DRAINS `next-step`
771
- // (`mutate("next-step", 0, this.nextStep.length, [], false)`). So by the time
772
- // this listener runs, the pending list is always empty and a "does a route
773
- // line already exist in the inbox?" test is structurally always false. An
774
- // earlier build did exactly that and re-injected on EVERY step: a real
775
- // 29-step subagent ended up with 28 identical route lines, which also made
776
- // the reported route churn between turns. Track what was last injected for
777
- // this agent instead.
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, messages }, next) => {
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
- return decision;
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 }) => {
@@ -825,6 +840,65 @@ function installRouteContextInjector(ctx, state) {
825
840
  }, "dsh-subagent-default-model: route context injector");
826
841
  }
827
842
 
843
+ /**
844
+ * Read the delegation request out of one `startActivation` spec, in either
845
+ * shape the host has shipped.
846
+ *
847
+ * 0.2.2-rc.2 changed `SubagentActivationSpec` from a nested object to one that
848
+ * extends `SubagentStartRequest`:
849
+ *
850
+ * <= 0.2.2-rc.1 : { provider, label, signal, delivery, request: { prompt, parent, agentOptions, … } }
851
+ * >= 0.2.2-rc.2 : { provider, label, signal, delivery, prompt, parent, agentOptions, … }
852
+ *
853
+ * Both are still in the wild (the peer range spans the whole 0.2.x line), so
854
+ * the shape is DETECTED, never assumed. Reading `spec.request` alone on rc.2
855
+ * yields `undefined`, the wrapper then passes the spec through untouched, and
856
+ * every child silently inherits the parent route while the route-visibility
857
+ * line keeps rendering correctly — a failure with no error and no log line.
858
+ *
859
+ * The probe is `prompt`, not `request`: `prompt` is REQUIRED on
860
+ * `SubagentStartRequest` in every version, so its presence at the top level is
861
+ * what makes the spec flat. A nested spec could in principle carry an
862
+ * unrelated `request` key; a flat one cannot exist without `prompt`.
863
+ *
864
+ * @param spec - the activation spec handed to `startActivation`.
865
+ * @returns the request-shaped object carrying `agentOptions`, or undefined.
866
+ */
867
+ function activationRequestOf(spec) {
868
+ if (spec === void 0 || spec === null) return void 0;
869
+ const nested = spec.request;
870
+ if (nested !== void 0 && nested !== null && typeof nested === "object") {
871
+ // Nested host. Prefer it even when `prompt` also sits at the top level
872
+ // (a spec built by copying fields around must not be re-shaped).
873
+ return nested;
874
+ }
875
+ if (spec.prompt !== void 0) return spec;
876
+ return void 0;
877
+ }
878
+
879
+ /**
880
+ * Rebuild one `startActivation` spec with an injected route, preserving the
881
+ * shape the host used.
882
+ *
883
+ * Identity is preserved whenever nothing is injected: host code compares spec
884
+ * and request identity, and a needless clone would be a silent behaviour
885
+ * change.
886
+ *
887
+ * @param spec - the original activation spec.
888
+ * @param injected - the possibly-updated request-shaped object.
889
+ * @param request - the original request-shaped object, for identity checks.
890
+ * @returns the spec to hand to the host.
891
+ */
892
+ function withActivationRequest(spec, injected, request) {
893
+ if (injected === request) return spec;
894
+ if (request === spec) {
895
+ // Flat spec: the request IS the spec, so the injected copy already
896
+ // carries provider / label / signal / delivery.
897
+ return injected;
898
+ }
899
+ return { ...spec, request: injected };
900
+ }
901
+
828
902
  function installSubagentWrapper(ctx, state) {
829
903
  // `ctx.subagents` is a per-call Cordis traceable proxy, so reach the raw
830
904
  // service object behind it for a stable handle and to install own methods.
@@ -856,13 +930,17 @@ function installSubagentWrapper(ctx, state) {
856
930
  if (spec === void 0 || spec === null) return originalStartActivation.call(raw, spec);
857
931
  // `spec.provider` names the delegation backend (`spawn` / `fork`), which
858
932
  // is what decides whether this child inherits the parent conversation.
859
- const request = applyDefaultModelFor(ctx, state, spec.request, spec.provider);
933
+ //
934
+ // The request is NOT always `spec.request`: 0.2.2-rc.2 flattened the
935
+ // spec, so on that host the fields live at the top level and
936
+ // `spec.request` is undefined. Reading the wrong one does not throw —
937
+ // it makes `applyDefaultModelFor` return early, so the child silently
938
+ // runs on the parent route. See `activationRequestOf`.
939
+ const request = activationRequestOf(spec);
940
+ const injected = applyDefaultModelFor(ctx, state, request, spec.provider);
860
941
  // Keep the spec reference when nothing was injected: host code compares
861
942
  // identity and a needless clone would be a silent behaviour change.
862
- return originalStartActivation.call(raw, request === spec.request ? spec : {
863
- ...spec,
864
- request
865
- });
943
+ return originalStartActivation.call(raw, withActivationRequest(spec, injected, request));
866
944
  }
867
945
  : void 0;
868
946
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-subagent-default-model",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "为 DeepSeek Harness 子代理配置默认模型:多模型顺序/随机分配、跨供应商连接失败故障转移,并在轨迹/对话视图显示当前供应商与模型,同时以一行真实提示词把当前路由注入子代理上下文。",
5
5
  "keywords": [
6
6
  "deepseek-harness",