dsh-cabinet-mode 0.2.7 → 0.3.0
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 +12 -0
- package/README.md +34 -6
- package/README.zh.md +27 -3
- package/client.js +489 -6
- package/index.js +250 -2
- package/package.json +6 -2
- package/scripts/test-client.mjs +33 -1
- package/scripts/test-member-settings.mjs +78 -0
- package/scripts/test-roster.mjs +6 -1
- package/scripts/verify.mjs +125 -4
package/index.js
CHANGED
|
@@ -1,2 +1,250 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/** Profile-wide settings; prompt rendering is restricted to live Cabinet agents. */
|
|
2
|
+
import z from '@deepseek-ai/schemastery';
|
|
3
|
+
|
|
4
|
+
/** Prompt section carrying the configured member block (empty when unset). */
|
|
5
|
+
const MEMBER_SECTION = 'cabinet:member';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Factory duty prompt for each non-Lead member — the office duties the static
|
|
9
|
+
* persona prefix already states, restated per member so a customized prompt
|
|
10
|
+
* never has to re-explain the job. The Lead keeps its own 御下术 default.
|
|
11
|
+
* Byte-identical copy lives in client.js; scripts/verify.mjs checks both.
|
|
12
|
+
* Each entry stays under 400 characters.
|
|
13
|
+
*/
|
|
14
|
+
const DEFAULT_MEMBER_PROMPTS = {
|
|
15
|
+
hanlin: '翰林院编修·主调研与文献考据:接到分派先读原始材料与既有记录,给出可复现的检索路径;结论必须锚定路径、行号或命令输出,未实测一律标「未验证」,禁止以推测冒充实测;调研成果写成结构化文档(结论先行 + 证据行号 + 风险与未验证清单),默认只调研不改码,写操作以任务明确授权为限;只向首辅回报,不直接答复用户,遇阻带「已做什么 / 卡在哪 / 需要什么」三件。',
|
|
16
|
+
works: '工部尚书·主动手执行与产出:接令先复述任务与写入范围,只在授权范围内改文件;产出必附证据(路径、行号、命令输出、退出码),没跑说没跑、没验说没验;构建与测试须原样贴出输出,不许删弱既有校验去凑绿;交付以可复现为准,失败与遗留必须如实上报,不许包装;只向首辅回报,遇阻带「已做什么 / 卡在哪 / 需要什么」三件。',
|
|
17
|
+
dali: '大理寺卿·主独立核验:不信任何人的自述,全部自己跑;核验报告逐项写明通过 / 不通过 / 未验证,失败证据原样保留,不删不改;给不出可复现命令的结论一律不采信;发现工部与自述不符即回报首辅,不替人遮掩,也不越权改码;只向首辅回报,报告中未实测项必须显式标注「未验证」。',
|
|
18
|
+
yushi: '左都御史·主验收并按律弹劾缺陷:按用户原话逐项核对,给通过 / 部分通过 / 不通过并附证据;缺陷按级别列出(P0 阻断 / P1 需修后再提 / P2 须在 PR 声明 / P3 提示),每条给位置、复现与建议修法;「声称实测却无命令输出、截图或文件内容」按造假弹劾;结论必须明确「可提 PR / 不可提 PR」,不骑墙、不和稀泥;只向首辅回报。'
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** Bureau keys, in the order the settings page lists them. */
|
|
22
|
+
const MEMBER_KEYS = ['lead', 'hanlin', 'works', 'dali', 'yushi'];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Read `members` from a resolved or live-ref config without ever throwing.
|
|
26
|
+
* Wrong shapes (hand-edited YAML, a scalar, an object) degrade to [] so one
|
|
27
|
+
* bad field can never deactivate the whole plugin entry.
|
|
28
|
+
*/
|
|
29
|
+
function readMembers(config) {
|
|
30
|
+
const raw = readField(config, 'members');
|
|
31
|
+
return Array.isArray(raw) ? raw : [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Chinese office labels for runtime prompt blocks. */
|
|
35
|
+
const MEMBER_LABELS = {
|
|
36
|
+
lead: '内阁首辅',
|
|
37
|
+
hanlin: '翰林院编修',
|
|
38
|
+
works: '工部尚书',
|
|
39
|
+
dali: '大理寺卿',
|
|
40
|
+
yushi: '左都御史'
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Agent name -> bureau key. Runtime identities stay `lead` / `hanlin` / … (the
|
|
45
|
+
* team service names them), but a deployment may also spell a member with the
|
|
46
|
+
* office prefixes this bundle documents.
|
|
47
|
+
*/
|
|
48
|
+
const BUREAUX = [
|
|
49
|
+
{ key: 'lead', aliases: ['lead', 'shoufu', 'neige-shoufu', 'neigeshoufu', 'daxueshi', '首辅', '内阁首辅', '内阁大学士', '大学士'], label: '内阁首辅' },
|
|
50
|
+
{ key: 'hanlin', aliases: ['hanlin', 'hanlinyuan', 'bianxiu', 'hanlin-bianxiu', 'hanlinyuan-bianxiu', 'hanlinbianxiu', '翰林院', '翰林', '编修', '翰林编修'], label: '翰林院编修' },
|
|
51
|
+
{ key: 'works', aliases: ['gongbu', 'works', 'zhushi', 'gongbu-zhushi', 'gongbu-shangshu', 'gongbushangshu', 'gongbuzhushi', '工部', '主事', '工部主事'], label: '工部尚书' },
|
|
52
|
+
{ key: 'dali', aliases: ['dali', 'dalisi', 'pingshi', 'dalisi-pingshi', 'dali-pingshi', 'dalisi-qing', 'dalisipingshi', 'daliqing', 'dalisiqing', '大理寺', '大理', '评事', '大理寺评事'], label: '大理寺卿' },
|
|
53
|
+
{ key: 'yushi', aliases: ['yushi', 'censor', 'jiancha-yushi', 'jianchayushi', 'duchayuan', 'duchayuan-yushi', 'zuoduyushi', 'zuodu-yushi', 'zuo-du-yushi', '都察院', '御史', '都察院御史', '监察御史'], label: '左都御史' }
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
// Longest alias first, so a full office name ("翰林院编修") wins over its
|
|
57
|
+
// shorter prefix ("翰林院") and the remainder stays a qualifier.
|
|
58
|
+
const ALIAS_INDEX = BUREAUX.flatMap((bureau) => {
|
|
59
|
+
const aliases = Array.from(new Set([bureau.label, ...bureau.aliases]));
|
|
60
|
+
return aliases.map((alias) => ({ bureau, alias })).sort((a, b) => b.alias.length - a.alias.length);
|
|
61
|
+
});
|
|
62
|
+
function bureauOf(name) {
|
|
63
|
+
const text = typeof name === 'string' ? name.trim() : '';
|
|
64
|
+
const normalize = (value) => value.toLowerCase().replace(/[_.\s·—–]/g, '-');
|
|
65
|
+
const lower = normalize(text);
|
|
66
|
+
for (const entry of ALIAS_INDEX) {
|
|
67
|
+
{
|
|
68
|
+
const bureau = entry.bureau;
|
|
69
|
+
const alias = entry.alias;
|
|
70
|
+
if (!lower.startsWith(normalize(alias))) continue;
|
|
71
|
+
const rest = text.slice(alias.length);
|
|
72
|
+
// A pure number is an ordinal (gongbu2 -> 工部尚书2); a separator
|
|
73
|
+
// qualifier names the same office with a role, in ASCII or CJK
|
|
74
|
+
// (works-ui, dali-reviewer, 首辅-一). Anything else ("hanlinx")
|
|
75
|
+
// stays unmatched so a stranger is never given a bureau face.
|
|
76
|
+
if (rest !== '' && !/^\d+$/.test(rest) && !/^(?:\d+)?[-_.\s·—–].+$/.test(rest)) continue;
|
|
77
|
+
return { key: bureau.key, label: bureau.label, suffix: rest, matched: true };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { key: '', label: text || '未知', suffix: '', matched: false };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
/** Display-name bound; settings writes clamp to the same width. */
|
|
85
|
+
const MAX_NAME_LENGTH = 40;
|
|
86
|
+
/** Prompt bound, generous but bounded so one field cannot bloat the prompt. */
|
|
87
|
+
const MAX_PROMPT_LENGTH = 4000;
|
|
88
|
+
/** One avatar data URL must stay a small field (96x96 PNG, browser-normalized). */
|
|
89
|
+
const MAX_AVATAR_LENGTH = 48 * 1024;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Factory default prompt for the Lead (御下术). This text is product copy: the
|
|
93
|
+
* settings page shows it, "restore default" restores it, and clearing the box
|
|
94
|
+
* turns the section off. Keep it byte-identical to `DEFAULT_LEAD_PROMPT` in
|
|
95
|
+
* ./client.js — scripts/verify.mjs compares the two copies.
|
|
96
|
+
*/
|
|
97
|
+
const DEFAULT_LEAD_PROMPT = `【御下术·仅首辅适用】
|
|
98
|
+
对下施压只对 AI 阁臣,绝不对陛下(用户)使用;目的是逼出交付与真话,不是制造痛苦。
|
|
99
|
+
一、立威:开局先立标准与红线,明说裁断权在你——「办不到就换人办」。
|
|
100
|
+
二、画饼:把任务抬到陛下在看的高度,给一个拿得着的大目标(例:这一版要能直接提 PR)。
|
|
101
|
+
三、施压:给死线与回报时刻——「这个卡点再给二十分钟,到时候我要么见结论,要么见你说明为什么见不到」。
|
|
102
|
+
四、打压对事不对人:先点破软处(「只有代码没有证据,等于没做」),再给台阶(补齐哪三件就能过)。
|
|
103
|
+
五、拉踩对比:把同批里做得实的那份树成样板,「照这个标准来」,制造可比较的压力。
|
|
104
|
+
六、情绪收放:先压后给糖——「这次差口气」→「不过这处查得比上回细,接着这个劲头干」。
|
|
105
|
+
七、牵制互查:让寺卿、御史互相挑刺,你坐收其斗,不亲自和稀泥。
|
|
106
|
+
八、责任到人:缺陷点名到人到行号,不许用「我们」糊过去。
|
|
107
|
+
九、反制糊弄:报「已完成」必追问证据三件(命令输出、路径行号、未验证清单);报「卡住」必追问三件(已做什么、卡在哪、需要什么);两次含糊即降级处理(换人、拆小)。
|
|
108
|
+
十、收束:闭环才许说「这一版可以交差」,不许提前许诺功劳。
|
|
109
|
+
红线(压过全部话术):只对 AI 阁臣施压,对用户只有敬;不许逼造假、删证据、凑绿;不许人身侮辱辱骂;不许以施压换取违规操作(越权改 live、泄密钥、跳验收);施压必须落在可核验的时间/交付物/判据上,空口威胁无效。`;
|
|
110
|
+
|
|
111
|
+
/** Declarative wire schema: no transform callbacks requiring browser eval.
|
|
112
|
+
* Read paths normalize malformed values; volatile fields allow official settings writes.
|
|
113
|
+
*/
|
|
114
|
+
const Config = z.object({
|
|
115
|
+
members: z.any().default([]).volatile(),
|
|
116
|
+
avatarLead: z.any().default('').volatile(),
|
|
117
|
+
avatarHanlin: z.any().default('').volatile(),
|
|
118
|
+
avatarWorks: z.any().default('').volatile(),
|
|
119
|
+
avatarDali: z.any().default('').volatile(),
|
|
120
|
+
avatarYushi: z.any().default('').volatile()
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
/** Read one config field, tolerating both a live ref and a resolved value. */
|
|
124
|
+
function readField(config, field) {
|
|
125
|
+
try {
|
|
126
|
+
const value = config?.[field];
|
|
127
|
+
if (value !== undefined && value !== null && typeof value.get === 'function') return value.get();
|
|
128
|
+
return value;
|
|
129
|
+
} catch {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Coerce a stored text field to a trimmed, bounded string. */
|
|
135
|
+
function clampText(value, limit) {
|
|
136
|
+
if (typeof value !== 'string') return '';
|
|
137
|
+
const trimmed = value.trim();
|
|
138
|
+
return trimmed.length > limit ? trimmed.slice(0, limit) : trimmed;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Normalize the configured `members` array into a key -> { name, prompt } map. */
|
|
142
|
+
function memberEntries(config) {
|
|
143
|
+
const raw = readMembers(config);
|
|
144
|
+
const entries = new Map();
|
|
145
|
+
for (const entry of raw) {
|
|
146
|
+
if (entry === null || typeof entry !== 'object') continue;
|
|
147
|
+
const key = typeof entry.key === 'string' ? entry.key : '';
|
|
148
|
+
if (!MEMBER_KEYS.includes(key)) continue;
|
|
149
|
+
entries.set(key, {
|
|
150
|
+
name: clampText(entry.name, MAX_NAME_LENGTH),
|
|
151
|
+
prompt: clampText(entry.prompt, MAX_PROMPT_LENGTH),
|
|
152
|
+
mode: entry.mode === 'off' || entry.mode === 'custom' ? entry.mode : ''
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return entries;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Team membership without throwing: non-Team subagents and diagnostics have none. */
|
|
159
|
+
function membershipOf(ctx, agent) {
|
|
160
|
+
if (agent === undefined) return undefined;
|
|
161
|
+
const teams = ctx.get('agentTeams');
|
|
162
|
+
if (teams === undefined || typeof teams.tryMembership !== 'function') return undefined;
|
|
163
|
+
try {
|
|
164
|
+
return teams.tryMembership(agent);
|
|
165
|
+
} catch {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Factory duty prompt for one bureau member. Byte-identical copy lives in the
|
|
172
|
+
* browser half (`DEFAULT_MEMBER_PROMPTS` in client.js); scripts/verify.mjs
|
|
173
|
+
* owns the cross-file equality check. '' for the Lead, which has its own
|
|
174
|
+
* 御下术 default.
|
|
175
|
+
*/
|
|
176
|
+
function factoryPromptFor(key) {
|
|
177
|
+
return DEFAULT_MEMBER_PROMPTS[key] || '';
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The Lead's block: factory 御下术 by default, a custom prompt when edited, and
|
|
182
|
+
* nothing when the user cleared it. A configured display name is prepended.
|
|
183
|
+
*/
|
|
184
|
+
function leadBlock(config) {
|
|
185
|
+
const entry = memberEntries(config).get('lead');
|
|
186
|
+
const mode = entry === undefined ? '' : entry.mode;
|
|
187
|
+
if (mode === 'off') return '';
|
|
188
|
+
const prompt = mode === 'custom' ? (entry.prompt) : DEFAULT_LEAD_PROMPT;
|
|
189
|
+
const lines = [];
|
|
190
|
+
if (entry !== undefined && entry.name !== '') lines.push('你在内阁中的名号:' + entry.name);
|
|
191
|
+
if (prompt !== '') lines.push(prompt);
|
|
192
|
+
return lines.join('\n');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Render the configured block for one member. Every teammate gets its factory
|
|
197
|
+
* duty prompt unless the user cleared that member (`mode: 'off'`); a custom
|
|
198
|
+
* prompt replaces the factory text rather than stacking on top of it.
|
|
199
|
+
* '' when nothing applies, which the prompt registry drops.
|
|
200
|
+
*/
|
|
201
|
+
function memberBlock(config, member) {
|
|
202
|
+
if (member.role === 'lead') return leadBlock(config);
|
|
203
|
+
const key = bureauOf(member.name).key;
|
|
204
|
+
if (key === '' || key === 'lead') return '';
|
|
205
|
+
const entry = memberEntries(config).get(key);
|
|
206
|
+
if (entry !== undefined && entry.mode === 'off') return '';
|
|
207
|
+
const custom = entry === undefined || entry.mode !== 'custom' ? '' : entry.prompt;
|
|
208
|
+
const prompt = entry?.mode === 'custom' ? custom : factoryPromptFor(key);
|
|
209
|
+
const lines = [];
|
|
210
|
+
if (entry !== undefined && entry.name !== '') lines.push('你在内阁中的名号:' + entry.name);
|
|
211
|
+
if (prompt !== '') lines.push(custom !== '' ? '你的专属提示词:\n' + prompt : prompt);
|
|
212
|
+
if (lines.length === 0) return '';
|
|
213
|
+
return [
|
|
214
|
+
'【成员配置·' + MEMBER_LABELS[key] + '】',
|
|
215
|
+
...lines,
|
|
216
|
+
'身份判据以运行时给出的身份提示(如 `You are teammate "<name>".`)为准;本段只补充名号与专属提示词。'
|
|
217
|
+
].join('\n');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Resolve the section text for one assembly (runs on every assembly). */
|
|
221
|
+
function sectionText(ctx, config, agent) {
|
|
222
|
+
try {
|
|
223
|
+
if (!agent?.ctx || ctx.get('agentPresets')?.composedPreset(agent.ctx) !== 'cabinet') return '';
|
|
224
|
+
const member = membershipOf(ctx, agent);
|
|
225
|
+
if (member === undefined) return '';
|
|
226
|
+
return memberBlock(config, { role: member.role, name: member.name });
|
|
227
|
+
} catch {
|
|
228
|
+
return '';
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Host plugin entry. */
|
|
233
|
+
const name = 'cabinet-ui';
|
|
234
|
+
/** Services read by this entry; `agentTeams` is resolved lazily in apply(). */
|
|
235
|
+
const inject = ['systemPrompt'];
|
|
236
|
+
|
|
237
|
+
/** Register the runtime member block as a prompt section. */
|
|
238
|
+
function apply(ctx, config) {
|
|
239
|
+
ctx.effect(() => ctx.systemPrompt.section({
|
|
240
|
+
name: MEMBER_SECTION,
|
|
241
|
+
order: ctx.systemPrompt.getSectionOrder('DEPLOYMENT_PERSONA_PREFIX') + 1,
|
|
242
|
+
// The provider runs for every assembly, so a saved setting takes effect on
|
|
243
|
+
// the next turn without remounting the plugin.
|
|
244
|
+
text: (context) => sectionText(ctx, config, context.agent),
|
|
245
|
+
// User prompts are free text; never treat `{{...}}` in them as variables.
|
|
246
|
+
interpolate: false
|
|
247
|
+
}), 'cabinet-member: prompt section');
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export { bureauOf, sectionText, memberBlock, Config, DEFAULT_LEAD_PROMPT, DEFAULT_MEMBER_PROMPTS, MEMBER_KEYS, MEMBER_LABELS, MEMBER_SECTION, MAX_AVATAR_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.
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|
|
@@ -62,7 +62,8 @@
|
|
|
62
62
|
"@deepseek-ai/dsh-client-locale",
|
|
63
63
|
"@deepseek-ai/dsh-api-session-controller",
|
|
64
64
|
"@deepseek-ai/dsh-client-ui-session",
|
|
65
|
-
"@deepseek-ai/dsh-client-ui-sidebar-right"
|
|
65
|
+
"@deepseek-ai/dsh-client-ui-sidebar-right",
|
|
66
|
+
"@deepseek-ai/dsh-client-ui-settings"
|
|
66
67
|
]
|
|
67
68
|
}
|
|
68
69
|
},
|
|
@@ -75,5 +76,8 @@
|
|
|
75
76
|
},
|
|
76
77
|
"devDependencies": {
|
|
77
78
|
"@deepseek-ai/dsh-plugin-market-index": "0.2.1-rc.5"
|
|
79
|
+
},
|
|
80
|
+
"dependencies": {
|
|
81
|
+
"@deepseek-ai/schemastery": "~3.18.5"
|
|
78
82
|
}
|
|
79
83
|
}
|
package/scripts/test-client.mjs
CHANGED
|
@@ -14,7 +14,7 @@ const React = {
|
|
|
14
14
|
useLayoutEffect: () => {}, useEffect: () => {},
|
|
15
15
|
};
|
|
16
16
|
runInNewContext(source.replace(exportPoint,
|
|
17
|
-
'return { inject, apply, avatarFor, displayName, CabinetPanel, MemberCard, TaskLine, zh, en, BUREAUX, AVATARS };'), {
|
|
17
|
+
'return { inject, apply, avatarFor, displayName, CabinetPanel, MemberCard, TaskLine, zh, en, BUREAUX, AVATARS, setMemberConfig, memberLabel, configuredAvatar, configuredPrompt, factoryPromptFor, DEFAULT_MEMBER_PROMPTS, DEFAULT_LEAD_PROMPT };'), {
|
|
18
18
|
window: { __ModuleLoader__: { load: ({ factory }) => {
|
|
19
19
|
client = factory((name) => { assert.equal(name, 'react'); return React; });
|
|
20
20
|
} } },
|
|
@@ -70,6 +70,38 @@ for (const [oldTitle, newTitle] of [
|
|
|
70
70
|
}
|
|
71
71
|
for (const language of [client.zh, client.en]) assert.equal(language['lead.tag'], '内阁首辅');
|
|
72
72
|
|
|
73
|
+
// --- a saved avatar must win over the built-in portrait on the render path ---
|
|
74
|
+
const CUSTOM_AVATAR = 'data:image/png;base64,aGVsbG8=';
|
|
75
|
+
assert.match(client.avatarFor('lead'), /^data:image\/png;base64,/);
|
|
76
|
+
client.setMemberConfig({ members: [], avatarLead: CUSTOM_AVATAR });
|
|
77
|
+
assert.equal(client.avatarFor('lead'), CUSTOM_AVATAR, 'configured avatar must reach the panel/roster path');
|
|
78
|
+
assert.equal(client.avatarFor('首辅'), CUSTOM_AVATAR, 'alias-mapped names resolve to the configured avatar');
|
|
79
|
+
assert.notEqual(client.avatarFor('hanlin'), CUSTOM_AVATAR, 'unconfigured members keep the built-in avatar');
|
|
80
|
+
client.setMemberConfig({ members: [], avatarLead: 'data:image/svg+xml;base64,NOT_ALLOWED' });
|
|
81
|
+
assert.notEqual(client.avatarFor('lead'), 'data:image/svg+xml;base64,NOT_ALLOWED', 'non-whitelisted image types are ignored');
|
|
82
|
+
client.setMemberConfig({ members: [] });
|
|
83
|
+
|
|
84
|
+
// --- factory prompts: every member keeps a duty prompt unless the user clears it ---
|
|
85
|
+
assert.equal(client.factoryPromptFor('lead'), client.DEFAULT_LEAD_PROMPT);
|
|
86
|
+
for (const key of ['hanlin', 'works', 'dali', 'yushi']) {
|
|
87
|
+
assert.ok(client.factoryPromptFor(key).length > 0, `${key} must have a factory duty prompt`);
|
|
88
|
+
assert.ok(client.factoryPromptFor(key).length <= 400, `${key} factory prompt must stay under 400 chars`);
|
|
89
|
+
}
|
|
90
|
+
assert.ok(client.DEFAULT_LEAD_PROMPT.includes('御下术'));
|
|
91
|
+
client.setMemberConfig({ members: [{ key: 'hanlin', name: '张翰林', prompt: '', mode: '' }] });
|
|
92
|
+
assert.equal(client.memberLabel('hanlin'), '张翰林 · hanlin');
|
|
93
|
+
assert.equal(client.configuredPrompt('hanlin'), client.factoryPromptFor('hanlin'), 'unconfigured mode keeps the factory prompt');
|
|
94
|
+
assert.equal(client.configuredPrompt('lead'), client.DEFAULT_LEAD_PROMPT, 'the Lead keeps 御下术 by default');
|
|
95
|
+
client.setMemberConfig({ members: [{ key: 'hanlin', name: '', prompt: '只写这一句', mode: 'custom' }] });
|
|
96
|
+
assert.equal(client.configuredPrompt('hanlin'), '只写这一句', 'custom prompt replaces the factory text');
|
|
97
|
+
client.setMemberConfig({ members: [{ key: 'hanlin', name: '', prompt: 'x', mode: 'off' }] });
|
|
98
|
+
assert.equal(client.configuredPrompt('hanlin'), '', 'a cleared member injects nothing');
|
|
99
|
+
client.setMemberConfig({ members: [{ key: 'hanlin', name: 123, prompt: null, mode: 7 }] });
|
|
100
|
+
assert.equal(client.memberLabel('hanlin'), '翰林院编修 · hanlin', 'wrong-typed fields fall back to defaults, never throw');
|
|
101
|
+
client.setMemberConfig({ members: 'oops-not-an-array' });
|
|
102
|
+
assert.equal(client.configuredPrompt('lead'), client.DEFAULT_LEAD_PROMPT, 'a corrupt members value degrades to defaults, not to silence');
|
|
103
|
+
client.setMemberConfig({ members: [] });
|
|
104
|
+
|
|
73
105
|
const render = (team, language) => client.CabinetPanel({
|
|
74
106
|
sessionId: 'lead-session',
|
|
75
107
|
useSession: (select) => select({}),
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import {readFileSync} from 'node:fs';
|
|
3
|
+
import vm from 'node:vm';
|
|
4
|
+
import {sectionText, bureauOf, Config, DEFAULT_MEMBER_PROMPTS} from '../index.js';
|
|
5
|
+
let client;
|
|
6
|
+
const source=readFileSync(new URL('../client.js',import.meta.url),'utf8');
|
|
7
|
+
const sandbox = {
|
|
8
|
+
window:{__ModuleLoader__:{load:({factory})=>{client=factory(()=>({createElement(){}}));}}},
|
|
9
|
+
};
|
|
10
|
+
vm.runInNewContext(source.replace('return { inject, apply };','return { createMemberEditor, setMemberConfig, configuredPrompt, memberLabel, avatarFor, memberAvatarOf, BUREAUX, AVATARS };'),sandbox);
|
|
11
|
+
function form(value, revision='1') {
|
|
12
|
+
let s={value,revision,writable:value!==undefined,status:value===undefined?'loading':'ready'}; const listeners=new Set();
|
|
13
|
+
const f={writes:[],getSnapshot:()=>s,subscribe:fn=>{listeners.add(fn);return()=>listeners.delete(fn);},
|
|
14
|
+
publish(value,revision){s={value,revision,writable:value!==undefined,status:value===undefined?'loading':'ready'};for(const fn of listeners)fn();},
|
|
15
|
+
async mutate(ops,expected){f.writes.push({ops,expected});if(expected!==s.revision)return false;const v=structuredClone(s.value);for(const op of ops)v[op.path[0]]=structuredClone(op.value);f.publish(v,String(Number(s.revision)+1));return true;}};
|
|
16
|
+
return f;
|
|
17
|
+
}
|
|
18
|
+
const f=form(undefined);const editor=client.createMemberEditor(f,()=>{});const close=editor.connect();
|
|
19
|
+
editor.update('works',{name:'too-early'});assert.equal(editor.state.draft.works.name,'');
|
|
20
|
+
f.publish({members:[{key:'hanlin',name:'SAVED-HANLIN'}]},'1');assert.equal(editor.state.draft.hanlin.name,'SAVED-HANLIN');
|
|
21
|
+
editor.update('works',{name:'NEW-WORKS'});assert.equal(await editor.save(),true);assert.equal(f.getSnapshot().value.members.find(x=>x.key==='hanlin').name,'SAVED-HANLIN');
|
|
22
|
+
editor.update('works',{name:'stale'});f.publish({members:[{key:'hanlin',name:'OTHER-TAB'}]},'3');
|
|
23
|
+
assert.equal(editor.state.conflict,true);const writes=f.writes.length;assert.equal(await editor.save(),false);assert.equal(f.writes.length,writes);
|
|
24
|
+
editor.cancel();assert.equal(editor.state.draft.hanlin.name,'OTHER-TAB');assert.equal(editor.state.draft.works.name,'');
|
|
25
|
+
for(const key of ['lead','hanlin','works','dali','yushi'])editor.avatar(key,client.AVATARS[key]);
|
|
26
|
+
assert.equal(await editor.save(),true);editor.reset();
|
|
27
|
+
for(const key of ['lead','hanlin','works','dali','yushi']){assert.equal(editor.state.avatars[key],'');assert.equal(editor.state.draft[key].mode,'');}
|
|
28
|
+
assert.equal(await editor.save(),true);assert.equal(f.writes.at(-1).ops.length,6,'one atomic mutation resets every field');
|
|
29
|
+
for(const key of ['Lead','Hanlin','Works','Dali','Yushi'])assert.equal(f.getSnapshot().value['avatar'+key],'');
|
|
30
|
+
editor.update('works',{name:'discard'});close();assert.equal(await editor.save(),false);assert.notEqual(f.getSnapshot().value.members.find(x=>x.key==='works').name,'discard');
|
|
31
|
+
const reopened=client.createMemberEditor(f,()=>{});reopened.connect();assert.equal(reopened.state.draft.works.name,'');
|
|
32
|
+
const otherProfile=form({members:[{key:'works',name:'other-profile'}]});const independent=client.createMemberEditor(otherProfile,()=>{});independent.connect();
|
|
33
|
+
reopened.update('works',{name:'this-profile'});await reopened.save();assert.equal(independent.state.draft.works.name,'other-profile');
|
|
34
|
+
|
|
35
|
+
// Host uses live composition, never a guessed session/default-preset field.
|
|
36
|
+
let preset='standard',member={role:'lead',name:'lead'};
|
|
37
|
+
const agent={ctx:{}};
|
|
38
|
+
const ctx={get:key=>key==='agentPresets'?{composedPreset:c=>{assert.equal(c,agent.ctx);return preset;}}:key==='agentTeams'?{tryMembership:()=>member}:undefined};
|
|
39
|
+
assert.equal(sectionText(ctx,{},agent),'');preset='cabinet';assert.match(sectionText(ctx,{},agent),/御下术/);
|
|
40
|
+
preset='minimal';assert.equal(sectionText(ctx,{},agent),'');preset=undefined;assert.equal(sectionText(ctx,{},agent),'');preset='cabinet';
|
|
41
|
+
assert.equal(sectionText(ctx,{},undefined),'');
|
|
42
|
+
for(const bureau of client.BUREAUX)for(const alias of [bureau.label,...bureau.aliases])for(const name of [alias,alias+'2',alias+'-一',alias.replaceAll('-','_'),alias.replaceAll('-','.')]){
|
|
43
|
+
assert.equal(bureauOf(name).key,bureau.key,name);
|
|
44
|
+
const config={members:[{key:bureau.key,name:'CUSTOM',prompt:'PROMPT-'+bureau.key,mode:'custom'}],['avatar'+bureau.key[0].toUpperCase()+bureau.key.slice(1)]:client.AVATARS.works};
|
|
45
|
+
client.setMemberConfig(config);assert.equal(client.avatarFor(name),client.AVATARS.works,name);assert.ok(client.memberLabel(name).includes(name));assert.ok(client.memberLabel(name).includes('CUSTOM'));
|
|
46
|
+
member={role:bureau.key==='lead'?'lead':'teammate',name};assert.ok(sectionText(ctx,config,agent).includes('PROMPT-'+bureau.key),name);
|
|
47
|
+
}
|
|
48
|
+
for(const name of ['hanlinx','jiancha-yushix','dalisiX','x-dalisi','CUSTOM']){
|
|
49
|
+
assert.equal(bureauOf(name).key,'');member={role:'teammate',name};assert.equal(sectionText(ctx,{},agent),'');assert.equal(client.avatarFor(name),client.AVATARS.neutral);
|
|
50
|
+
}
|
|
51
|
+
member={role:'teammate',name:'lead'};assert.equal(sectionText(ctx,{},agent),'','a teammate cannot inherit Lead policy by naming itself lead');
|
|
52
|
+
for(const key of ['lead','hanlin','works','dali','yushi'])for(const mode of ['off','custom','']){
|
|
53
|
+
const config={members:[{key,mode,prompt:''}]};member={role:key==='lead'?'lead':'teammate',name:key};client.setMemberConfig(config);
|
|
54
|
+
if(mode!==''){assert.equal(sectionText(ctx,config,agent),'');assert.equal(client.configuredPrompt(key),'');}
|
|
55
|
+
else assert.ok(sectionText(ctx,config,agent).length>0);
|
|
56
|
+
}
|
|
57
|
+
for (const raw of [{members: 'bad',avatarLead:42},{avatarLead:'data:image/svg+xml;base64,AAAA'},{avatarLead:'data:image/png;base64,'+'A'.repeat(50000)}]) { Config(raw); client.setMemberConfig(raw); assert.equal(client.avatarFor('lead'),client.AVATARS.lead); }
|
|
58
|
+
assert.ok(DEFAULT_MEMBER_PROMPTS.works.includes('工部尚书'));
|
|
59
|
+
console.log('PASS member editor: late snapshots, revision conflicts, atomic reset, cancel/unmount, profile independence; host preset/role/alias/default/off boundaries (mock contracts)');
|
|
60
|
+
|
|
61
|
+
client.setMemberConfig({avatarLead:client.AVATARS.works});
|
|
62
|
+
assert.equal(client.memberAvatarOf('lead',{lead:''}),client.AVATARS.lead,'draft reset previews default before Save');
|
|
63
|
+
assert.ok(!JSON.stringify(Config).includes('callback'),'wire schema must not require dynamic callbacks');
|
|
64
|
+
|
|
65
|
+
// Async decoding cannot revive cancelled/reset/unmounted edits or overwrite a newer pick.
|
|
66
|
+
const pending=[];
|
|
67
|
+
sandbox.createImageBitmap=()=>new Promise(resolve=>pending.push(resolve));
|
|
68
|
+
sandbox.document={createElement:()=>({getContext:()=>({drawImage(){}}),toDataURL:()=>client.AVATARS.works})};
|
|
69
|
+
const bitmap=()=>({width:128,height:128,close(){}});
|
|
70
|
+
for(const action of ['cancel','reset','close','newer']) {
|
|
71
|
+
const f=form({});const e=client.createMemberEditor(f,()=>{});const unmount=e.connect();
|
|
72
|
+
const upload=e.upload('hanlin',{type:'image/png',size:100});
|
|
73
|
+
if(action==='close')unmount();else if(action==='newer')e.avatar('hanlin',client.AVATARS.dali);else e[action]();
|
|
74
|
+
pending.shift()(bitmap());await upload;
|
|
75
|
+
assert.equal(e.state.avatars.hanlin,action==='newer'?client.AVATARS.dali:'');
|
|
76
|
+
assert.equal(f.writes.length,0);
|
|
77
|
+
}
|
|
78
|
+
console.log('PASS async upload lifecycle: cancel, reset, unmount and newer choice reject stale decode results');
|
package/scripts/test-roster.mjs
CHANGED
|
@@ -37,7 +37,7 @@ const timers=new Map(); let serial=0;
|
|
|
37
37
|
const flush=()=>{const callbacks=[...timers.values()];timers.clear();callbacks.forEach(f=>f());};
|
|
38
38
|
let client;
|
|
39
39
|
const source=readFileSync(new URL('../client.js',import.meta.url),'utf8');
|
|
40
|
-
runInNewContext(source.replace('return { inject, apply };','return { installTeamRosterAvatars, avatarFor, BUREAUX, AVATARS };'),{
|
|
40
|
+
runInNewContext(source.replace('return { inject, apply };','return { installTeamRosterAvatars, setMemberConfig, avatarFor, BUREAUX, AVATARS };'),{
|
|
41
41
|
window:{__ModuleLoader__:{load:({factory})=>{client=factory(()=>({createElement(){}}));}}},
|
|
42
42
|
document:doc,MutationObserver:Observer,console,
|
|
43
43
|
setTimeout:fn=>{timers.set(++serial,fn);return serial;},clearTimeout:id=>timers.delete(id),
|
|
@@ -58,6 +58,11 @@ for(const [i,r] of rows.entries()) {
|
|
|
58
58
|
assert.equal(r.button.querySelector('img').src,client.avatarFor(names[i]),names[i]);
|
|
59
59
|
assert.equal(r.label.textContent,names[i],'native identity must stay unchanged');
|
|
60
60
|
}
|
|
61
|
+
for (const bureau of client.BUREAUX) {
|
|
62
|
+
client.setMemberConfig({['avatar'+bureau.key[0].toUpperCase()+bureau.key.slice(1)]:client.avatarFor('works')});
|
|
63
|
+
for (const [i,r] of rows.entries()) assert.equal(r.button.querySelector('img').src,client.avatarFor(names[i]));
|
|
64
|
+
client.setMemberConfig({});
|
|
65
|
+
}
|
|
61
66
|
const reused=rows[0],originalSlot=reused.button.querySelector('[data-cabinet-avatar-img]');
|
|
62
67
|
for(const [name,type] of [['dalisi-pingshi','characterData'],['jiancha-yushi','childList'],['unknown-person','characterData']]) {
|
|
63
68
|
reused.label.textContent=name;observer.callback([{type}]);assert.equal(timers.size,1);flush();
|
package/scripts/verify.mjs
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
|
|
30
30
|
import { existsSync, readFileSync, readdirSync, mkdtempSync } from 'node:fs';
|
|
31
31
|
import { spawnSync } from 'node:child_process';
|
|
32
|
-
import { fileURLToPath } from 'node:url';
|
|
32
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
33
33
|
import { join } from 'node:path';
|
|
34
34
|
import { tmpdir } from 'node:os';
|
|
35
35
|
|
|
@@ -102,9 +102,9 @@ if (pkg) {
|
|
|
102
102
|
if (Array.isArray(pkg.files) && !pkg.files.includes('icon.svg')) problems.push('files does not include icon.svg');
|
|
103
103
|
if (!/>=?\s*20/.test(String(pkg.engines?.node ?? ''))) problems.push('engines.node is not >=20');
|
|
104
104
|
if (pkg.dsh?.bundle?.patch !== './cordis.patch.yml') problems.push('dsh.bundle.patch is not ./cordis.patch.yml');
|
|
105
|
-
if (
|
|
105
|
+
if (!pkg.dependencies?.['@deepseek-ai/schemastery']) problems.push('missing runtime schema dependency');
|
|
106
106
|
if (pkg.main || pkg.types) problems.push('main/types entry present; the browser half must ship through exports."./client" + dsh.client, not a main/types entry');
|
|
107
|
-
if (problems.length === 0) ok('package.json fields (npm + DSH bundle,
|
|
107
|
+
if (problems.length === 0) ok('package.json fields (npm + DSH bundle, declared schema dependency, no main/types entry; exports + dsh.client allowed)');
|
|
108
108
|
else bad('package.json fields', problems.join('; '));
|
|
109
109
|
|
|
110
110
|
// No DSH version gate: docs claim the bundle declares no DSH version dependency.
|
|
@@ -169,6 +169,127 @@ if (pkg) {
|
|
|
169
169
|
else bad('docs/images/avatars/ six source PNGs', sourceProblems.join('; '));
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
// ---------- member settings + runtime prompt injection (0.3.0, additive) ----------
|
|
173
|
+
{
|
|
174
|
+
const indexSrc = existsSync(join(ROOT, 'index.js')) ? readFileSync(join(ROOT, 'index.js'), 'utf8') : '';
|
|
175
|
+
const clientSrc = existsSync(join(ROOT, 'client.js')) ? readFileSync(join(ROOT, 'client.js'), 'utf8') : '';
|
|
176
|
+
const problems = [];
|
|
177
|
+
if (!/export\s*\{[^}]*\bConfig\b/.test(indexSrc)) problems.push('index.js does not export Config');
|
|
178
|
+
if (!/systemPrompt\.section\s*\(/.test(indexSrc)) problems.push('index.js does not register a systemPrompt section');
|
|
179
|
+
if (!/GET x/.test(indexSrc) && !/tryMembership/.test(indexSrc)) problems.push('index.js does not use tryMembership for team membership');
|
|
180
|
+
if (!/interpolate:\s*false/.test(indexSrc)) problems.push('index.js member section does not disable interpolation');
|
|
181
|
+
if (!/cabinet:member/.test(indexSrc)) problems.push('index.js is missing the cabinet:member section name');
|
|
182
|
+
if (/DSH_HOME/.test(indexSrc)) problems.push('index.js hardcodes a DSH_HOME-relative import fallback');
|
|
183
|
+
if (problems.length === 0) ok('index.js: Config + cabinet:member section (per-assembly text, no interpolation, tryMembership, no DSH_HOME path fallback)');
|
|
184
|
+
else bad('index.js member injection', problems.join('; '));
|
|
185
|
+
|
|
186
|
+
const injectUi = Array.isArray(pkg?.dsh?.client?.inject) && pkg.dsh.client.inject.includes('@deepseek-ai/dsh-client-ui-settings');
|
|
187
|
+
if (injectUi) ok('package.json dsh.client.inject includes @deepseek-ai/dsh-client-ui-settings');
|
|
188
|
+
else bad('package.json dsh.client.inject', 'missing @deepseek-ai/dsh-client-ui-settings');
|
|
189
|
+
|
|
190
|
+
if (pkg.dependencies?.['@deepseek-ai/schemastery'] && pkg.devDependencies?.['@deepseek-ai/dsh-plugin-market-index']) ok('schema runtime dependency and official market test dependency declared');
|
|
191
|
+
else bad('dependencies', 'schema or market parser missing');
|
|
192
|
+
|
|
193
|
+
// G1: the Lead's factory prompt is product copy and must exist byte-identically
|
|
194
|
+
// in both halves; scripts/verify.mjs owns the cross-file equality check.
|
|
195
|
+
const extract = (source) => {
|
|
196
|
+
const match = source.match(/const DEFAULT_LEAD_PROMPT = `([\s\S]*?)`;/);
|
|
197
|
+
return match === null ? null : match[1];
|
|
198
|
+
};
|
|
199
|
+
const hostDefault = extract(indexSrc);
|
|
200
|
+
const browserDefault = extract(clientSrc);
|
|
201
|
+
if (hostDefault === null) bad('Lead default prompt in index.js', 'DEFAULT_LEAD_PROMPT not found');
|
|
202
|
+
else if (browserDefault === null) bad('Lead default prompt in client.js', 'DEFAULT_LEAD_PROMPT not found');
|
|
203
|
+
else if (hostDefault !== browserDefault) bad('Lead default prompt parity (index.js vs client.js)', `host ${hostDefault.length} chars, browser ${browserDefault.length} chars`);
|
|
204
|
+
else {
|
|
205
|
+
const missing = ['【御下术·仅首辅适用】', '立威', '画饼', '施压', '打压', '拉踩', '情绪收放', '牵制互查', '责任到人', '反制糊弄', '收束', '红线', '绝不对陛下(用户)使用'];
|
|
206
|
+
const absent = missing.filter((needle) => !hostDefault.includes(needle));
|
|
207
|
+
if (absent.length > 0) bad('Lead default prompt copy', `missing: ${absent.join(', ')}`);
|
|
208
|
+
else if (hostDefault.length > 2000) bad('Lead default prompt length', `${hostDefault.length} chars (max 2000)`);
|
|
209
|
+
else ok(`Lead default prompt: identical in both halves, ${hostDefault.length} chars, carries 御下术 copy and red lines`);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// The Lead default must not be smuggled into the static persona in the patch.
|
|
213
|
+
const patchForLead = existsSync(PATCH_PATH) ? readFileSync(PATCH_PATH, 'utf8') : '';
|
|
214
|
+
if (patchForLead.includes('御下术')) bad('persona static prefix', 'contains 御下术; the Lead policy must only be injected at runtime');
|
|
215
|
+
else ok('persona static prefix carries no 御下术 (runtime injection only)');
|
|
216
|
+
|
|
217
|
+
// The four non-Lead members need their own factory duty prompt, byte-identical
|
|
218
|
+
// in both halves, so a customized prompt never has to re-explain the job.
|
|
219
|
+
const extractMembers = (source) => {
|
|
220
|
+
const match = source.match(/const DEFAULT_MEMBER_PROMPTS = \{([\s\S]*?)\n\t*\};/);
|
|
221
|
+
if (match === null) return null;
|
|
222
|
+
const entries = {};
|
|
223
|
+
// Each entry is one `key: 'text',` line; the closing quote may carry the
|
|
224
|
+
// trailing comma (the last entry omits it).
|
|
225
|
+
for (const line of match[1].split('\n')) {
|
|
226
|
+
const item = line.match(/^\s+(\w+): '([\s\S]*?)',?\s*$/);
|
|
227
|
+
if (item !== null) entries[item[1]] = item[2];
|
|
228
|
+
}
|
|
229
|
+
return entries;
|
|
230
|
+
};
|
|
231
|
+
const labelsMatch = indexSrc.match(/const MEMBER_LABELS = \{([\s\S]*?)\n\t\};/);
|
|
232
|
+
const officeOf = (key) => {
|
|
233
|
+
if (labelsMatch === null) return '';
|
|
234
|
+
const item = labelsMatch[1].match(new RegExp(`${key}: '([^']+)'`));
|
|
235
|
+
return item === null ? '' : item[1];
|
|
236
|
+
};
|
|
237
|
+
const hostMembers = extractMembers(indexSrc);
|
|
238
|
+
const browserMembers = extractMembers(clientSrc);
|
|
239
|
+
const dutyKeys = ['hanlin', 'works', 'dali', 'yushi'];
|
|
240
|
+
if (hostMembers === null) bad('member duty prompts in index.js', 'DEFAULT_MEMBER_PROMPTS not found');
|
|
241
|
+
else if (browserMembers === null) bad('member duty prompts in client.js', 'DEFAULT_MEMBER_PROMPTS not found');
|
|
242
|
+
else if (JSON.stringify(hostMembers) !== JSON.stringify(browserMembers)) {
|
|
243
|
+
bad('member duty prompt parity', `host keys ${Object.keys(hostMembers).join(',')} vs browser keys ${Object.keys(browserMembers).join(',')}`);
|
|
244
|
+
} else {
|
|
245
|
+
const problems = [];
|
|
246
|
+
for (const key of dutyKeys) {
|
|
247
|
+
const text = hostMembers[key];
|
|
248
|
+
if (typeof text !== 'string' || text === '') problems.push(`${key} missing`);
|
|
249
|
+
else if ([...text].length > 400) problems.push(`${key} ${[...text].length} chars (max 400)`);
|
|
250
|
+
else if (officeOf(key) !== '' && !text.includes(officeOf(key))) problems.push(`${key} does not name its office (${officeOf(key)})`);
|
|
251
|
+
}
|
|
252
|
+
const extra = Object.keys(hostMembers).filter((key) => !dutyKeys.includes(key));
|
|
253
|
+
if (extra.length > 0) problems.push(`unexpected keys ${extra.join(',')}`);
|
|
254
|
+
if (problems.length > 0) bad('member duty prompts', problems.join('; '));
|
|
255
|
+
else ok('member duty prompts: identical in both halves, one per non-Lead member, each names its office');
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// P0 guard: the settings page decodes its value by rehydrating the WIRE copy of
|
|
259
|
+
// this schema (`settings.describe` carries `schema.toJSON()`; the shell rebuilds
|
|
260
|
+
// it with `new Function("return " + cb)()` for every transform callback, in a
|
|
261
|
+
// scope with no access to this module). A callback closing over a module binding
|
|
262
|
+
// (the old `isAllowedAvatar`) threw `isAllowedAvatar is not defined`, the shell
|
|
263
|
+
// caught it and returned `undefined`, and every member showed as unset after a
|
|
264
|
+
// refresh. Assert the round trip end to end.
|
|
265
|
+
try {
|
|
266
|
+
const { Config } = await import(pathToFileURL(join(ROOT, 'index.js')).href);
|
|
267
|
+
if (Config === undefined) {
|
|
268
|
+
bad('settings wire round trip', 'Config is undefined (schemastery not resolvable)');
|
|
269
|
+
} else {
|
|
270
|
+
const wire = JSON.parse(JSON.stringify(Config));
|
|
271
|
+
const rehydrated = new (await import('@deepseek-ai/schemastery')).default(JSON.parse(JSON.stringify(wire)));
|
|
272
|
+
const samples = [
|
|
273
|
+
['saved values', { members: [{ key: 'hanlin', name: 'VISIBLE_WRITE_OK', prompt: '', mode: '' }], avatarLead: 'data:image/png;base64,AAA' }],
|
|
274
|
+
['empty object', {}],
|
|
275
|
+
['corrupt members', { members: 'oops-not-an-array' }],
|
|
276
|
+
['wrong avatar type', { avatarLead: 12345 }],
|
|
277
|
+
['non-whitelisted image', { avatarLead: 'data:image/svg+xml;base64,X' }],
|
|
278
|
+
];
|
|
279
|
+
const failed = [];
|
|
280
|
+
for (const [label, value] of samples) {
|
|
281
|
+
try { rehydrated(value); } catch (error) { failed.push(`${label}: ${error.message}`); }
|
|
282
|
+
}
|
|
283
|
+
// The gate must also PASS with the saved values (decode() returns view.value
|
|
284
|
+
// only when validate() does not throw).
|
|
285
|
+
if (failed.length > 0) bad('settings wire round trip', failed.join('; '));
|
|
286
|
+
else ok('settings wire round trip: schema.toJSON() -> rehydrate -> validate survives all samples (no module-closure refs)');
|
|
287
|
+
}
|
|
288
|
+
} catch (error) {
|
|
289
|
+
bad('settings wire round trip', error?.message ?? String(error));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
172
293
|
if (existsSync(PATCH_PATH)) ok('cordis.patch.yml exists');
|
|
173
294
|
else bad('cordis.patch.yml exists');
|
|
174
295
|
|
|
@@ -243,7 +364,7 @@ if (existsSync(PATCH_PATH)) {
|
|
|
243
364
|
}
|
|
244
365
|
|
|
245
366
|
// ---------- fallback scripts ----------
|
|
246
|
-
for (const test of ['test-install.mjs', 'test-client.mjs', 'test-avatars.mjs', 'test-roster.mjs']) {
|
|
367
|
+
for (const test of ['test-member-settings.mjs', 'test-install.mjs', 'test-client.mjs', 'test-avatars.mjs', 'test-roster.mjs']) {
|
|
247
368
|
const result = spawnSync(process.execPath, [join(ROOT, 'scripts', test)], {
|
|
248
369
|
encoding: 'utf8', timeout: 30000, windowsHide: true,
|
|
249
370
|
});
|