dsh-cabinet-mode 0.2.7 → 0.3.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.
@@ -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 (Object.keys(pkg.dependencies ?? {}).length > 0) problems.push('runtime dependencies are not empty');
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, no runtime deps, no main/types entry; exports + dsh.client allowed)');
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
 
@@ -217,6 +338,11 @@ if (existsSync(PATCH_PATH)) {
217
338
  ['Lead duties: close loop', '闭环'],
218
339
  ['research-only default', '默认只调研不改码'],
219
340
  ['no fabricated sources', '不编造数据来源'],
341
+ ['dispatch budget is prompt-only', '分派预算约定(提示词约束,非运行时计数器)'],
342
+ ['single-file budget', '≤30 次工具调用'],
343
+ ['integration budget', '≤100 次'],
344
+ ['retry budget', '同一失败重试 ≤2 次'],
345
+ ['budget exhaustion disclosure', '到限未完成就交「失败 / 未验证」'],
220
346
  ];
221
347
  const personaMissing = personaChecks.filter(([, needle]) => !patchText.includes(needle)).map(([label]) => label);
222
348
  if (personaMissing.length === 0) ok('dual-identity persona keywords');
@@ -243,7 +369,7 @@ if (existsSync(PATCH_PATH)) {
243
369
  }
244
370
 
245
371
  // ---------- fallback scripts ----------
246
- for (const test of ['test-install.mjs', 'test-client.mjs', 'test-avatars.mjs', 'test-roster.mjs']) {
372
+ for (const test of ['test-member-settings.mjs', 'test-install.mjs', 'test-client.mjs', 'test-avatars.mjs', 'test-roster.mjs']) {
247
373
  const result = spawnSync(process.execPath, [join(ROOT, 'scripts', test)], {
248
374
  encoding: 'utf8', timeout: 30000, windowsHide: true,
249
375
  });
@@ -357,6 +483,8 @@ if (!dshVersion) {
357
483
  const missingShipped = shipped.filter((id) => countOccurrences(output, `- id: ${id}`) !== 1);
358
484
  if (missingShipped.length === 0) ok('dump-config keeps the four shipped presets');
359
485
  else bad('dump-config shipped presets', missingShipped.join(', '));
486
+ if (output.includes('分派预算约定(提示词约束,非运行时计数器)') && output.includes('≤30 次工具调用') && output.includes('≤100 次') && /同一失败重试\s+≤2\s+次/.test(output)) ok('dump-config contains the new prompt-only dispatch budgets');
487
+ else bad('dump-config dispatch budgets');
360
488
  if (output.includes('内阁模式')) ok('dump-config contains the Cabinet Mode display name');
361
489
  else bad('dump-config contains 内阁模式');
362
490
  }