@sparkelf/dsh-plus 0.2.7-alpha.50 → 0.2.9-alpha.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +1 -1
  3. package/README.zh.md +1 -1
  4. package/cordis.patch.yml +29 -7
  5. package/lib/{apply-DmICvIGh.js → apply-CvePS57c.js} +213 -43
  6. package/lib/{apply-08huHfLG.js → apply-DycMqLJO.js} +240 -53
  7. package/lib/apply-c_7SZFSh.js +1193 -0
  8. package/lib/apply.js +2 -2
  9. package/lib/bin.js +20 -319
  10. package/lib/types/apply.d.ts +14 -1
  11. package/lib/types/apply.js +275 -53
  12. package/lib/types/capabilities.js +25 -36
  13. package/lib/types/manifest.d.ts +24 -0
  14. package/lib/types/manifest.js +51 -0
  15. package/lib/types/profile.d.ts +1 -0
  16. package/lib/types/profile.js +14 -3
  17. package/package.json +529 -577
  18. package/patches/approval-allow-policy.patch +3 -3
  19. package/patches/atomic-write-zombie-lock-holder.patch +1 -1
  20. package/patches/bootstrap-exempt-names.patch +6 -6
  21. package/patches/composer-popover-boundaries.patch +41 -283
  22. package/patches/image-offload-hoist-replay.patch +34 -31
  23. package/patches/input-trigger-source-label.patch +63 -0
  24. package/patches/legacy-code-preset.patch +5 -5
  25. package/patches/llm-pi-ai-transport-truncation.patch +4 -4
  26. package/patches/mobile-journal-generation.patch +2 -2
  27. package/patches/office-preview-stable-load.patch +1 -1
  28. package/patches/officecli-deliverables.patch +2 -2
  29. package/patches/ptc-mcp-schema-types.patch +3 -3
  30. package/patches/responses-reasoning-status.patch +197 -48
  31. package/patches/session-controller-image-downgrade-and-tool-visibility.patch +16 -14
  32. package/patches/session-export-chinese.patch +11 -11
  33. package/patches/session-format-legacy-restart.patch +1 -1
  34. package/patches/sidebar-right-tab-menu.patch +119 -0
  35. package/patches/state-dot-brand-blue.patch +2 -2
  36. package/patches/ui-settings-compact-phone.patch +2 -9
  37. package/patches/ui-sidebar-right-global-panel.patch +3 -3
  38. package/patches/workspace-hide-group-rooms.patch +38 -0
  39. package/patches/workspace-storage-restore.patch +21 -5
  40. package/patches/wsl-native-open.patch +8 -8
  41. package/lib/apply-e0aMC4B4.js +0 -601
  42. package/lib/types/standalone-capabilities.d.ts +0 -139
  43. package/lib/types/standalone-capabilities.js +0 -688
  44. package/lib/types/standalone-cli.d.ts +0 -17
  45. package/lib/types/standalone-cli.js +0 -913
  46. package/lib/types/standalone-profile.d.ts +0 -258
  47. package/lib/types/standalone-profile.js +0 -747
  48. package/lib/types/standalone-server.d.ts +0 -70
  49. package/lib/types/standalone-server.js +0 -158
  50. package/patches/browser-auth-mode.patch +0 -127
  51. package/patches/diagram-preview.patch +0 -562
  52. package/patches/dsh-resource-ref-chip.patch +0 -40
  53. package/patches/session-envelope-ignorable.patch +0 -63
  54. package/patches/session-log-trajectory-toolbar.patch +0 -352
  55. package/patches/ui-schedule-plaza-tab.patch +0 -217
  56. package/patches/web-runtime-compat.patch +0 -83
@@ -1,12 +1,13 @@
1
- /** Materialize the Plus distribution's embedded patch set without Desktop. */
1
+ /** Materialize the Plus distribution's independent patch packages without Desktop. */
2
2
  import { spawnSync } from 'node:child_process';
3
3
  import { chmodSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, symlinkSync, writeFileSync, } from 'node:fs';
4
4
  import { createRequire } from 'node:module';
5
- import { basename, dirname, isAbsolute, relative, resolve } from 'node:path';
5
+ import { readPatchSet } from "./patch-set.js";
6
+ import { writeProfileCompatibility } from "./manifest.js";
7
+ import { dirname, isAbsolute, relative, resolve } from 'node:path';
6
8
  import { tmpdir } from 'node:os';
7
9
  import { satisfies, valid, validRange } from 'semver';
8
10
  import { parseDocument } from 'yaml';
9
- import { readPatchSet } from "./patch-set.js";
10
11
  const FORMAT_VERSION = 1;
