dsh-subagent-default-model 2.1.0 → 2.1.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 +14 -0
- package/lib/index.js +43 -14
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.1.1 (2026-10-01)
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- **P0:首步不注入,导致 2.1.0 的注入对单步子代理完全不生效**。真实宿主实测发现:重启后派出的探针子代理报告上下文里**没有**那一行。
|
|
8
|
+
|
|
9
|
+
根因(逐行核对 `dsh-agent-loop` 后确认):每轮迭代的顺序是 `preStep()`(`lib/index.js:954`)**先于** `buildRequest()`/`agent/request`(`:1063`)。而 2.1.0 的实现只在 `agent/request` 瀑布里缓存路由、再到 `agent/pre-step` 读取它——于是**首步永远读不到缓存**(此刻第一个请求尚未构建)。单步子代理只有首步,因此注入**恒不触发**;多步子代理从第二步起才生效,这一点掩盖了缺陷(本地测试夹具同时驱动了两条瀑布,但与宿主的真实顺序相反,故未能暴露)。
|
|
10
|
+
**修复**:pre-step 侧改为「**结算后请求路由 ?? agent 自身实时路由**」。`agent.options.provider` / `.model` 正是宿主 `prepareRequest()` 复制到即将发出的请求上的那一对(`const route = { provider: this.options.provider, model: this.options.model }`),因此**首步即权威可得**;`agent/request` 缓存保留,用于让**故障转移切换后**的路由覆盖它(切换只体现在请求级结算值上)。
|
|
11
|
+
**回归护栏**:新增用例特意**不调用 `dispatchRequest`**,直接以首步 pre-step 断言必须注入——变异验证:把来源退回纯缓存方案,该用例立即失败。原「无路由不注入」用例的前提随修复改变(其 agent 本就带 `options`),已拆分为「首步必须注入」与「路由真为空时不写占位行」两项。
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- **本地夹具的瀑布顺序与宿主不一致,是上述缺陷得以漏过测试的原因**。新用例改为模拟宿主的真实顺序(单个 pre-step、无前置 request),并保留原有用例继续覆盖多步与故障转移场景。
|
|
16
|
+
|
|
3
17
|
## 2.1.0 (2026-10-01)
|
|
4
18
|
|
|
5
19
|
### Added
|
package/lib/index.js
CHANGED
|
@@ -403,6 +403,33 @@ function isRouteContextMessage(message) {
|
|
|
403
403
|
return message?.source?.kind === ROUTE_CONTEXT_SOURCE && message.source.form === ROUTE_CONTEXT_FORM;
|
|
404
404
|
}
|
|
405
405
|
|
|
406
|
+
/**
|
|
407
|
+
* Read the route an agent's loop will actually request, at PRE-STEP time.
|
|
408
|
+
*
|
|
409
|
+
* This is the loop's own resolved route (`agent.options.provider` / `.model`) —
|
|
410
|
+
* the exact pair `prepareRequest()` copies into the request it is about to
|
|
411
|
+
* build (`dsh-agent-loop`: `const route = { provider: this.options.provider,
|
|
412
|
+
* model: this.options.model }`).
|
|
413
|
+
*
|
|
414
|
+
* WHY NOT `agent/request` ALONE: the loop calls `preStep()` BEFORE
|
|
415
|
+
* `buildRequest()` on every iteration, so on the FIRST step no `agent/request`
|
|
416
|
+
* has fired yet and a request-driven cache is empty exactly when the first
|
|
417
|
+
* (often only) step needs it. That ordering is why an earlier build of this
|
|
418
|
+
* feature silently injected nothing for single-step subagents. Reading
|
|
419
|
+
* `agent.options` here is earlier and just as authoritative.
|
|
420
|
+
*
|
|
421
|
+
* @param {object} agent - the loop agent for this step.
|
|
422
|
+
* @returns {{provider: string, model: string}|undefined} the route, when known.
|
|
423
|
+
*/
|
|
424
|
+
function routeOfAgent(agent) {
|
|
425
|
+
const options = agent?.options;
|
|
426
|
+
if (options === void 0 || options === null) return void 0;
|
|
427
|
+
const provider = typeof options.provider === "string" ? options.provider : "";
|
|
428
|
+
const model = typeof options.model === "string" ? options.model : "";
|
|
429
|
+
if (provider === "" && model === "") return void 0;
|
|
430
|
+
return { provider, model };
|
|
431
|
+
}
|
|
432
|
+
|
|
406
433
|
/**
|
|
407
434
|
* Install the subagent route-context injector.
|
|
408
435
|
*
|
|
@@ -413,13 +440,13 @@ function isRouteContextMessage(message) {
|
|
|
413
440
|
* conversation. This injects one line stating the route the child is ACTUALLY
|
|
414
441
|
* using.
|
|
415
442
|
*
|
|
416
|
-
* SOURCE OF TRUTH:
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
443
|
+
* SOURCE OF TRUTH: two sources, in priority order.
|
|
444
|
+
* 1. `agent.options` at pre-step time (see `routeOfAgent`) — always available,
|
|
445
|
+
* including the very first step.
|
|
446
|
+
* 2. The SETTLED seed from the `agent/request` waterfall, once a request has
|
|
447
|
+
* been built. It reflects every listener's rewrite (including this
|
|
448
|
+
* plugin's own failover swap), so after a mid-run switch the injected line
|
|
449
|
+
* follows the new route rather than the one the agent started on.
|
|
423
450
|
*
|
|
424
451
|
* Injected on every step whose route differs from the line already present, so
|
|
425
452
|
* a failover switch or a route change is reflected immediately; an unchanged
|
|
@@ -429,12 +456,12 @@ function isRouteContextMessage(message) {
|
|
|
429
456
|
* agent's context is never touched.
|
|
430
457
|
*/
|
|
431
458
|
function installRouteContextInjector(ctx, state) {
|
|
432
|
-
/**
|
|
459
|
+
/** Settled route per agent id, captured after `agent/request` resolves. */
|
|
433
460
|
const resolvedRoute = new Map();
|
|
434
461
|
|
|
435
|
-
// Capture the
|
|
436
|
-
// observes the
|
|
437
|
-
//
|
|
462
|
+
// Capture the SETTLED route once a request has actually been built. Runs
|
|
463
|
+
// AFTER `next()` so it observes the final seed — including this plugin's own
|
|
464
|
+
// failover swap and any other plugin's rewrite.
|
|
438
465
|
const disposeRequest = ctx.on("agent/request", async (payload, next) => {
|
|
439
466
|
const seed = await next();
|
|
440
467
|
const { agent } = payload;
|
|
@@ -447,15 +474,17 @@ function installRouteContextInjector(ctx, state) {
|
|
|
447
474
|
return seed;
|
|
448
475
|
});
|
|
449
476
|
|
|
450
|
-
// Inject on the
|
|
451
|
-
//
|
|
477
|
+
// Inject on the pre-step, where the message list for the step about to run
|
|
478
|
+
// is still mutable and the agent's own route is already known.
|
|
452
479
|
const disposePreStep = ctx.on("agent/pre-step", async ({ agent, messages }, next) => {
|
|
453
480
|
const decision = await next();
|
|
454
481
|
if (decision === void 0 || decision === null || decision.kind === "reject") return decision;
|
|
455
482
|
if (state.getSection()?.injectRouteContext === false) return decision;
|
|
456
483
|
if (!isSubagentAgent(agent)) return decision;
|
|
457
484
|
|
|
458
|
-
|
|
485
|
+
// Prefer the settled request route (post-failover); fall back to the
|
|
486
|
+
// agent's own live route, which is all the first step has.
|
|
487
|
+
const route = resolvedRoute.get(agent.id) ?? routeOfAgent(agent);
|
|
459
488
|
if (route === void 0) return decision;
|
|
460
489
|
// Defensive: only the loop's live Agent exposes an inbox. A test double
|
|
461
490
|
// or a future agent shape without one must not break the step.
|
package/package.json
CHANGED