dsh-cabinet-mode 0.5.2 → 0.5.3
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 +18 -0
- package/README.md +37 -22
- package/README.zh.md +28 -15
- package/index.js +149 -6
- package/package.json +1 -1
- package/scripts/test-model-prepared.mjs +173 -0
- package/scripts/test-model-routing.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.5.3] - 2026-11-07
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- Select Cabinet member models through the public rc.1 AgentModel API before
|
|
10
|
+
step preparation, preserving one frozen selection for tools, prompts and requests.
|
|
11
|
+
- Observe entry-scoped volatile saves without remounting; use real empty-inbox
|
|
12
|
+
regressions and refuse stale owned routes after mode changes.
|
|
13
|
+
- Persist minimal ownership with host-loaded Session plugin records and an
|
|
14
|
+
incremental projection; recover interrupted writes and preserve later native
|
|
15
|
+
choices when clearing, exiting Cabinet or unloading. Standard mode restores
|
|
16
|
+
the original reasoning effort even when its route matches the last override.
|
|
17
|
+
- Keep the legacy rc.5 model path; the shipped preset still targets rc.1.
|
|
18
|
+
Existing unmarked overrides require a one-time native selection on migration.
|
|
19
|
+
- Update bilingual compatibility guidance, website versions and download links;
|
|
20
|
+
retain 0.5.2 locale/icon exports. Add official-component regressions without
|
|
21
|
+
model calls; these do not claim full browser/team end-to-end coverage.
|
|
22
|
+
|
|
5
23
|
## [0.5.2] - 2026-11-07
|
|
6
24
|
|
|
7
25
|
### Fixed
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Cabinet Mode (内阁模式) for DeepSeek Harness
|
|
2
2
|
|
|
3
|
+
**Version compatibility (0.5.3):** Targets DSH **0.2.2-rc.1**. This patch repairs per-office model selection before the host freezes each step; 0.5.1/0.5.2 only repaired preset loading and display metadata. Verified with official host components and isolated profiles, without real model calls; see the model regression scope below. Earlier rc.3/rc.5 UI and installation results are historical evidence for earlier packages. On DSH 0.2.1-rc.3/rc.5 retain the previously verified package, including 0.5.0: the current preset omits the separate list_agents entry required on rc.5. Select the compatible version in the market.
|
|
4
|
+
|
|
3
5
|
[中文](README.zh.md) | English
|
|
4
6
|
|
|
5
7
|
**Install:** [Use the plugin market (recommended)](#install-from-the-plugin-market-recommended).
|
|
@@ -35,9 +37,7 @@ and the rest) come from the profile-level
|
|
|
35
37
|
ship them**.
|
|
36
38
|
|
|
37
39
|
This bundle declares **no hard DSH version gate**: no `engines.dsh`, no DSH
|
|
38
|
-
`peerDependencies`, no install-time version check.
|
|
39
|
-
**0.2.1-rc.3**; other DSH versions that provide the declarative preset mechanism
|
|
40
|
-
may work, but are **not verified** (see [DSH-side constraints](#dsh-side-constraints)).
|
|
40
|
+
`peerDependencies`, no install-time version check. Earlier package releases were tested on DSH **0.2.1-rc.3**; use the compatibility guidance above for 0.5.3 (see [DSH-side constraints](#dsh-side-constraints)).
|
|
41
41
|
|
|
42
42
|
## Cabinet member settings
|
|
43
43
|
|
|
@@ -59,23 +59,38 @@ failures do not erase them. If the catalog is unavailable, a manual
|
|
|
59
59
|
`provider/id` field is offered. IDs may contain +, @, spaces and further slashes;
|
|
60
60
|
only the first slash separates the provider. Invalid input blocks Save.
|
|
61
61
|
|
|
62
|
-
In **Cabinet mode**,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
62
|
+
In **Cabinet mode**, an explicit member model takes precedence; an empty teammate
|
|
63
|
+
selection follows the configured Lead model. On rc.1, a session with no configured
|
|
64
|
+
Cabinet override keeps its native selection. Clearing a previously owned override
|
|
65
|
+
restores the current **DSH deployment default** (not another session's last model).
|
|
66
|
+
A newer native manual selection is preserved when clearing or unloading the policy.
|
|
67
|
+
|
|
68
|
+
On rc.1, the plugin calls the public AgentModel.select() before step preparation;
|
|
69
|
+
the host's frozen selection supplies tools, prompt variables and the request together.
|
|
70
|
+
Saving uses the owning entry's committed loader/volatile-update notification, so
|
|
71
|
+
it applies to the next step even with an empty inbox and no remount; an already
|
|
72
|
+
prepared step keeps its selection. Unsignaled in-memory config mutations are only
|
|
73
|
+
sampled at attachment, a real status change or a claimed inbox message. Deployment
|
|
74
|
+
defaults are sampled when clearing an owned override; later default edits do not
|
|
75
|
+
silently rewrite a native selection. Actual team roles and the current preset gate the policy: a
|
|
76
|
+
teammate named lead cannot gain Lead policy. Different routes use the new adapter's
|
|
77
|
+
reasoning default; matching routes retain native effort. Exiting Cabinet restores
|
|
78
|
+
the pre-policy native selection, including its effort. Unloading cancels the active
|
|
79
|
+
managed turn and retains queued input, then restores a still-owned selection.
|
|
80
|
+
|
|
81
|
+
A host-only Session projection tracks minimal route ownership through public plugin
|
|
82
|
+
records. An intent is recorded before selection; restoration happens before ownership
|
|
83
|
+
is cleared. Interrupted writes can be recovered on reopening, without overwriting a
|
|
84
|
+
later native choice. No credentials or complete configuration are recorded. Missing
|
|
85
|
+
host record APIs reject configured overrides before a model request. Historical
|
|
86
|
+
versions did not record ownership: if an old override is already persisted, select
|
|
87
|
+
the desired native model once before enabling the new policy; its origin cannot be
|
|
88
|
+
inferred safely from a request header.
|
|
89
|
+
|
|
90
|
+
Regression scope: 120 rc.1 cases use official Cordis, Session, AgentModel, projections,
|
|
91
|
+
SystemPrompt and the unchanged preStep/prepareRequest implementations. The inbox and volatile Loader updates are real; team identity and model adapters are fixtures; there are no paid/real model calls and this
|
|
92
|
+
is not a full team/browser end-to-end test. The 41 legacy rc.5 model cases remain
|
|
93
|
+
covered, but do not certify the current rc.1 preset for older hosts.
|
|
79
94
|
|
|
80
95
|
Upload PNG/JPEG/WebP up to 2 MB; the browser crops it to a 96×96 PNG (at most
|
|
81
96
|
48 KB data URL). Saved portraits apply to Cabinet cards and native team avatars.
|
|
@@ -243,7 +258,7 @@ On failure, show the exact error. For $.format must be 1, replace the webpage so
|
|
|
243
258
|
Use this only when the market is unavailable or for local development. Fully quit desktop DSH first to release the profile lock, then install the release bundle:
|
|
244
259
|
|
|
245
260
|
```sh
|
|
246
|
-
dsh plugin --profile desktop add https://github.com/luodaoyi/dsh-cabinet-mode/releases/download/v0.5.
|
|
261
|
+
dsh plugin --profile desktop add https://github.com/luodaoyi/dsh-cabinet-mode/releases/download/v0.5.3/dsh-cabinet-mode-0.5.3.tgz
|
|
247
262
|
dsh plugin --profile desktop list
|
|
248
263
|
```
|
|
249
264
|
|
|
@@ -258,7 +273,7 @@ the same install command with the new version URL (or pick the new `.tgz` in the
|
|
|
258
273
|
plugin page), then fully quit and restart DeepSeek Harness:
|
|
259
274
|
|
|
260
275
|
```sh
|
|
261
|
-
dsh plugin --profile desktop add https://github.com/luodaoyi/dsh-cabinet-mode/releases/download/v0.5.
|
|
276
|
+
dsh plugin --profile desktop add https://github.com/luodaoyi/dsh-cabinet-mode/releases/download/v0.5.3/dsh-cabinet-mode-0.5.3.tgz
|
|
262
277
|
```
|
|
263
278
|
|
|
264
279
|
`dsh plugin --profile desktop list` should report the new version. Upgrades were
|
package/README.zh.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# 内阁模式(Cabinet Mode)· DeepSeek Harness 插件
|
|
2
2
|
|
|
3
|
+
**版本兼容(0.5.3):** 面向 DSH **0.2.2-rc.1**,在宿主固定每步模型前完成官职模型选择;0.5.1/0.5.2 仅修复了预设加载和显示元数据。已使用官方宿主组件与隔离 profile 验证,未调用真实模型;测试范围见下文。旧 rc.3/rc.5 的界面及安装记录仅适用于当时的包。DSH 0.2.1-rc.3/rc.5 用户应保留原先已验证版本(包括 0.5.0),当前预设已移除 rc.5 所需的独立 list_agents 入口;请在商店选择匹配版本。
|
|
4
|
+
|
|
3
5
|
[English](README.md) | 中文
|
|
4
6
|
|
|
5
7
|
**安装入口:** [优先从插件市场安装](#从插件市场安装索引源推荐)。
|
|
@@ -19,7 +21,7 @@
|
|
|
19
21
|
|
|
20
22
|
它声明**两行**——`preset-cabinet`(一条 `@deepseek-ai/dsh-agent-preset` 声明)与 `cabinet-ui`(载入本包 JavaScript 的 Loader 行)——并复用 DSH **标准模式**(Standard Mode)出厂的 22 行插件清单,因此工具与标准模式一致;与出厂模式的差异是 persona,并另加右栏「内阁」面板。团队工具(`spawn_teammate`、`team_task_*` 等)由 profile 层的 `@deepseek-ai/dsh-experimental-agent-team-profile` 提供,**本 preset 未内置**。
|
|
21
23
|
|
|
22
|
-
本包声明 **无 DSH 版本硬限制**:没有 `engines.dsh`、没有 DSH `peerDependencies
|
|
24
|
+
本包声明 **无 DSH 版本硬限制**:没有 `engines.dsh`、没有 DSH `peerDependencies`、安装时不做版本检查。旧包曾在 DSH **0.2.1-rc.3** 实测;0.5.3 请遵循上方版本兼容说明(见 [DSH 侧限制与说明](#dsh-侧限制与说明))。
|
|
23
25
|
|
|
24
26
|
## 内阁成员配置
|
|
25
27
|
|
|
@@ -37,18 +39,29 @@
|
|
|
37
39
|
目录不可用时提供手动 `provider/id` 输入。模型 ID 支持 +、@、空格及额外斜杠,
|
|
38
40
|
仅第一个斜杠分隔提供方;格式错误会阻止保存。
|
|
39
41
|
|
|
40
|
-
仅在 **内阁模式**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
仅在 **内阁模式** 中,成员显式模型优先,阁臣留空时跟随已配置的首辅模型。
|
|
43
|
+
rc.1 中从未配置内阁覆盖的会话保留原生选择;清空原先受管的覆盖时恢复当前
|
|
44
|
+
**DSH 部署默认模型**,不继承其他会话最后使用的模型。清空或卸载时保留后来
|
|
45
|
+
由用户手动设置的原生选择。
|
|
46
|
+
|
|
47
|
+
rc.1 路径在步骤准备前调用公开 AgentModel.select(),工具、提示变量和请求均使用
|
|
48
|
+
宿主固定的同一模型。保存通过仅属于本插件的 loader/volatile-update 通知同步模型,即使 inbox 为空且
|
|
49
|
+
没有重挂载也影响下一步;已经准备的步骤保持原选择。没有发送通知的内存配置修改
|
|
50
|
+
仅在挂载、真实状态变化或领取 inbox 消息时重新读取。部署默认模型在清空受管覆盖
|
|
51
|
+
时读取,后续修改部署默认不会静默改写已有原生选择。实时 preset 和真实团队角色限定范围,名为 lead 的阁臣不会获得首辅策略。
|
|
52
|
+
换路由使用新适配器的 reasoning 默认值,同路由保留原生 effort。退出内阁恢复
|
|
53
|
+
接管前的原生模型及 effort;卸载中止受管轮次、保留排队输入并恢复仍归插件所有的选择。
|
|
54
|
+
|
|
55
|
+
公开 Session 插件记录和宿主 projection 仅记录路由归属,不记录凭据或完整配置。
|
|
56
|
+
先记录覆盖意图再选择模型;先恢复原生选择再清除归属。两次写入之间中断后可在
|
|
57
|
+
重开时恢复,且不覆盖后来的原生手动选择。缺失宿主记录 API 时,显式覆盖会在模型
|
|
58
|
+
请求前报错。旧版本没有归属记录,不能仅凭历史请求头安全推断来源;若旧覆盖已
|
|
59
|
+
持久化,请先用原生模型选择器选回所需模型,再启用新策略。
|
|
60
|
+
|
|
61
|
+
回归范围:120 项 rc.1 测试使用官方 Cordis、Session、AgentModel、projection、
|
|
62
|
+
SystemPrompt 及未改动的 preStep/prepareRequest 实现;inbox 和 Loader volatile 更新使用真实实现,身份和模型适配器为
|
|
63
|
+
测试替身,未调用真实模型,也不是完整团队或浏览器端到端测试。保留旧 rc.5 的
|
|
64
|
+
41 项模型组合回归,但这不代表当前 rc.1 预设已通过旧宿主验收。
|
|
52
65
|
|
|
53
66
|
可上传不超过 2 MB 的 PNG/JPEG/WebP;浏览器居中裁成 96×96 PNG,data URL 不超过
|
|
54
67
|
48 KB。保存后头像同时用于内阁面板和原生团队列表。**恢复默认** 将该官职组的
|
|
@@ -176,7 +189,7 @@ https://raw.githubusercontent.com/luodaoyi/dsh-cabinet-mode/market-index/marketp
|
|
|
176
189
|
仅在商店不可用或本地开发时使用。先完全退出桌面 DSH,释放 profile 锁,再执行:
|
|
177
190
|
|
|
178
191
|
```sh
|
|
179
|
-
dsh plugin --profile desktop add https://github.com/luodaoyi/dsh-cabinet-mode/releases/download/v0.5.
|
|
192
|
+
dsh plugin --profile desktop add https://github.com/luodaoyi/dsh-cabinet-mode/releases/download/v0.5.3/dsh-cabinet-mode-0.5.3.tgz
|
|
180
193
|
dsh plugin --profile desktop list
|
|
181
194
|
```
|
|
182
195
|
|
|
@@ -187,7 +200,7 @@ dsh plugin --profile desktop list
|
|
|
187
200
|
若通过插件市场安装:刷新市场,先在**已安装**页卸载旧版本,再从**插件市场**安装新版本,然后重启——没有 tgz URL 要换,也没有一键更新。否则用同一条安装命令换新版本 URL(或在插件页选新 `.tgz`),然后完全退出并重启 DeepSeek Harness:
|
|
188
201
|
|
|
189
202
|
```sh
|
|
190
|
-
dsh plugin --profile desktop add https://github.com/luodaoyi/dsh-cabinet-mode/releases/download/v0.5.
|
|
203
|
+
dsh plugin --profile desktop add https://github.com/luodaoyi/dsh-cabinet-mode/releases/download/v0.5.3/dsh-cabinet-mode-0.5.3.tgz
|
|
191
204
|
```
|
|
192
205
|
|
|
193
206
|
`dsh plugin --profile desktop list` 应显示新版本。升级已在 Windows 实测:
|
package/index.js
CHANGED
|
@@ -285,9 +285,12 @@ function memberKeyOf(ctx, agent) {
|
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
/** Couple one live Cabinet route to one AgentLoop turn signal. */
|
|
288
|
-
function attachMemberModel(ctx, config, agent, attached, routeMemory = new Map()) {
|
|
288
|
+
function attachMemberModel(ctx, config, agent, attached, routeMemory = new Map(), sessionApi) {
|
|
289
289
|
if (!agent || typeof agent.ctx?.on !== 'function') return undefined;
|
|
290
290
|
if (agent.id !== undefined && attached.has(agent.id)) return undefined;
|
|
291
|
+
if (typeof agent.model?.current === 'function' && typeof agent.model?.select === 'function') {
|
|
292
|
+
return attachPreparedMemberModel(ctx, config, agent, attached, routeMemory, sessionApi);
|
|
293
|
+
}
|
|
291
294
|
let active = true;
|
|
292
295
|
let controlledSignal;
|
|
293
296
|
const turns = new WeakMap();
|
|
@@ -382,13 +385,153 @@ function attachMemberModel(ctx, config, agent, attached, routeMemory = new Map()
|
|
|
382
385
|
return dispose;
|
|
383
386
|
}
|
|
384
387
|
|
|
388
|
+
// Use the host's module instance and incremental projection contract. Records
|
|
389
|
+
// contain only selection provenance, never provider credentials or user config.
|
|
390
|
+
async function prepareModelSessionApi(ctx) {
|
|
391
|
+
const loader = ctx.get('loader'), registry = ctx.get('sessionProjections');
|
|
392
|
+
if (!loader?.import || !registry?.register) return undefined;
|
|
393
|
+
const api = await loader.import('@deepseek-ai/dsh-session');
|
|
394
|
+
const { z } = await loader.import('zod');
|
|
395
|
+
const route = z.object({ provider: z.string().min(1), model: z.string().min(1), reasoningEffort: z.string().optional() });
|
|
396
|
+
const record = z.object({ agentId: z.string(), baseline: route, override: route, from: route, settled: z.boolean().default(false) });
|
|
397
|
+
const equal = (a, b) => a?.provider === b?.provider && a?.model === b?.model && a?.reasoningEffort === b?.reasoningEffort;
|
|
398
|
+
const ownership = await registry.register({
|
|
399
|
+
key: 'cabinetModelOwnership', stateVersion: 1,
|
|
400
|
+
stateSchema: z.object({ inheritedCount: z.number(), record: record.nullable() }),
|
|
401
|
+
init: (_, inheritedCount = 0) => ({ inheritedCount, record: null }),
|
|
402
|
+
apply: (state, event) => {
|
|
403
|
+
if (event.seq < state.inheritedCount) return state;
|
|
404
|
+
const item = api.pluginRecordOf(event);
|
|
405
|
+
if (item?.type === 'plugin:dsh-cabinet-mode/model-policy') {
|
|
406
|
+
const parsed = record.safeParse(item.data);
|
|
407
|
+
return { ...state, record: parsed.success ? parsed.data : null };
|
|
408
|
+
}
|
|
409
|
+
if (event.type === 'model/selection' && state.record) return {
|
|
410
|
+
...state, record: equal(event.data, state.record.override) ? { ...state.record, settled: true } : null
|
|
411
|
+
};
|
|
412
|
+
return state;
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
return { ...api, ownership };
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** Host plugin entry. */
|
|
419
|
+
function attachPreparedMemberModel(ctx, config, agent, attached, routeMemory, sessionApi) {
|
|
420
|
+
let active = true;
|
|
421
|
+
let synchronizedKey;
|
|
422
|
+
const sameRoute = (a, b) => !!a && !!b && a.provider === b.provider && a.model === b.model;
|
|
423
|
+
const sameSelection = (a, b) => sameRoute(a, b) && a.reasoningEffort === b.reasoningEffort;
|
|
424
|
+
const recordType = 'plugin:dsh-cabinet-mode/model-policy';
|
|
425
|
+
const validRoute = value => value && typeof value.provider === 'string' && value.provider.length > 0 && typeof value.model === 'string' && value.model.length > 0 && (value.reasoningEffort === undefined || typeof value.reasoningEffort === 'string');
|
|
426
|
+
const canRecord = typeof sessionApi?.appendPluginRecord === 'function' && typeof sessionApi?.pluginRecordOf === 'function' && typeof sessionApi?.Session === 'function' && agent.session instanceof sessionApi.Session && !!sessionApi.ownership;
|
|
427
|
+
const refreshOwnership = () => {
|
|
428
|
+
const record = canRecord ? sessionApi.ownership.stateOf(agent.session).record : undefined;
|
|
429
|
+
const current = agent.model.current();
|
|
430
|
+
if (record?.agentId === agent.id && (sameSelection(current, record.override) || (!record.settled && sameSelection(current, record.from) && !sameSelection(record.from, record.baseline)))) {
|
|
431
|
+
routeMemory.set(agent.id, { baseline: record.baseline, override: current });
|
|
432
|
+
} else routeMemory.delete(agent.id);
|
|
433
|
+
};
|
|
434
|
+
const remember = value => {
|
|
435
|
+
if (!canRecord) throw new Error('Cabinet: host Session plugin-record API unavailable; model override refused');
|
|
436
|
+
sessionApi.appendPluginRecord(agent.session, recordType, value ? { agentId: agent.id, ...value, from: agent.model.current() } : { agentId: agent.id });
|
|
437
|
+
if (value) routeMemory.set(agent.id, value); else routeMemory.delete(agent.id);
|
|
438
|
+
};
|
|
439
|
+
const keyFor = () => { try { return memberKeyOf(ctx, agent); } catch { return undefined; } };
|
|
440
|
+
const syncSelection = () => {
|
|
441
|
+
if (!active) return;
|
|
442
|
+
refreshOwnership();
|
|
443
|
+
const key = keyFor();
|
|
444
|
+
synchronizedKey = key;
|
|
445
|
+
const current = agent.model.current();
|
|
446
|
+
const previous = routeMemory.get(agent.id);
|
|
447
|
+
const override = key === undefined ? undefined : memberModel(config, key) ?? (key === 'lead' ? undefined : memberModel(config, 'lead'));
|
|
448
|
+
if (!override && !previous) return; // Never alter an unconfigured/native agent.
|
|
449
|
+
if (!override && previous && !sameSelection(current, previous.override)) {
|
|
450
|
+
remember(undefined); return; // Respect a newer native selection.
|
|
451
|
+
}
|
|
452
|
+
const defaults = ctx.get('agentDefaultModel')?.currentSelection?.() ?? agent.options;
|
|
453
|
+
const desired = override ?? (key === undefined ? previous?.baseline : defaults);
|
|
454
|
+
if (!desired?.provider || !desired?.model) throw new Error('Cabinet: no model available to restore native selection');
|
|
455
|
+
const selection = (override || key !== undefined) && sameRoute(desired, current) ? current : {
|
|
456
|
+
provider: desired.provider, model: desired.model,
|
|
457
|
+
...(desired.reasoningEffort === undefined ? {} : { reasoningEffort: desired.reasoningEffort })
|
|
458
|
+
};
|
|
459
|
+
if (override) {
|
|
460
|
+
const value = { baseline: previous && sameSelection(current, previous.override) ? previous.baseline : current, override: selection };
|
|
461
|
+
if (!validRoute(value.baseline)) throw new Error('Cabinet: no native selection available to restore');
|
|
462
|
+
if (JSON.stringify(value) !== JSON.stringify(previous)) remember(value);
|
|
463
|
+
}
|
|
464
|
+
agent.model.select(selection);
|
|
465
|
+
// Clear ownership only after restoration is durable. Reopening between
|
|
466
|
+
// these writes sees the native selection and retires the stale marker.
|
|
467
|
+
if (!override) remember(undefined);
|
|
468
|
+
};
|
|
469
|
+
// Both notifications precede preStep's model.current(): status starts the
|
|
470
|
+
// turn, and inbox claim resolves members registered after agent creation.
|
|
471
|
+
let syncError;
|
|
472
|
+
const sync = () => {
|
|
473
|
+
try { syncSelection(); syncError = undefined; }
|
|
474
|
+
catch (error) { syncError = error; }
|
|
475
|
+
};
|
|
476
|
+
const offStatus = agent.ctx.on('agent/status', sync);
|
|
477
|
+
const offClaim = agent.ctx.on('agent/inbox/claimed', sync);
|
|
478
|
+
// Loader dispatches committed volatile paths only to the owning plugin fiber.
|
|
479
|
+
// Register on this entry's context, not the unrelated Agent scope.
|
|
480
|
+
const offConfig = ctx.on('loader/volatile-update', paths => {
|
|
481
|
+
if (paths.some(path => path[0] === 'members')) sync();
|
|
482
|
+
});
|
|
483
|
+
// Defer errors to preparation too: a failed capability check must never
|
|
484
|
+
// silently send a configured override to the native model.
|
|
485
|
+
sync();
|
|
486
|
+
const turns = new WeakMap();
|
|
487
|
+
let controlledSignal;
|
|
488
|
+
const offAssembly = agent.ctx.on('system-prompt/assemble', async (_, context, next) => {
|
|
489
|
+
if (syncError) throw syncError;
|
|
490
|
+
const key = keyFor();
|
|
491
|
+
// An empty inbox emits no notification. Refuse a stale owned selection
|
|
492
|
+
// after a mode/role change even before the next status boundary can restore it.
|
|
493
|
+
refreshOwnership();
|
|
494
|
+
const configured = key === undefined ? undefined : memberModel(config, key) ?? (key === 'lead' ? undefined : memberModel(config, 'lead'));
|
|
495
|
+
if ((routeMemory.has(agent.id) || configured) && key !== synchronizedKey) throw new Error('Cabinet: model policy changed before step preparation; start a new turn');
|
|
496
|
+
const controlled = key !== undefined && routeMemory.has(agent.id);
|
|
497
|
+
const state = { key, controlled };
|
|
498
|
+
if (context.signal) {
|
|
499
|
+
turns.set(context.signal, state);
|
|
500
|
+
if (controlled) controlledSignal = context.signal;
|
|
501
|
+
}
|
|
502
|
+
const result = await next();
|
|
503
|
+
if (controlled && (!active || context.signal?.aborted || keyFor() !== key)) throw new Error('Cabinet: model policy changed during step preparation');
|
|
504
|
+
return result; // The official frozen modelSelection owns all variables.
|
|
505
|
+
}, { prepend: true });
|
|
506
|
+
const offRequest = agent.ctx.on('agent/request', async (payload, next) => {
|
|
507
|
+
const state = turns.get(payload.signal);
|
|
508
|
+
const result = await next();
|
|
509
|
+
if (state?.controlled && (!active || payload.signal.aborted || keyFor() !== state.key)) throw new Error('Cabinet: model policy changed before request');
|
|
510
|
+
return result; // Never change the prepared route or effort.
|
|
511
|
+
}, { prepend: true });
|
|
512
|
+
const dispose = () => {
|
|
513
|
+
active = false;
|
|
514
|
+
if (controlledSignal && !controlledSignal.aborted) agent.cancel?.({ kind: 'hook', reason: 'Cabinet model policy unloaded' }, { keepInbox: true });
|
|
515
|
+
offStatus(); offClaim(); offConfig(); offAssembly(); offRequest();
|
|
516
|
+
refreshOwnership();
|
|
517
|
+
const previous = routeMemory.get(agent.id);
|
|
518
|
+
if (previous?.baseline && sameSelection(agent.model.current(), previous.override)) agent.model.select(previous.baseline);
|
|
519
|
+
if (previous && canRecord) remember(undefined);
|
|
520
|
+
};
|
|
521
|
+
if (agent.id !== undefined) attached.set(agent.id, dispose);
|
|
522
|
+
return dispose;
|
|
523
|
+
}
|
|
524
|
+
|
|
385
525
|
/** Host plugin entry. */
|
|
386
526
|
const name = 'cabinet-ui';
|
|
387
|
-
/**
|
|
388
|
-
const inject = ['systemPrompt'];
|
|
527
|
+
/** Host services needed for prompt sections and durable model ownership. */
|
|
528
|
+
const inject = ['systemPrompt', 'loader', 'sessionProjections'];
|
|
389
529
|
|
|
390
530
|
/** Register the runtime member block as a prompt section. */
|
|
391
|
-
function apply(ctx, config) {
|
|
531
|
+
async function apply(ctx, config) {
|
|
532
|
+
let sessionApi;
|
|
533
|
+
try { sessionApi = await prepareModelSessionApi(ctx); }
|
|
534
|
+
catch { /* Legacy hosts need no records; rc.1 overrides fail closed below. */ }
|
|
392
535
|
ctx.effect(() => ctx.systemPrompt.section({
|
|
393
536
|
name: MEMBER_SECTION,
|
|
394
537
|
order: ctx.systemPrompt.getSectionOrder('DEPLOYMENT_PERSONA_PREFIX') + 1,
|
|
@@ -407,7 +550,7 @@ function apply(ctx, config) {
|
|
|
407
550
|
const routeMemory = new Map();
|
|
408
551
|
const attach = (agent) => {
|
|
409
552
|
try {
|
|
410
|
-
attachMemberModel(ctx, config, agent, attached, routeMemory);
|
|
553
|
+
attachMemberModel(ctx, config, agent, attached, routeMemory, sessionApi);
|
|
411
554
|
} catch (error) {
|
|
412
555
|
try { ctx.logger?.warn?.(`cabinet-ui: model selection attach failed: ${String(error)}`); } catch { /* logger unavailable */ }
|
|
413
556
|
}
|
|
@@ -433,4 +576,4 @@ function apply(ctx, config) {
|
|
|
433
576
|
}, 'cabinet-member: model selection');
|
|
434
577
|
}
|
|
435
578
|
|
|
436
|
-
export { bureauOf, sectionText, memberBlock, memberModel, modelRoute, clampModel, attachMemberModel, Config, DEFAULT_LEAD_PROMPT, DEFAULT_MEMBER_PROMPTS, MEMBER_KEYS, MEMBER_LABELS, MEMBER_SECTION, MAX_AVATAR_LENGTH, MAX_MODEL_LENGTH, MAX_NAME_LENGTH, MAX_PROMPT_LENGTH, apply, inject, name };
|
|
579
|
+
export { prepareModelSessionApi, bureauOf, sectionText, memberBlock, memberModel, modelRoute, clampModel, attachMemberModel, Config, DEFAULT_LEAD_PROMPT, DEFAULT_MEMBER_PROMPTS, MEMBER_KEYS, MEMBER_LABELS, MEMBER_SECTION, MAX_AVATAR_LENGTH, MAX_MODEL_LENGTH, MAX_NAME_LENGTH, MAX_PROMPT_LENGTH, apply, inject, name };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cabinet-mode",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "Cabinet Mode (内阁模式) for DeepSeek Harness: a declarative DSH bundle that adds a dual-identity Lead/teammate agent preset for the Great Ming Research Bureau cabinet team.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"icon": "./icon.svg",
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {pathToFileURL} from 'node:url';
|
|
5
|
+
import {randomUUID} from 'node:crypto';
|
|
6
|
+
import {attachMemberModel,prepareModelSessionApi,apply,inject} from '../index.js';
|
|
7
|
+
const base=path.join(process.env.DSH_MODULE_ROOT,'@deepseek-ai');
|
|
8
|
+
const load=name=>import(pathToFileURL(path.join(base,name,'lib/index.js')));
|
|
9
|
+
const {Context}=await load('cordis'),{SystemPrompt}=await load('dsh-system-prompt');
|
|
10
|
+
const {createScope}=await load('dsh-scope');
|
|
11
|
+
const {AgentModel,agentEvents,installModelSelection,modelSelectionProjectionDefinition}=await load('dsh-agent');
|
|
12
|
+
const {Loader}=await load('cordis-plugin-loader');
|
|
13
|
+
const loaderCtx=new Context();loaderCtx.baseUrl=pathToFileURL(path.join(process.env.DSH_MODULE_ROOT,'../cordis.yml')).href;new Loader(loaderCtx);
|
|
14
|
+
const {SessionProjectionRegistry}=await load('dsh-session-projection');new SessionProjectionRegistry(loaderCtx);
|
|
15
|
+
const sessionApi=await prepareModelSessionApi(loaderCtx);
|
|
16
|
+
assert.equal(sessionApi.Session,(await load('dsh-session')).Session);
|
|
17
|
+
// Expose the official implementation without changing any method or guard.
|
|
18
|
+
// This additional module lives only in the isolated test runtime and is removed.
|
|
19
|
+
const loopPath=path.join(base,'dsh-agent-loop/lib/index.js');
|
|
20
|
+
const exposed=path.join(path.dirname(loopPath),'cabinet-test-'+randomUUID()+'.mjs');
|
|
21
|
+
fs.writeFileSync(exposed,fs.readFileSync(loopPath,'utf8')+'\nexport { ReactLoopAgent, ReactLoopInbox, inboxProjectionDefinition };\n');
|
|
22
|
+
let Loop,Inbox,inboxProjection;try{const official=await import(pathToFileURL(exposed));Loop=official.ReactLoopAgent;Inbox=official.ReactLoopInbox;inboxProjection=official.inboxProjectionDefinition;}finally{fs.unlinkSync(exposed);}
|
|
23
|
+
// Mount the exported declaration through real Cordis; direct apply() tests cannot
|
|
24
|
+
// detect an invalid injection schema that silently leaves the entry pending.
|
|
25
|
+
new SystemPrompt(loaderCtx,{});let mounted=false;
|
|
26
|
+
const entry=loaderCtx.plugin({name:'cabinet-test-entry',inject,apply:async(ctx,cfg)=>{await apply(ctx,cfg);mounted=true;}},{members:[]});
|
|
27
|
+
await entry;assert.ok(mounted,'Cabinet entry activates through actual Cordis inject');
|
|
28
|
+
let passed=1;
|
|
29
|
+
for(const role of ['lead','teammate']){
|
|
30
|
+
const ctx=new Context();new SystemPrompt(ctx,{});
|
|
31
|
+
// The two variable providers registered by the official AgentLoop constructor.
|
|
32
|
+
ctx.systemPrompt.variable('provider',context=>context.modelSelection?.provider ?? context.agent?.options.provider);
|
|
33
|
+
ctx.systemPrompt.variable('model',context=>context.modelSelection?.model ?? context.agent?.options.model);
|
|
34
|
+
let preset='cabinet',member={role,name:role==='lead'?'lead':'hanlin'},defaults={provider:'default',model:'model'};
|
|
35
|
+
ctx.provide('agentPresets',{composedPreset:()=>preset});ctx.provide('agentTeams',{tryMembership:()=>member});ctx.provide('agentDefaultModel',{currentSelection:()=>defaults});
|
|
36
|
+
let header={config:{provider:'native',model:'initial',reasoningEffort:'high'}},calls=0,toolSelection;
|
|
37
|
+
const agent={id:role,options:{...header.config},requestHeaderLogged:true,phase:{kind:'idle'}};
|
|
38
|
+
Object.defineProperty(agent,'status',Object.getOwnPropertyDescriptor(Loop.prototype,'status'));
|
|
39
|
+
const scope=createScope(ctx,agent);agent.ctx=scope.ctx;agent.dispatch=agentEvents(ctx,agent);
|
|
40
|
+
function reopen(seed){agent.session=sessionApi.Session.create(role,seed);if(!seed)agent.session.append('request/header',{header,reason:'initial'});agent.model=new AgentModel(()=>agent.session.snapshotEvents().reduce(modelSelectionProjectionDefinition.apply,modelSelectionProjectionDefinition.init()),agent.session,agent.options);agent.inbox=new Inbox(()=>agent.session.snapshotEvents().reduce(inboxProjection.apply,inboxProjection.init()),agent.session,agent.dispatch);}
|
|
41
|
+
reopen();assert.ok(agent.session instanceof sessionApi.Session);
|
|
42
|
+
agent.loopCtx={systemPrompt:ctx.systemPrompt,tools:{resolve:async({modelSelection})=>{toolSelection=modelSelection;return{dispose(){},tools:[]}}},llm:{prepareCall:async(config)=>{calls++;return{config}}}};
|
|
43
|
+
agent.runtimeContext={project:()=>undefined};
|
|
44
|
+
const cfg={members:[{key:role==='lead'?'lead':'hanlin',model:'p/override'}]};
|
|
45
|
+
installModelSelection(agent.ctx);
|
|
46
|
+
const memory=new Map(),off=attachMemberModel(ctx,cfg,agent,new Map(),memory,sessionApi);
|
|
47
|
+
const cancellations=[];agent.cancel=(cause,options)=>{cancellations.push({cause,options});agent.phase?.abort.abort(cause)};
|
|
48
|
+
async function step(expected,newTurn=true){if(newTurn){Loop.prototype.setPhase.call(agent,{kind:'idle'});Loop.prototype.setPhase.call(agent,{kind:'running',abort:new AbortController()});}const d=await Loop.prototype.preStep.call(agent,'next-turn',{turn:1,step:1});assert.equal(d.kind,'enter');const request=await Loop.prototype.prepareRequest.call(agent,1,1,d.selection,agent.phase.abort.signal);assert.deepEqual(request.config,expected);assert.deepEqual(toolSelection,d.selection);assert.equal(d.assembly.variables.provider,expected.provider);assert.equal(d.assembly.variables.model,expected.model);passed++;return d;}
|
|
49
|
+
await step({provider:'p',model:'override'});
|
|
50
|
+
cfg.members=[];await step(defaults);
|
|
51
|
+
cfg.members=[{key:role==='lead'?'lead':'hanlin',model:'native/initial'}];await step({provider:'native',model:'initial'});
|
|
52
|
+
agent.model.select({...agent.model.current(),reasoningEffort:'high'});await step({provider:'native',model:'initial',reasoningEffort:'high'});
|
|
53
|
+
cfg.members=[{key:'lead',model:'p/lead'}];await step({provider:'p',model:'lead'});
|
|
54
|
+
preset='standard';await step(header.config);
|
|
55
|
+
if(role==='teammate'){preset='cabinet';member={role:'teammate',name:'lead'};await step(header.config);member={role:'teammate',name:'hanlin'};}
|
|
56
|
+
preset='cabinet';await step({provider:'p',model:'lead'});
|
|
57
|
+
// A real prepared step retains its own route across later configuration changes.
|
|
58
|
+
agent.phase={kind:'running',abort:new AbortController()};
|
|
59
|
+
const a=await Loop.prototype.preStep.call(agent,'next-turn',{turn:2,step:1});
|
|
60
|
+
const aSignal=agent.phase.abort.signal;
|
|
61
|
+
cfg.members=[{key:'lead',model:'p/next'}];agent.dispatch.emit('agent/status',{status:'running'});
|
|
62
|
+
const b=await Loop.prototype.preStep.call(agent,'next-turn',{turn:2,step:2});
|
|
63
|
+
assert.equal((await Loop.prototype.prepareRequest.call(agent,2,1,a.selection,aSignal)).config.model,'lead');
|
|
64
|
+
assert.equal((await Loop.prototype.prepareRequest.call(agent,2,2,b.selection,aSignal)).config.model,'next');passed++;
|
|
65
|
+
// Signal-free preview cannot change either prepared selection or unload tracking.
|
|
66
|
+
await ctx.systemPrompt.assemble({agent,scope:agent});
|
|
67
|
+
assert.equal(agent.model.current().model,'next');passed++;
|
|
68
|
+
preset='standard';await assert.rejects(Loop.prototype.prepareRequest.call(agent,2,2,b.selection,aSignal),/policy changed/);passed++;
|
|
69
|
+
preset='cabinet';
|
|
70
|
+
off();assert.deepEqual(agent.model.current(),header.config);passed++;
|
|
71
|
+
assert.equal(cancellations.length,1);assert.equal(cancellations[0].options.keepInbox,true);assert.ok(aSignal.aborted);passed++;
|
|
72
|
+
// Native mode with configured Cabinet overrides remains entirely untouched.
|
|
73
|
+
preset='standard';reopen();
|
|
74
|
+
const offNative=attachMemberModel(ctx,cfg,agent,new Map(),new Map(),sessionApi);
|
|
75
|
+
await step(header.config);offNative();passed++;
|
|
76
|
+
// Actual teammate role, not a lead-like name, controls access to Lead policy.
|
|
77
|
+
preset='cabinet';member={role:'teammate',name:'lead'};reopen();
|
|
78
|
+
const offImpostor=attachMemberModel(ctx,cfg,agent,new Map(),new Map(),sessionApi);await step(header.config);offImpostor();passed++;
|
|
79
|
+
// Created before membership: the first running notification selects before preStep.
|
|
80
|
+
member=undefined;const offLate=attachMemberModel(ctx,cfg,agent,new Map(),new Map(),sessionApi);
|
|
81
|
+
member={role:'lead',name:'lead'};agent.dispatch.emit('agent/status',{status:'running'});await step({provider:'p',model:'next'});passed++;
|
|
82
|
+
const disk=path.join(path.dirname(exposed),'cabinet-session-'+randomUUID()+'.json');
|
|
83
|
+
fs.writeFileSync(disk,JSON.stringify(agent.session.snapshotEvents()));offLate();
|
|
84
|
+
const crashLog=JSON.parse(fs.readFileSync(disk,'utf8'));fs.unlinkSync(disk);reopen(crashLog);cfg.members=[];
|
|
85
|
+
const offRestored=attachMemberModel(ctx,cfg,agent,new Map(),new Map(),sessionApi);await step(defaults);offRestored();passed++;
|
|
86
|
+
|
|
87
|
+
// Recover real Session logs across each side of the two-write transaction.
|
|
88
|
+
const native={...header.config};member={role:'lead',name:'lead'};preset='cabinet';
|
|
89
|
+
const persist=()=>{const file=path.join(path.dirname(exposed),'cabinet-crash-'+randomUUID()+'.json');fs.writeFileSync(file,JSON.stringify(agent.session.snapshotEvents()));const result=JSON.parse(fs.readFileSync(file,'utf8'));fs.unlinkSync(file);return result;};
|
|
90
|
+
const attach=(api=sessionApi)=>attachMemberModel(ctx,cfg,agent,new Map(),new Map(),api);
|
|
91
|
+
const notify=()=>agent.dispatch.emit('agent/status',{status:'running'});
|
|
92
|
+
// Initial intent durable, selection failed: a never-applied policy must not claim native state.
|
|
93
|
+
reopen();cfg.members=[{key:'lead',model:'p/first'}];
|
|
94
|
+
let select=agent.model.select.bind(agent.model);agent.model.select=()=>{throw Error('injected select failure')};
|
|
95
|
+
let cleanup=attach();await assert.rejects(step({}),/injected select failure/);passed++;
|
|
96
|
+
let seed=persist();agent.model.select=select;cleanup();reopen(seed);cfg.members=[];cleanup=attach();await step(native);cleanup();
|
|
97
|
+
// Changing an owned override: failure after new intent must retain the old override's provenance.
|
|
98
|
+
reopen();cfg.members=[{key:'lead',model:'p/first'}];cleanup=attach();await step({provider:'p',model:'first'});
|
|
99
|
+
select=agent.model.select.bind(agent.model);agent.model.select=()=>{throw Error('between intent and select')};
|
|
100
|
+
cfg.members=[{key:'lead',model:'p/second'}];notify();await assert.rejects(step({}),/between intent and select/);passed++;
|
|
101
|
+
seed=persist();agent.model.select=select;cleanup();reopen(seed);cfg.members=[];cleanup=attach();await step(defaults);cleanup();
|
|
102
|
+
// Restoration succeeds, clearing ownership fails: replay must keep the restored native choice.
|
|
103
|
+
reopen();cfg.members=[{key:'lead',model:'p/first'}];let failClear=false;
|
|
104
|
+
const interruptedApi={...sessionApi,appendPluginRecord:(session,type,data)=>{if(failClear&&!data.baseline)throw Error('between restore and clear');return sessionApi.appendPluginRecord(session,type,data);}};
|
|
105
|
+
cleanup=attach(interruptedApi);await step({provider:'p',model:'first'});cfg.members=[];failClear=true;notify();
|
|
106
|
+
assert.deepEqual(agent.model.current(),defaults);await assert.rejects(ctx.systemPrompt.assemble({agent,scope:agent}),/between restore and clear/);passed++;
|
|
107
|
+
seed=persist();failClear=false;cleanup();reopen(seed);cleanup=attach();await step(defaults);cleanup();
|
|
108
|
+
// A manual native change, even away and back to the same override, revokes ownership.
|
|
109
|
+
for(const action of ['clear','unload','restart','standard']){
|
|
110
|
+
reopen();cfg.members=[{key:'lead',model:'p/first'}];cleanup=attach();await step({provider:'p',model:'first'});
|
|
111
|
+
agent.model.select({provider:'manual',model:'other',reasoningEffort:'low'});agent.model.select({provider:'p',model:'first'});
|
|
112
|
+
if(action==='restart'){seed=persist();cleanup();reopen(seed);cfg.members=[];cleanup=attach();}
|
|
113
|
+
else if(action==='unload'){cleanup();cleanup=()=>{};}
|
|
114
|
+
else if(action==='standard')preset='standard';else cfg.members=[];
|
|
115
|
+
assert.deepEqual(agent.model.current(),{provider:'p',model:'first'});
|
|
116
|
+
if(action!=='unload')await step({provider:'p',model:'first'});else passed++;
|
|
117
|
+
cleanup();preset='cabinet';
|
|
118
|
+
}
|
|
119
|
+
// Restoring Standard reinstates baseline effort even if its route equals the latest override.
|
|
120
|
+
reopen();cfg.members=[{key:'lead',model:'p/first'}];cleanup=attach();await step({provider:'p',model:'first'});
|
|
121
|
+
cfg.members=[{key:'lead',model:'native/initial'}];await step({provider:'native',model:'initial'});
|
|
122
|
+
preset='standard';await step(native);cleanup();preset='cabinet';
|
|
123
|
+
// Empty real inbox: neither claim nor running-to-running publishes a new boundary.
|
|
124
|
+
reopen();cfg.members=[{key:'lead',model:'p/first'}];cleanup=attach();await step({provider:'p',model:'first'});
|
|
125
|
+
cfg.members=[{key:'lead',model:'p/second'}];Loop.prototype.setPhase.call(agent,{...agent.phase});
|
|
126
|
+
await step({provider:'p',model:'first'},false);
|
|
127
|
+
// A real claimed message, unlike an empty queue, synchronizes before selection freezes.
|
|
128
|
+
agent.inbox.append('next-step',{id:'fixture-'+role,role:'user',content:[{type:'text',text:'fixture'}]});
|
|
129
|
+
await step({provider:'p',model:'second'},false);
|
|
130
|
+
cfg.members=[];defaults={provider:'changed-default',model:'new'};
|
|
131
|
+
await step({provider:'p',model:'second'},false);await step(defaults);cleanup();
|
|
132
|
+
defaults={provider:'default',model:'model'};
|
|
133
|
+
// Changing preset with no phase/inbox notification cannot send the old owned route.
|
|
134
|
+
reopen();cfg.members=[{key:'lead',model:'p/first'}];cleanup=attach();await step({provider:'p',model:'first'});
|
|
135
|
+
preset='standard';const beforeMode=calls;await assert.rejects(step({},false),/policy changed before step/);assert.equal(calls,beforeMode);passed++;
|
|
136
|
+
await step(native);cleanup();preset='cabinet';
|
|
137
|
+
// Membership arriving after a running transition must not silently use native fallback.
|
|
138
|
+
reopen();member=undefined;cfg.members=[{key:'lead',model:'p/late'}];cleanup=attach();await step(native);
|
|
139
|
+
member={role:'lead',name:'lead'};const beforeLate=calls;await assert.rejects(step({},false),/policy changed before step/);assert.equal(calls,beforeLate);passed++;
|
|
140
|
+
await step({provider:'p',model:'late'});cleanup();
|
|
141
|
+
// Corrupt records do not acquire ownership, and missing host APIs fail before any adapter call.
|
|
142
|
+
reopen();cfg.members=[];sessionApi.appendPluginRecord(agent.session,'plugin:dsh-cabinet-mode/model-policy',{agentId:agent.id,baseline:'bad',override:native});
|
|
143
|
+
cleanup=attach();await step(native);cleanup();
|
|
144
|
+
reopen();cfg.members=[{key:'lead',model:'p/first'}];const before=calls;cleanup=attach({});await assert.rejects(step({}),/API unavailable/);assert.equal(calls,before);passed++;
|
|
145
|
+
cfg.members=[];notify();await step(native);cleanup();
|
|
146
|
+
|
|
147
|
+
// Exercise real Loader volatile reconciliation, not a synthetic save notification.
|
|
148
|
+
reopen();member={role:'lead',name:'lead'};preset='cabinet';
|
|
149
|
+
ctx.baseUrl=loaderCtx.baseUrl;await ctx.plugin(Loader);new SessionProjectionRegistry(ctx);
|
|
150
|
+
ctx.provide('agents',{list:()=>[agent]});const loader=ctx.get('loader');
|
|
151
|
+
const entryId=await loader.create({name:new URL('../index.js',import.meta.url).href,config:{members:[{key:'lead',model:'p/saved-a'}]}});
|
|
152
|
+
await loader.await();const loaded=loader.resolve(entryId);assert.equal(loaded.fiber.state,2);const originalFiber=loaded.fiber;
|
|
153
|
+
await step({provider:'p',model:'saved-a'});
|
|
154
|
+
const oldPrepared=await Loop.prototype.preStep.call(agent,'next-step',{turn:3,step:1});const oldSignal=agent.phase.abort.signal;
|
|
155
|
+
await loader.update(entryId,{config:{members:[{key:'lead',model:'p/saved-b'}]}});await loader.await();
|
|
156
|
+
assert.equal(loaded.fiber,originalFiber,'volatile save does not remount');
|
|
157
|
+
assert.equal((await Loop.prototype.prepareRequest.call(agent,3,1,oldPrepared.selection,oldSignal)).config.model,'saved-a');passed++;
|
|
158
|
+
await step({provider:'p',model:'saved-b'},false);
|
|
159
|
+
// Another entry changing a field also called members cannot synchronize this policy.
|
|
160
|
+
const otherFile=path.join(path.dirname(exposed),'cabinet-unrelated-'+randomUUID()+'.mjs');
|
|
161
|
+
fs.writeFileSync(otherFile,'export {Config} from '+JSON.stringify(new URL('../index.js',import.meta.url).href)+'; export function apply(){}');
|
|
162
|
+
let otherId;try{otherId=await loader.create({name:pathToFileURL(otherFile).href,config:{members:[]}});await loader.await();
|
|
163
|
+
agent.model.select({provider:'manual',model:'keep'});
|
|
164
|
+
await loader.update(otherId,{config:{members:[{key:'lead',model:'p/unrelated'}]}});await loader.await();
|
|
165
|
+
assert.deepEqual(agent.model.current(),{provider:'manual',model:'keep'});passed++;
|
|
166
|
+
}finally{if(otherId)loader.remove(otherId);await loader.await();fs.unlinkSync(otherFile);}
|
|
167
|
+
// Restore a controlled route via a real save, then clear it with an empty inbox.
|
|
168
|
+
await loader.update(entryId,{config:{members:[{key:'lead',model:'p/saved-c'}]}});await loader.await();await step({provider:'p',model:'saved-c'},false);
|
|
169
|
+
await loader.update(entryId,{config:{members:[]}});await loader.await();await step(defaults,false);
|
|
170
|
+
loader.remove(entryId);await loader.await();
|
|
171
|
+
assert.ok(calls>=7);
|
|
172
|
+
}
|
|
173
|
+
console.log(`PASS ${passed} official rc.1 preStep -> prepareRequest cases; real AgentModel/Cordis/SystemPrompt; real inbox; identity and adapter fixtures; no model calls`);
|
|
@@ -14,7 +14,7 @@ preset='cabinet';config.members=[];assert.deepEqual((await route()).r,defaults);
|
|
|
14
14
|
services.agentPresets=undefined;assert.equal((await route()).r.model,'seed');
|
|
15
15
|
off();assert.equal(Object.keys(callbacks).length,0);
|
|
16
16
|
const effects=[],events={};services.agents={list:()=>[agent]};
|
|
17
|
-
apply({get:key=>services[key],effect:fn=>effects.push(fn()),on:(name,fn)=>{events[name]=fn;return()=>delete events[name];},systemPrompt:{getSectionOrder:()=>0,section:()=>()=>{}}},config);
|
|
17
|
+
await apply({get:key=>services[key],effect:fn=>effects.push(fn()),on:(name,fn)=>{events[name]=fn;return()=>delete events[name];},systemPrompt:{getSectionOrder:()=>0,section:()=>()=>{}}},config);
|
|
18
18
|
assert.equal(typeof callbacks['agent/request'],'function','backfill existing agents');
|
|
19
19
|
events['agent/disposed']({agent});assert.equal(Object.keys(callbacks).length,0);
|
|
20
20
|
events['agent/created']({agent});assert.equal(typeof callbacks['agent/request'],'function','attach before membership is available');
|