dsh-subagent-default-model 2.1.11 → 2.1.12

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/lib/client.js +117 -17
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.1.12 (2026-10-30)
4
+
5
+ ### Fixed
6
+
7
+ **issue #2:「保存」按钮永久灰着**。三条独立缺陷互相叠加,任一条都能单独锁死保存。
8
+
9
+ 1. **保存门禁包含非单调谓词**。`saveDisabled = busy || !dirty || hasIncompleteRoute`:点「添加模型」会在同一次点击里既让 `dirty=true`(启用保存)又让 `hasIncompleteRoute=true`(禁用保存),两个条件互相抵消,按钮永远不亮。并且这个谓词**无法通过 UI 满足**——模型目录为空时新行的 provider 只能是 `""`,Model 下拉又 `disabled: !route.provider`,于是 `!route.provider` 永远成立。
10
+
11
+ 改为 `busy || !(dirty || draftDiffers)`,与同作者三个插件(`trae` / `workbuddy` / `qoder`)的既有范式一致:**先把校验放在点击之后**,失败时用 `saveErrorState` 说清哪里不对。一个点不动的按钮无法告诉用户哪里错了,这正是缺陷本身。
12
+
13
+ 2. **空行被持久化成裸空串,死锁会跨重启存活**。`serializeDefaultModels` 对「provider 与首行相同且无 effort」的行只写 `route.model`,空行于是落盘为 `""`;`normalizeDefaultModels` 再把 `""` 还原成 `{ provider: <section provider>, model: "" }` —— 一个看上去可填、实际填不完的行。**只要带着空行保存过一次,下次启动就永久灰着**,用户完全不知道是自己那次保存写进去的。
14
+
15
+ 三处同时修:`save()` 丢弃全空行;`serializeDefaultModels` 自身兜底过滤;裸串优化加 `route.model` 前置条件(`{provider, model:""}` 这种「刚选好 provider 还没选模型」的行保持显式对象,不再退化成空串);`normalizeDefaultModels` 丢弃空条目,使旧版本写坏的历史文档也不会复活死锁。
16
+
17
+ 3. **空模型目录下 `addRoute()` 造出无法填完的行**。`groupsState` 为空时它写 `provider: ""`,而该值在 UI 上无法改变(provider 列表只有 `""`,model 下拉恒禁用)。改为**拒绝新增**并复用已有的 `row.catalogEmpty` 文案;目录可用时直接选中该 provider 的首个模型,让新行一出现就是合法的。
18
+
19
+ 4. **`dirty` 是纯组件内 state,卡片重挂载即丢**。卡片在离开 Plugins 页时卸载,重挂载时草稿从 scope 重新 seed,于是表单显示着用户刚才的值、`dirty` 却回到 false,保存按钮灰着且无任何解释。改为**派生**:比较草稿与已保存值(路由列表 + 三个开关),让「有没有改动」成为关于数据的事实,而不是一次被记住的交互。
20
+
21
+ ### Tests
22
+
23
+ 164/164(159 → 164),`skip 0`。新增 5 个回归用例,每条缺陷一个方向:
24
+
25
+ - 目录可用时点「添加模型」→ Save **变为可点**(旧门禁下恒为 disabled)
26
+ - 目录为空时点「添加模型」→ **不产生**路由行,并给出目录为空提示
27
+ - 全空行经保存链路 → **永不落盘为裸 `""`**
28
+ - **半填行**(选了 provider 未选 model)存在时 Save **仍可点** —— 缺陷核心的最小子集
29
+ - 未改动的重挂载 **不得**误报为有未保存改动
30
+
31
+ 变异验证(每条都确认相关用例失败后恢复):①门禁加回 `hasIncompleteRoute` → 半填用例失败;②`serializeDefaultModels` 裸串优化去掉 `route.model` 判空 → 空行落盘用例失败;③`addRoute` 恢复写 `provider: ""` → 目录为空用例失败。
32
+
3
33
  ## 2.1.11 (2026-10-30)
4
34
 
5
35
  > **发布说明**:本节的改动与下一节 2.1.10 的宿主兼容性核查**同批发布**,npm 上直接从 2.1.9 升到 2.1.11,2.1.10 没有单独发布过。保留两个条目是因为「换了宿主版本」和「改了行为」是两件独立的事,事后查证时分开更好读;`npm install` 请直接用 `2.1.11`。