11
12
  function isSelectedNpmPatch(patch) {
12
13
  return patch.target.kind === 'npm';
@@ -49,24 +50,44 @@ function requireStringArray(value, label) {
49
50
  throw new Error(label + ' must not contain duplicates');
50
51
  return strings;
51
52
  }
52
- function resolveInstalledPackage(distributionDirectory, packageName) {
53
+ /**
54
+ * Resolve one installed package's manifest directory.
55
+ *
56
+ * `require.resolve(name + '/package.json')` respects the package's `exports`
57
+ * map, so a dependency that publishes only `"."` — `@sparkelf/dsh-quant`
58
+ * 0.91.0-sparkelf.13 among the `personal` edition's packages — fails to
59
+ * resolve even though the package is installed. Reading a manifest is not a
60
+ * public-export lookup, so resolve the package entry and walk up to the
61
+ * manifest that names it.
62
+ * @param distributionDirectory - directory whose resolution anchors the lookup.
63
+ * @param packageName - dependency name to locate.
64
+ * @returns path of the `package.json` that declares `packageName`.
65
+ */
66
+ function resolvePackageManifest(distributionDirectory, packageName) {
53
67
  const requireFromDistribution = createRequire(resolve(distributionDirectory, 'package.json'));
54
- let manifestPath;
55
68
  try {
56
- manifestPath = requireFromDistribution.resolve(packageName + '/package.json');
69
+ return requireFromDistribution.resolve(packageName + '/package.json');
57
70
  }
58
71
  catch {
59
- // Some packages do not export `./package.json`; resolve the entry module instead and walk
60
- // up to the directory that holds the manifest.
61
- let directory = dirname(requireFromDistribution.resolve(packageName));
62
- while (!existsSync(resolve(directory, 'package.json'))) {
63
- const parent = dirname(directory);
64
- if (parent === directory)
65
- throw new Error(packageName + ' has no resolvable package manifest');
66
- directory = parent;
72
+ // Exports does not carry the subpath; fall through to the entry walk.
73
+ }
74
+ let directory = dirname(requireFromDistribution.resolve(packageName));
75
+ for (;;) {
76
+ const candidate = resolve(directory, 'package.json');
77
+ if (existsSync(candidate)) {
78
+ const names = JSON.parse(readFileSync(candidate, 'utf8'));
79
+ if (names.name === packageName)
80
+ return candidate;
67
81
  }
68
- manifestPath = resolve(directory, 'package.json');
82
+ const parent = dirname(directory);
83
+ if (parent === directory) {
84
+ throw new Error(packageName + ' is installed but no package.json naming it was found');
85
+ }
86
+ directory = parent;
69
87
  }
88
+ }
89
+ function resolveInstalledPackage(distributionDirectory, packageName) {
90
+ const manifestPath = resolvePackageManifest(distributionDirectory, packageName);
70
91
  const manifest = readJsonObject(manifestPath, packageName + ' manifest');
71
92
  return {
72
93
  name: packageName,
@@ -75,6 +96,48 @@ function resolveInstalledPackage(distributionDirectory, packageName) {
75
96
  manifest,
76
97
  };
77
98
  }
99
+ function resolvePatchFile(packageDirectory, declared) {
100
+ const absoluteFile = resolve(packageDirectory, declared);
101
+ const local = relative(packageDirectory, absoluteFile);
102
+ if (isAbsolute(local) || local === '..' || local.startsWith('../')) {
103
+ throw new Error('patch file must stay inside its patch package: ' + declared);
104
+ }
105
+ if (!existsSync(absoluteFile))
106
+ throw new Error('patch file does not exist: ' + absoluteFile);
107
+ return { relativeFile: local.replaceAll('\\', '/'), absoluteFile };
108
+ }
109
+ function parseVariant(value, index, patchPackage) {
110
+ const label = patchPackage.name + ' dshPatch.variants[' + String(index) + ']';
111
+ const variant = requireObject(value, label);
112
+ const target = requireObject(variant.target, label + '.target');
113
+ const kind = requireString(target.kind, label + '.target.kind');
114
+ const common = {
115
+ id: requireString(variant.id, label + '.id'),
116
+ dsh: requireRange(variant.dsh, label + '.dsh'),
117
+ file: requireString(variant.file, label + '.file'),
118
+ patchPackage,
119
+ };
120
+ if (kind === 'npm') {
121
+ return {
122
+ ...common,
123
+ target: {
124
+ kind,
125
+ name: requireString(target.name, label + '.target.name'),
126
+ range: requireRange(target.range, label + '.target.range'),
127
+ },
128
+ };
129
+ }
130
+ if (kind === 'dsh-source') {
131
+ return {
132
+ ...common,
133
+ target: {
134
+ kind,
135
+ baseRevision: requireString(target.baseRevision, label + '.target.baseRevision'),
136
+ },
137
+ };
138
+ }
139
+ throw new Error('unsupported patch target kind: ' + kind);
140
+ }
78
141
  function git(root, args, acceptFailure = false) {
79
142
  const result = spawnSync('git', args, { cwd: root, encoding: 'utf8' });
80
143
  if (result.status === 0)
@@ -122,6 +185,79 @@ function requireSourceBase(root, baseRevision) {
122
185
  }
123
186
  return checkoutRevision;
124
187
  }
188
+ /**
189
+ * Names of distribution dependencies that carry `dshPatch` variants.
190
+ *
191
+ * `patchPackageVariants()` resolves these names from the Plus install tree, so they must be
192
+ * packages this distribution actually depends on. The current manifest declares `dshPlus.patchSet`
193
+ * instead of a flat list: only entries whose target is an npm package name a `dshPatch` carrier
194
+ * (`dsh-source` entries name the source packages being patched, which are never Plus dependencies).
195
+ * An older tarball may still carry the flat `dshPlus.patchPackages` list, which wins when present.
196
+ *
197
+ * @param plus - Parsed `dshPlus` block of the distribution manifest.
198
+ * @returns Patch-carrier package names; empty when the distribution ships only source patches.
199
+ */
200
+ export function resolvePatchPackageNames(plus) {
201
+ const declared = plus.patchPackages;
202
+ if (declared !== undefined) {
203
+ const names = requireStringArray(declared, 'dshPlus.patchPackages');
204
+ if (names.length > 0)
205
+ return names;
206
+ }
207
+ const patchSet = requireObject(plus.patchSet, 'dshPlus.patchSet');
208
+ const entries = patchSet.entries;
209
+ if (!Array.isArray(entries))
210
+ throw new Error('dshPlus.patchSet.entries must be an array');
211
+ const names = new Set();
212
+ for (const [index, value] of entries.entries()) {
213
+ const entry = requireObject(value, 'dshPlus.patchSet.entries[' + String(index) + ']');
214
+ const target = requireObject(entry.target, 'dshPlus.patchSet.entries[' + String(index) + '].target');
215
+ if (target.kind !== 'npm')
216
+ continue;
217
+ names.add(requireString(target.name, 'dshPlus.patchSet.entries[' + String(index) + '].target.name'));
218
+ }
219
+ return [...names].sort();
220
+ }
221
+ function patchPackageVariants(distributionDirectory, names) {
222
+ const variants = [];
223
+ for (const name of names) {
224
+ const patchPackage = resolveInstalledPackage(distributionDirectory, name);
225
+ const declaration = requireObject(patchPackage.manifest.dshPatch, name + ' dshPatch');
226
+ if (declaration.formatVersion !== FORMAT_VERSION) {
227
+ throw new Error('unsupported dshPatch formatVersion in ' + name + ': ' + String(declaration.formatVersion));
228
+ }
229
+ if (!Array.isArray(declaration.variants) || declaration.variants.length === 0) {
230
+ throw new Error(name + ' dshPatch.variants must be a non-empty array');
231
+ }
232
+ for (const [index, value] of declaration.variants.entries()) {
233
+ variants.push(parseVariant(value, index, patchPackage));
234
+ }
235
+ }
236
+ return variants;
237
+ }
238
+ /**
239
+ * Build patch variants from the distribution's `dshPlus.patchSet`.
240
+ *
241
+ * The patch files live inside the Plus package (`./patches/*.patch`), so every variant points at
242
+ * the distribution itself as its patch package: `resolvePatchFile()` then resolves the declared
243
+ * path inside the tarball, and `materializePatchFiles()` copies it into the profile's stable
244
+ * patch directory. Unlike the retired `dshPatch` carrier packages, the source packages named in
245
+ * `target.packages` are never resolved from the Plus tree -- they are the packages being patched.
246
+ *
247
+ * @param distribution - Installed Plus distribution package.
248
+ */
249
+ function patchSetVariants(distribution) {
250
+ const patchSet = readPatchSet(distribution.directory, distribution.manifest);
251
+ return [...patchSet.entries, ...patchSet.thirdPartyPatches].map((entry) => ({
252
+ id: entry.id,
253
+ dsh: entry.dsh,
254
+ file: entry.file,
255
+ patchPackage: distribution,
256
+ target: entry.target.kind === 'npm'
257
+ ? { kind: 'npm', name: entry.target.name, range: entry.target.range }
258
+ : { kind: 'dsh-source', baseRevision: entry.target.baseRevision },
259
+ }));
260
+ }
125
261
  // 先验证official source,再物化Plus声明的profile依赖,避免source不匹配时改动用户profile。
126
262
  function prepareSelection(distributionDirectory, profileDirectory, dshRoot) {
127
263
  const distributionManifest = readJsonObject(resolve(distributionDirectory, 'package.json'), 'Plus distribution manifest');
@@ -149,66 +285,109 @@ function prepareSelection(distributionDirectory, profileDirectory, dshRoot) {
149
285
  throw new Error('dshPlus.profile.allowBuilds.' + name + ' must be a boolean');
150
286
  allowBuilds[name] = allowed;
151
287
  }
152
- const patchSet = readPatchSet(distributionDirectory, distributionManifest);
288
+ const compatibilityExemptions = profile.compatibility === undefined
289
+ ? []
290
+ : requireStringArray(profile.compatibility, 'dshPlus.profile.compatibility');
291
+ for (const entry of compatibilityExemptions) {
292
+ const separator = entry.lastIndexOf('@');
293
+ const name = entry.slice(0, separator);
294
+ const version = entry.slice(separator + 1);
295
+ if (separator <= 0 || valid(version) === null) {
296
+ throw new Error('dshPlus.profile.compatibility entry must be an exact package@version, got: ' + entry);
297
+ }
298
+ if (profileDependencySpecs[name] !== version) {
299
+ throw new Error('dshPlus.profile.compatibility names ' + entry + ', which dshPlus.profile.dependencies does not pin');
300
+ }
301
+ }
302
+ const patchPackageNames = resolvePatchPackageNames(plus);
153
303
  const dependencies = requireObject(distributionManifest.dependencies, 'Plus distribution dependencies');
154
304
  const dshManifest = readJsonObject(resolve(dshRoot, 'package.json'), 'DSH source manifest');
155
305
  const dshVersion = requireVersion(dshManifest.version, 'DSH source version');
156
306
  if (!satisfies(dshVersion, dshRange, { includePrerelease: true })) {
157
307
  throw new Error(distributionName + '@' + distributionVersion + ' requires DSH ' + dshRange + ', found ' + dshVersion);
158
308
  }
159
- const checkoutRevision = requireSourceBase(dshRoot, patchSet.sourceBaseRevision);
160
- const patchEntries = [...patchSet.entries, ...patchSet.thirdPartyPatches];
309
+ const checkoutRevision = requireSourceBase(dshRoot, baseRevision);
310
+ // Legacy tarballs declare `dshPlus.patchPackages` (dshPatch carrier packages); the current
311
+ // distribution declares `dshPlus.patchSet` with the patch files inside the Plus package.
312
+ const variants = plus.patchPackages === undefined
313
+ ? patchSetVariants({
314
+ name: distributionName,
315
+ version: distributionVersion,
316
+ directory: distributionDirectory,
317
+ manifest: distributionManifest,
318
+ })
319
+ : patchPackageVariants(distributionDirectory, patchPackageNames);
320
+ const groups = new Map();
321
+ for (const variant of variants) {
322
+ const entries = groups.get(variant.id) ?? [];
323
+ entries.push(variant);
324
+ groups.set(variant.id, entries);
325
+ }
161
326
  const sourceStates = new Map();
162
- for (const item of patchEntries) {
163
- if (!satisfies(dshVersion, item.dsh, { includePrerelease: true })) {
164
- throw new Error('patch ' + item.id + ' declares DSH ' + item.dsh + ', found ' + dshVersion);
327
+ const orderedGroups = [...groups].sort(([left], [right]) => left.localeCompare(right));
328
+ for (const [, variants] of orderedGroups) {
329
+ for (const variant of variants) {
330
+ if (variant.target.kind !== 'dsh-source'
331
+ || variant.target.baseRevision !== baseRevision
332
+ || !satisfies(dshVersion, variant.dsh, { includePrerelease: true }))
333
+ continue;
334
+ const file = resolvePatchFile(variant.patchPackage.directory, variant.file);
335
+ sourceStates.set(file.absoluteFile, sourcePatchState(dshRoot, file.absoluteFile));
165
336
  }
166
- if (item.target.kind !== 'dsh-source')
167
- continue;
168
- const absoluteFile = resolve(distributionDirectory, item.file);
169
- sourceStates.set(absoluteFile, sourcePatchState(dshRoot, absoluteFile));
170
337
  }
171
338
  const pendingSourceFiles = [...sourceStates].flatMap(([file, state]) => state === 'pending' ? [file] : []);
172
339
  preflightSourcePatches(dshRoot, pendingSourceFiles);
173
340
  writeProfileRequirements(profileDirectory, profileDependencySpecs, allowBuilds);
341
+ writeProfileCompatibility(profileDirectory, compatibilityExemptions, dshVersion);
174
342
  runPnpm(profileDirectory, ['install', '--no-frozen-lockfile'], 'pnpm install Plus profile dependencies');
175
343
  const profileDependencies = Object.keys(profileDependencySpecs).sort().map((name) => {
176
344
  const installed = resolveInstalledPackage(profileDirectory, name);
177
345
  return { name, version: installed.version };
178
346
  });
179
347
  const runtimePackages = [
180
- ...Object.keys(dependencies).sort().map((name) => {
348
+ ...Object.keys(dependencies).filter(name => !patchPackageNames.includes(name)).sort().map((name) => {
181
349
  const installed = resolveInstalledPackage(distributionDirectory, name);
182
350
  return { name, version: installed.version };
183
351
  }),
184
352
  ...profileDependencies,
185
353
  ].sort((left, right) => left.name.localeCompare(right.name));
186
354
  const selected = [];
187
- for (const item of patchEntries) {
188
- const absoluteFile = resolve(distributionDirectory, item.file);
189
- if (item.target.kind === 'dsh-source') {
190
- selected.push({
191
- id: item.id,
192
- scope: item.scope,
193
- file: item.file,
194
- absoluteFile,
195
- target: { kind: 'dsh-source', baseRevision: patchSet.sourceBaseRevision },
196
- alreadyApplied: sourceStates.get(absoluteFile) === 'applied',
197
- });
198
- continue;
199
- }
200
- const targetDirectory = item.target.name in profileDependencySpecs ? profileDirectory : distributionDirectory;
201
- const targetVersion = resolveInstalledPackage(targetDirectory, item.target.name).version;
202
- if (!satisfies(targetVersion, item.target.range, { includePrerelease: true })) {
203
- throw new Error('patch ' + item.id + ' targets ' + item.target.name + ' ' + item.target.range + ', found ' + targetVersion);
204
- }
205
- selected.push({
206
- id: item.id,
207
- scope: item.scope,
208
- file: item.file,
209
- absoluteFile,
210
- target: { kind: 'npm', name: item.target.name, version: targetVersion },
355
+ // 每个patch id必须在当前DSH、official base与installed npm graph上唯一命中,不能fallback到第二variant。
356
+ for (const [id, variants] of orderedGroups) {
357
+ const candidates = variants.flatMap((variant) => {
358
+ if (!satisfies(dshVersion, variant.dsh, { includePrerelease: true }))
359
+ return [];
360
+ const file = resolvePatchFile(variant.patchPackage.directory, variant.file);
361
+ if (variant.target.kind === 'dsh-source') {
362
+ if (variant.target.baseRevision !== baseRevision)
363
+ return [];
364
+ return [{
365
+ id,
366
+ patchPackage: { name: variant.patchPackage.name, version: variant.patchPackage.version },
367
+ file: file.relativeFile,
368
+ absoluteFile: file.absoluteFile,
369
+ target: { kind: 'dsh-source', baseRevision },
370
+ alreadyApplied: sourceStates.get(file.absoluteFile) === 'applied',
371
+ }];
372
+ }
373
+ const targetDirectory = variant.target.name in profileDependencySpecs ? profileDirectory : distributionDirectory;
374
+ const targetVersion = resolveInstalledPackage(targetDirectory, variant.target.name).version;
375
+ if (!satisfies(targetVersion, variant.target.range, { includePrerelease: true }))
376
+ return [];
377
+ return [{
378
+ id,
379
+ patchPackage: { name: variant.patchPackage.name, version: variant.patchPackage.version },
380
+ file: file.relativeFile,
381
+ absoluteFile: file.absoluteFile,
382
+ target: { kind: 'npm', name: variant.target.name, version: targetVersion },
383
+ }];
211
384
  });
385
+ const [candidate] = candidates;
386
+ if (candidate === undefined)
387
+ throw new Error('no compatible patch variant for ' + id + ' on DSH ' + dshVersion);
388
+ if (candidates.length > 1)
389
+ throw new Error('multiple compatible patch variants for ' + id + ' on DSH ' + dshVersion);
390
+ selected.push(candidate);
212
391
  }
213
392
  const lockPatches = selected.map((patch) => {
214
393
  if ('alreadyApplied' in patch) {
@@ -238,7 +417,7 @@ function materializePatchFiles(profileDirectory, patches) {
238
417
  const root = resolve(profileDirectory, '.dsh-plus', 'patches');
239
418
  rmSync(root, { recursive: true, force: true });
240
419
  const stablePatches = patches.map((patch) => {
241
- const destination = resolve(root, patch.scope, patch.id, basename(patch.file));
420
+ const destination = resolve(root, patch.patchPackage.name, patch.patchPackage.version, patch.file);
242
421
  mkdirSync(dirname(destination), { recursive: true });
243
422
  copyFileSync(patch.absoluteFile, destination);
244
423
  return { ...patch, absoluteFile: destination };
@@ -262,7 +441,7 @@ function materializePatchFiles(profileDirectory, patches) {
262
441
  continue;
263
442
  }
264
443
  // 成员或版本变化必须改变workspace路径,使pnpm重新应用新的组合payload。
265
- const members = group.map(patch => encodeURIComponent(patch.id)).join('+');
444
+ const members = group.map(patch => encodeURIComponent(patch.id + '@' + patch.patchPackage.version)).join('+');
266
445
  const destination = resolve(root, 'combined', encodeURIComponent(key), members + '.patch');
267
446
  mkdirSync(dirname(destination), { recursive: true });
268
447
  const contents = group.map((patch) => {
@@ -307,6 +486,48 @@ function profilePatchConfiguration(profileDirectory, npmPatchFiles) {
307
486
  return { text: String(document), changed };
308
487
  }
309
488
  // 用户显式执行apply后,这里一次性写入profile root依赖与唯一native build许可;冲突直接失败。
489
+ /**
490
+ * Profile-local pnpm hook that keeps the CDN-only xlsx dependency installable.
491
+ *
492
+ * `@deepseek-ai/dsh-client-ui-sidebar-documentpreview` declares `xlsx` as
493
+ * `https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz`. SheetJS stopped publishing to npm
494
+ * after 0.18.5, so no registry mirror carries 0.20.3, and the build network cannot reach that
495
+ * CDN (measured 2026-11-06: every request times out). The image vendors the tarball at
496
+ * /opt/dsh-vendor; this hook rewrites the spec wherever it appears so a cold profile install
497
+ * never requests the CDN.
498
+ *
499
+ * Written into the profile root rather than a template: the Plus bundle has no profile
500
+ * template directory, the profile manifest and pnpm-workspace.yaml are generated here.
501
+ */
502
+ const PROFILE_PNPMFILE = `// Generated by @sparkelf/dsh-plus -- do not edit; rewritten on every apply.
503
+ const VENDORED_XLSX = '/opt/dsh-vendor/xlsx-0.20.3.tgz'
504
+ const CDN_XLSX = /^https?:\\/\\/cdn\\.sheetjs\\.com\\//
505
+ const FIELDS = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']
506
+
507
+ module.exports = {
508
+ hooks: {
509
+ readPackage(pkg) {
510
+ for (const field of FIELDS) {
511
+ const deps = pkg && pkg[field]
512
+ if (deps && typeof deps.xlsx === 'string' && CDN_XLSX.test(deps.xlsx)) {
513
+ deps.xlsx = 'file:' + VENDORED_XLSX
514
+ }
515
+ }
516
+ return pkg
517
+ },
518
+ },
519
+ }
520
+ `;
521
+ /** Write the profile pnpmfile when its content changed; returns whether it wrote. */
522
+ function writeProfilePnpmfile(profileDirectory) {
523
+ const path = resolve(profileDirectory, '.pnpmfile.cjs');
524
+ const current = existsSync(path) ? readFileSync(path, 'utf8') : undefined;
525
+ if (current === PROFILE_PNPMFILE)
526
+ return false;
527
+ writeFileSync(path, PROFILE_PNPMFILE);
528
+ console.log('profile pnpmfile: xlsx -> /opt/dsh-vendor/xlsx-0.20.3.tgz');
529
+ return true;
530
+ }
310
531
  function writeProfileRequirements(profileDirectory, dependencySpecs, allowBuilds) {
311
532
  const manifestPath = resolve(profileDirectory, 'package.json');
312
533
  const manifest = readJsonObject(manifestPath, 'DSH profile manifest');
@@ -374,7 +595,8 @@ function writeProfileRequirements(profileDirectory, dependencySpecs, allowBuilds
374
595
  }
375
596
  if (workspaceChanged)
376
597
  writeFileSync(workspacePath, String(document));
377
- return manifestChanged || workspaceChanged;
598
+ const pnpmfileChanged = writeProfilePnpmfile(profileDirectory);
599
+ return manifestChanged || workspaceChanged || pnpmfileChanged;
378
600
  }
379
601
  function writeProfileComposition(profileDirectory, bundles, runtimePackages) {
380
602
  const path = resolve(profileDirectory, 'package.json');
@@ -6,7 +6,7 @@ export const CAPABILITIES = [
6
6
  {
7
7
  id: 'exa',
8
8
  title: 'Web search (Exa)',
9
- detail: 'Search the web through Exa instead of the built-in provider; needs an API key',
9
+ detail: 'Route web search through the Exa provider the profile mounts; needs an API key',
10
10
  needsEndpoint: false,
11
11
  },
12
12
  {
@@ -151,9 +151,11 @@ export function capabilityEnvironment(answers, existing = '') {
151
151
  * The profile patch layer that turns the selected capabilities on.
152
152
  *
153
153
  * The file is data the profile's loader merges, so enabling a capability writes a
154
- * row rather than editing the deployment. An empty selection still writes the file,
155
- * because a layer that exists and mounts nothing is how a previously enabled
156
- * capability is turned back off.
154
+ * row rather than editing the deployment. Exa is the exception: the distribution
155
+ * mounts its provider unconditionally and the capability supplies only the key in the
156
+ * deployment env file, so no row is written for it. An empty selection still writes
157
+ * the file, because a layer that exists and mounts nothing is how a previously
158
+ * enabled capability is turned back off.
157
159
  *
158
160
  * The profile's own layer is a separate file with its own name: a deployment that
159
161
  * configured something by hand keeps it, and the capability rows are rewritten
@@ -222,9 +224,10 @@ function foreignPatchRows(existing) {
222
224
  export function capabilityPatchLayer(answers, existing = '') {
223
225
  const enabled = new Set(answers.enabled);
224
226
  const rows = [];
225
- if (enabled.has('exa')) {
226
- rows.push(' - id: web-search-exa', " name: '@deepseek-ai/dsh-web-search-exa'", ' config:', ' searchType: auto', ' numResults: 8');
227
- }
227
+ // Exa is mounted by the distribution's own patch layer, so enabling the capability
228
+ // writes no row: the plugin registers itself unavailable until `EXA_API_KEY` resolves,
229
+ // and the bundle layer's selector falls back to the official provider without it.
230
+ // The answer reaches Exa through the deployment env file instead.
228
231
  if (enabled.has('computer-use')) {
229
232
  rows.push(' - id: computer-use', " name: '@deepseek-ai/dsh-computer-use'", ' - id: computer-use-cua-driver-mcp', " name: '@deepseek-ai/dsh-experimental-computer-use-cua-driver-mcp'");
230
233
  }
@@ -262,9 +265,6 @@ export function capabilityPatchLayer(answers, existing = '') {
262
265
  else {
263
266
  lines.push('[]');
264
267
  }
265
- if (enabled.has('exa')) {
266
- lines.push('', '# Route web_search through Exa rather than the built-in provider.', '- id: web', ' config:', ' searchProvider: exa');
267
- }
268
268
  if (foreign.length > 0) {
269
269
  lines.push('', '# Rows this file carried before the capability interview; kept verbatim.', ...foreign);
270
270
  }
@@ -323,22 +323,25 @@ export function readCapabilityRecord(home) {
323
323
  */
324
324
  export function detectEnabledCapabilities(profilePatchText, envText) {
325
325
  const mounted = [];
326
+ const env = [];
327
+ for (const line of envText.split('\n')) {
328
+ const name = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(line)?.[1];
329
+ if (name !== undefined && !env.includes(name))
330
+ env.push(name);
331
+ }
332
+ // Exa's provider row belongs to the distribution layer, so the key is what enables the
333
+ // capability. A row in a layer written by an earlier release still counts as mounted;
334
+ // the distribution layer provides the same provider, and the key decides availability.
335
+ if (env.includes('EXA_API_KEY') || /^\s*- id: web-search-exa\s*$/mu.test(profilePatchText))
336
+ mounted.push('exa');
326
337
  // Matching the row id is what the loader does; matching a bare package name would also
327
338
  // hit a comment or a name mentioned in an unrelated row's config.
328
- if (/^\s*- id: web-search-exa\s*$/mu.test(profilePatchText))
329
- mounted.push('exa');
330
339
  if (/^\s*- id: mineru\s*$/mu.test(profilePatchText))
331
340
  mounted.push('mineru');
332
341
  if (/^\s*- id: officecli\s*$/mu.test(profilePatchText))
333
342
  mounted.push('officecli');
334
343
  if (/^\s*- id: computer-use\s*$/mu.test(profilePatchText))
335
344
  mounted.push('computer-use');
336
- const env = [];
337
- for (const line of envText.split('\n')) {
338
- const name = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(line)?.[1];
339
- if (name !== undefined && !env.includes(name))
340
- env.push(name);
341
- }
342
345
  return { mounted, env };
343
346
  }
344
347
  /**
@@ -352,15 +355,6 @@ export function detectEnabledCapabilities(profilePatchText, envText) {
352
355
  * @returns the insert payload lines, without the surrounding `- insert:` entry.
353
356
  */
354
357
  function capabilityRows(id) {
355
- if (id === 'exa') {
356
- return [
357
- ' - id: web-search-exa',
358
- " name: '@deepseek-ai/dsh-web-search-exa'",
359
- ' config:',
360
- ' searchType: auto',
361
- ' numResults: 8',
362
- ];
363
- }
364
358
  if (id === 'officecli') {
365
359
  return [
366
360
  ' - id: officecli',
@@ -379,6 +373,8 @@ function capabilityRows(id) {
379
373
  }
380
374
  /** The row ids a capability owns in the profile layer. */
381
375
  function capabilityRowIds(id) {
376
+ // Exa's row belongs to the distribution layer now. The name stays owned here so a
377
+ // layer written by an earlier release is cleaned up rather than left to duplicate it.
382
378
  if (id === 'exa')
383
379
  return ['web-search-exa'];
384
380
  if (id === 'officecli')
@@ -416,7 +412,7 @@ export function editCapabilityPatchLayer(existing, id, enable, mineruEndpoint) {
416
412
  ];
417
413
  const rows = id === 'mineru' && enable ? mineruRows : capabilityRows(id);
418
414
  const text = enable && rows !== undefined
419
- ? insertCapabilityRows(withoutRows, rows, id === 'exa')
415
+ ? insertCapabilityRows(withoutRows, rows)
420
416
  : withoutRows.text;
421
417
  // Every file this repository writes ends with exactly one newline; an edited layer must
422
418
  // not lose that, and the loader's YAML parse is indifferent to it either way.
@@ -495,10 +491,9 @@ function dropOwnedRows(existing, ids, withSelector) {
495
491
  *
496
492
  * @param state - the layer with this capability's own rows already removed.
497
493
  * @param rows - the insert payload lines to add.
498
- * @param withSelector - whether Exa's `web` selector row must also be present.
499
494
  * @returns the layer's new text.
500
495
  */
501
- function insertCapabilityRows(state, rows, withSelector) {
496
+ function insertCapabilityRows(state, rows) {
502
497
  const lines = state.text.split('\n');
503
498
  const insertIndex = lines.findIndex(line => /^- insert:\s*$/.test(line));
504
499
  if (insertIndex >= 0) {
@@ -527,12 +522,6 @@ function insertCapabilityRows(state, rows, withSelector) {
527
522
  lines.push(trailing);
528
523
  }
529
524
  }
530
- if (withSelector && !/^\s*- id: web\s*$/mu.test(lines.join('\n'))) {
531
- // The selector is a top-level row: it patches the bundle layer's own `web` entry, and
532
- // it must restate `fetchProvider` because a patch replaces the whole `config` object
533
- // rather than merging into it.
534
- lines.push('', '# Route web_search through Exa rather than the built-in provider.', '- id: web', ' config:', ' searchProvider: exa', ' fetchProvider: http');
535
- }
536
525
  return lines.join('\n');
537
526
  }
538
527
  /**
@@ -10,6 +10,8 @@
10
10
  *
11
11
  * @module manifest
12
12
  */
13
+ /** Independent profile metadata the app-boot preflight reads before importing plugins. */
14
+ export declare const PROFILE_COMPATIBILITY_FILENAME = "compatibility.json";
13
15
  /** One entry of the distribution's patch set, as far as override derivation reads it. */
14
16
  export interface PatchEntryFacts {
15
17
  readonly id: string;
@@ -30,6 +32,15 @@ export interface DistributionFacts {
30
32
  readonly omissionSpec: string;
31
33
  readonly bundles: readonly string[];
32
34
  readonly dependencies: Readonly<Record<string, string>>;
35
+ /**
36
+ * Exact `package@version` grants the generated profile records in `compatibility.json`.
37
+ *
38
+ * The app-boot preflight disables a row whose exact `@deepseek-ai/dsh-*` peers disagree
39
+ * with the running runtime. An official plugin cut against the previous patch release can
40
+ * still be the newest published build, so the distribution declares the exact package it
41
+ * admits on its own runtime instead of widening the plugin's peer range.
42
+ */
43
+ readonly compatibilityExemptions: readonly string[];
33
44
  readonly allowBuilds: Readonly<Record<string, boolean>>;
34
45
  /** Official package name to republished build spec. */
35
46
  readonly redirects: Readonly<Record<string, string>>;
@@ -117,6 +128,19 @@ export declare function projectEdition(facts: DistributionFacts, editionId?: str
117
128
  * @returns nothing; throws on the first unavailable target.
118
129
  */
119
130
  export declare function assertRedirectsPublished(redirects: Readonly<Record<string, string>>, registry?: string): Promise<void>;
131
+ /**
132
+ * Record the distribution's exact-version grants in the profile's compatibility file.
133
+ *
134
+ * The file is the app-boot preflight's own grant mechanism: a missing or unreadable file
135
+ * authorizes nothing, and every other key belongs to the deployment. Writing merges the
136
+ * distribution's grants into the existing object rather than replacing it, so a grant a
137
+ * user or image added for another plugin survives a `dsh-plus install`/`start`.
138
+ *
139
+ * @param directory - profile directory that receives the file.
140
+ * @param exemptions - exact `package@version` grants the distribution admits.
141
+ * @param runtimeVersion - exact runtime each grant names.
142
+ */
143
+ export declare function writeProfileCompatibility(directory: string, exemptions: readonly string[], runtimeVersion: string): void;
120
144
  /**
121
145
  * Write the profile manifest and the pnpm workspace the install reads.
122
146
  *