package/lib/client.js CHANGED
@@ -154,13 +154,28 @@ window.__ModuleLoader__.load({
154
154
  // (see `servedNamespaceNow` in the `configForms` block).
155
155
  var SUBAGENT_MODEL_SETTINGS_NS = "dsh-subagent-default-model";
156
156
 
157
+ // Decode a stored section into the card's route list.
158
+ //
159
+ // An EMPTY entry is dropped rather than decoded (issue #2). A bare `""` in
160
+ // `models`, or an object with neither provider nor model, carries no route;
161
+ // decoding it (the old behaviour) produced `{ provider: <section provider>,
162
+ // model: "" }` — identical in the UI to a genuine half-filled row, so the
163
+ // user saw a mysterious unfillable row after a restart, with no way to tell
164
+ // it apart from their own draft. `serializeDefaultModels` no longer writes
165
+ // such entries, and this keeps a document written by an older version from
166
+ // resurrecting one.
157
167
  function normalizeDefaultModels(value) {
158
168
  var result = [];
159
169
  if (Array.isArray(value.models) && value.models.length > 0) {
160
170
  for (var i = 0; i < value.models.length; i++) {
161
171
  var entry = value.models[i];
162
- if (typeof entry === "string") result.push({ provider: value.provider || "", model: entry, reasoningEffort: "" });
163
- else if (entry && typeof entry === "object") result.push({ provider: entry.provider || value.provider || "", model: entry.model || "", reasoningEffort: entry.reasoningEffort || "" });
172
+ if (typeof entry === "string") {
173
+ if (entry === "") continue;
174
+ result.push({ provider: value.provider || "", model: entry, reasoningEffort: "" });
175
+ } else if (entry && typeof entry === "object") {
176
+ if (!entry.provider && !entry.model) continue;
177
+ result.push({ provider: entry.provider || value.provider || "", model: entry.model || "", reasoningEffort: entry.reasoningEffort || "" });
178
+ }
164
179
  }
165
180
  } else if (value.provider || value.model) {
166
181
  result.push({ provider: value.provider || "", model: value.model || "", reasoningEffort: value.reasoningEffort || "" });
@@ -169,6 +184,17 @@ window.__ModuleLoader__.load({
169
184
  }
170
185
 
171
186
  function serializeDefaultModels(previousValue, routes, strategy, failoverEnabled, injectRouteContext, applyToForkChildren) {
187
+ // Drop rows with neither a provider nor a model BEFORE anything else
188
+ // (issue #2). `save()` already filters, and this is the second line of
189
+ // defence: an all-empty row used to serialize as a bare `""` (its
190
+ // provider matched the section, so only `route.model` — the empty string
191
+ // — was written), which `normalizeDefaultModels` decoded back into
192
+ // `{ provider: <section provider>, model: "" }` — a row the UI can never
193
+ // complete, re-locking Save on the NEXT start. Filtering here makes that
194
+ // loss impossible regardless of which caller reaches this function.
195
+ routes = (routes || []).filter(function (route) {
196
+ return route && (Boolean(route.provider) || Boolean(route.model));
197
+ });
172
198
  var next = Object.assign({}, previousValue || {});
173
199
  next.failoverEnabled = failoverEnabled === false ? false : true;
174
200
  next.injectRouteContext = injectRouteContext === false ? false : true;
@@ -187,7 +213,13 @@ window.__ModuleLoader__.load({
187
213
  next.provider = provider;
188
214
  next.model = "";
189
215
  next.models = routes.map(function (route) {
190
- if (route.provider === provider && !route.reasoningEffort) {
216
+ // The bare-string (same-provider) form is an OPTIMIZATION, and it is
217
+ // only lossless when the row actually names a model. A row with a
218
+ // provider but no model yet — the normal state right after picking a
219
+ // provider — must stay an explicit object, because the bare form would
220
+ // be `""` and `normalizeDefaultModels` would read that back as a
221
+ // fillable-looking row (issue #2's persistence loop).
222
+ if (route.provider === provider && !route.reasoningEffort && route.model) {
191
223
  return route.model;
192
224
  }
193
225
  var base = { provider: route.provider, model: route.model };
@@ -391,6 +423,8 @@ window.__ModuleLoader__.load({
391
423
  var saveErrorState = React.useState(null);
392
424
  var toastState = React.useState(null);
393
425
  var toastSeq = React.useRef(0);
426
+ // `dirtyState` records "the user has interacted", but it is NOT what
427
+ // decides whether Save can be pressed — see `draftDiffers` below.
394
428
  var dirtyState = React.useState(false);
395
429
  var busyState = React.useState(false);
396
430
  React.useEffect(function () {
@@ -444,9 +478,27 @@ window.__ModuleLoader__.load({
444
478
  dirtyState[1](true);
445
479
  }
446
480
  function addRoute() {
481
+ // A new row needs a REAL provider to be fillable: the model dropdown is
482
+ // disabled until a provider is chosen, and the provider list is empty
483
+ // when the catalog never loaded. Writing `provider: ""` in that state
484
+ // produced a row the UI could not complete — and, before the gate fix in
485
+ // this release, that row locked Save shut permanently (issue #2).
486
+ //
487
+ // So: refuse the add and say why, using the catalog-empty copy the card
488
+ // already owns. Refusing is recoverable (the user retries once the
489
+ // catalog arrives); a dead row is not.
447
490
  var firstGroup = groupsState[0][0];
491
+ if (!firstGroup) {
492
+ saveErrorState[1](t("row.catalogEmpty"));
493
+ return;
494
+ }
495
+ // Pick the first model the group actually advertises, so the row is
496
+ // valid the moment it appears rather than one interaction short of
497
+ // complete. An empty model list still yields `model: ""`, which the
498
+ // save-time filter drops instead of persisting.
499
+ var firstModel = firstGroup.models && firstGroup.models[0] ? firstGroup.models[0].id : "";
448
500
  routesState[1](function (routes) {
449
- return routes.concat({ provider: firstGroup ? firstGroup.id : "", model: "", reasoningEffort: "" });
501
+ return routes.concat({ provider: firstGroup.id, model: firstModel, reasoningEffort: "" });
450
502
  });
451
503
  savedState[1](false);
452
504
  saveErrorState[1](null);
@@ -475,7 +527,23 @@ window.__ModuleLoader__.load({
475
527
  // cards do — `trae`/`workbuddy` disable on `!dirty || saving` and let the
476
528
  // write answer for itself.
477
529
  if (busyState[0]) return;
478
- var nextValue = serializeDefaultModels(value, routesState[0], strategyState[0], failoverEnabledState[0], injectRouteContextState[0], applyToForkChildrenState[0]);
530
+ // Validate HERE, not on the button (issue #2).
531
+ //
532
+ // An EMPTY row — both fields blank — is not an error: it is a row the
533
+ // user added and has not reached yet. Drop it rather than refusing the
534
+ // whole save, which also stops the empty string from being persisted
535
+ // (the round-trip loss that turned one stray row into a permanent
536
+ // `model: ""` row and re-locked Save on the next start).
537
+ //
538
+ // A HALF-filled row is still saved, not refused: only the sides the user
539
+ // actually set are meaningful, and `serializeDefaultModels` already
540
+ // handles a model-less entry. Refusing here would reproduce the very
541
+ // defect being fixed — a click that does nothing — just with a message.
542
+ var filledRoutes = routesState[0].filter(function (route) {
543
+ return Boolean(route.provider) || Boolean(route.model);
544
+ });
545
+ var nextValue = serializeDefaultModels(value, filledRoutes, strategyState[0], failoverEnabledState[0], injectRouteContextState[0], applyToForkChildrenState[0]);
546
+
479
547
  savedState[1](false);
480
548
  saveErrorState[1](null);
481
549
  busyState[1](true);
@@ -651,18 +719,50 @@ window.__ModuleLoader__.load({
651
719
  var warning = checkEffortSupport(route, groupsState[0]);
652
720
  if (warning !== null) effortWarnings.push({ index: index, key: warning.key, warning: warning });
653
721
  });
654
- // Save gate, aligned with the family cards (`trae` / `workbuddy` disable on
655
- // `!dirty || saving` plus one content rule). Two scope gates used to sit
656
- // here — `snap.status !== "ready"` and `snap.writable === false` — and they
657
- // are exactly what made Save permanently unclickable: the settings scope is
658
- // bound asynchronously from the describe mirror, so while the mirror has not
659
- // answered (or the Host never serves this namespace) both conditions stay
660
- // true forever, the button stays grey, and no message ever explains why.
661
- // The family does not pre-gate on scope state: it lets the write happen and
662
- // reports the refusal. `hasIncompleteRoute` stays, because a half-filled
663
- // route genuinely has nothing valid to save — the family's equivalent of
664
- // "no models enabled".
665
- var saveDisabled = busyState[0] || !dirtyState[0] || hasIncompleteRoute;
722
+ // Save gate: `busy || !dirty` — NOTHING else.
723
+ //
724
+ // Two scope gates used to sit here (`snap.status !== "ready"` and
725
+ // `snap.writable === false`) and made Save permanently unclickable while
726
+ // the describe mirror was still answering. `hasIncompleteRoute` was the
727
+ // third, and it produced the same class of deadlock (issue #2): the
728
+ // predicate is NON-MONOTONIC — "add a model row" sets `dirty` (enabling
729
+ // Save) and simultaneously makes `hasIncompleteRoute` true (disabling it),
730
+ // so the two conditions cancel out and the button never lights up. With an
731
+ // empty model catalog the new row's provider cannot even be filled in, so
732
+ // the deadlock is unrecoverable through the UI.
733
+ //
734
+ // The family cards (`trae` / `workbuddy` / `qoder`) never pre-gate on row
735
+ // completeness; they let the click happen and report the refusal. This does
736
+ // the same: `save()` filters empty rows and `saveErrorState` explains any
737
+ // row that is half-filled. A button that refuses to be pressed carries no
738
+ // information about WHAT is wrong — that is the whole defect.
739
+ // Whether the draft differs from what is SAVED (issue #2, defect 4).
740
+ //
741
+ // `dirty` used to be a component-local boolean that only the six input
742
+ // handlers set. The card unmounts when the user leaves the Plugins page,
743
+ // and on remount the draft is re-seeded from `savedForm` — so the form
744
+ // showed the user's values while Save stayed grey, with nothing on screen
745
+ // explaining it. Deriving "has anything changed?" from the DATA makes a
746
+ // remount unable to disagree with what is displayed.
747
+ //
748
+ // The comparison is over the normalized route list plus the three scalar
749
+ // toggles, i.e. exactly what a save would write.
750
+ var draftSignature = JSON.stringify({
751
+ routes: routesState[0].filter(function (route) { return Boolean(route.provider) || Boolean(route.model); }),
752
+ strategy: strategyState[0],
753
+ failoverEnabled: failoverEnabledState[0] !== false,
754
+ injectRouteContext: injectRouteContextState[0] !== false,
755
+ applyToForkChildren: applyToForkChildrenState[0] === true
756
+ });
757
+ var savedSignature = JSON.stringify({
758
+ routes: normalizeDefaultModels(value),
759
+ strategy: value.strategy === "random" ? "random" : "round-robin",
760
+ failoverEnabled: value.failoverEnabled !== false,
761
+ injectRouteContext: value.injectRouteContext !== false,
762
+ applyToForkChildren: value.applyToForkChildren === true
763
+ });
764
+ var draftDiffers = draftSignature !== savedSignature;
765
+ var saveDisabled = busyState[0] || !(dirtyState[0] || draftDiffers);
666
766
  var discardDisabled = !dirtyState[0] || busyState[0];
667
767
  var routes = routesState[0].map(function (route, index) {
668
768
  var group = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-subagent-default-model",
3
- "version": "2.1.11",
3
+ "version": "2.1.12",
4
4
  "description": "为 DeepSeek Harness 子代理配置默认模型:多模型顺序/随机分配、跨供应商连接失败故障转移,并在轨迹/对话视图显示当前供应商与模型,同时以一行真实提示词把当前路由注入子代理上下文。",
5
5
  "keywords": [
6
6
  "deepseek-harness",