@sparkelf/dsh-plus 0.2.9-alpha.83 → 0.2.9-alpha.85

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/lib/apply.js CHANGED
@@ -1,2 +1,2 @@
1
- import { i as runApply, n as parseOfficialWorkspacePackages, r as resolvePatchPackageNames, t as materializeOfficialPackageScope } from "./apply-DycMqLJO.js";
1
+ import { i as runApply, n as parseOfficialWorkspacePackages, r as resolvePatchPackageNames, t as materializeOfficialPackageScope } from "./apply-c_7SZFSh.js";
2
2
  export { materializeOfficialPackageScope, parseOfficialWorkspacePackages, resolvePatchPackageNames, runApply };
package/lib/bin.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { a as readPatchSet, i as runApply } from "./apply-DycMqLJO.js";
2
+ import { a as assertRedirectsPublished, c as writeProfileCompatibility, i as runApply, l as writeProfileProjection, o as projectEdition, s as readDistributionFacts, u as readPatchSet } from "./apply-c_7SZFSh.js";
3
3
  import { createRequire } from "node:module";
4
4
  import { execFileSync, spawn, spawnSync } from "node:child_process";
5
5
  import { createWriteStream, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
6
6
  import { dirname, join, posix, resolve, win32 } from "node:path";
7
- import semver, { valid, validRange } from "semver";
7
+ import semver from "semver";
8
8
  import { homedir } from "node:os";
9
9
  import { parseDocument } from "yaml";
10
10
  import { fileURLToPath } from "node:url";
@@ -75,307 +75,13 @@ function newerVersion(name, installed, registry = "https://registry.npmjs.org")
75
75
  return publishedVersions(name, registry).filter((entry) => semver.gt(entry.version, installed)).at(-1);
76
76
  }
77
77
  //#endregion
78
- //#region lib/types/manifest.js
79
- /**
80
- * Derive the profile's override table from the distribution's own facts.
81
- *
82
- * The distribution records one truth per fact: the patch set names the official packages it
83
- * patches, the runtime names the version its republished builds carry, and an edition names the
84
- * capabilities a deployment omits. The override table npm and pnpm read is a projection of those
85
- * three, never a fourth list: an entry that cannot be derived fails the build instead of being
86
- * carried forward, which is what kept a stale `@deepseek-ai/dsh-client-ui-slots` pin alive long
87
- * after the patch behind it had gone.
88
- *
89
- * @module manifest
90
- */
91
- /** npm scope every patched official package is republished under. */
92
- const OFFICIAL_PREFIX = "@deepseek-ai/";
93
- /** npm scope the distribution publishes its republished builds under. */
94
- const REPUBLISHED_PREFIX = "@sparkelf/";
95
- function record(value, label) {
96
- if (value === null || typeof value !== "object" || Array.isArray(value)) throw new Error(label + " must be an object");
97
- return value;
98
- }
99
- /** A declared value as text, or the fallback when the manifest holds something else. */
100
- function text(value, fallback = "") {
101
- return typeof value === "string" ? value : fallback;
102
- }
103
- function stringArray(value, label) {
104
- if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string" || entry === "")) throw new Error(label + " must be a non-empty string array");
105
- return value;
106
- }
107
- function stringMap(value, label) {
108
- const result = {};
109
- for (const [name, spec] of Object.entries(record(value, label))) {
110
- if (typeof spec !== "string" || spec === "") throw new Error(label + "." + name + " must be a non-empty string");
111
- result[name] = spec;
112
- }
113
- return result;
114
- }
115
- /**
116
- * The republished scope name for one official package.
117
- *
118
- * @param official - an `@deepseek-ai/dsh-*` name.
119
- * @returns the `@sparkelf/dsh-*` name the distribution publishes it as.
120
- */
121
- function republishedName(official) {
122
- if (!official.startsWith(OFFICIAL_PREFIX)) throw new Error(official + " is not an official package name");
123
- return REPUBLISHED_PREFIX + official.slice(13);
124
- }
125
- /**
126
- * Derive the redirect table from the patch set.
127
- *
128
- * Every `dsh-source` entry republishes the packages its payload modifies, because a registry
129
- * installation has no source tree to patch. An entry that changes only types sets
130
- * `target.republish: false` and must say why; anything else would look like a redirect that
131
- * silently never happens.
132
- *
133
- * @param entries - the distribution's patch entries.
134
- * @param runtimeVersion - exact version the republished builds carry.
135
- * @returns official name to `npm:` alias spec.
136
- */
137
- function deriveRedirects(entries, runtimeVersion) {
138
- const redirects = {};
139
- const ids = {};
140
- for (const entry of entries) {
141
- if (entry.target.kind !== "dsh-source") continue;
142
- const packages = entry.target.packages ?? [];
143
- if (packages.length === 0) throw new Error("patch entry " + entry.id + " declares no target packages");
144
- if (!(entry.target.republish !== false)) {
145
- if (entry.target.reason === void 0 || entry.target.reason.trim() === "") throw new Error("patch entry " + entry.id + " sets republish:false without a reason");
146
- continue;
147
- }
148
- for (const official of packages) {
149
- const spec = "npm:" + republishedName(official) + "@" + runtimeVersion;
150
- if (redirects[official] !== void 0 && redirects[official] !== spec) throw new Error("patch entries " + (ids[official] ?? "?") + " and " + entry.id + " redirect " + official + " to different targets");
151
- redirects[official] = spec;
152
- ids[official] = entry.id;
153
- }
154
- }
155
- if (Object.keys(redirects).length === 0) throw new Error("the patch set declares no republishable target");
156
- return {
157
- redirects,
158
- ids
159
- };
160
- }
161
- /** Read and validate the facts one installed distribution declares. */
162
- function readDistributionFacts(directory) {
163
- const manifest = record(JSON.parse(readFileSync(join(directory, "package.json"), "utf8")), "distribution manifest");
164
- const plus = record(manifest.dshPlus, "dshPlus");
165
- const profile = record(plus.profile, "dshPlus.profile");
166
- if (profile.overrides !== void 0) throw new Error("dshPlus.profile.overrides is retired; overrides are derived from dshPlus.patchSet");
167
- const runtimeVersion = text(record(plus.runtime, "dshPlus.runtime").version);
168
- if (valid(runtimeVersion) === null) throw new Error("dshPlus.runtime.version must be an exact version, got: " + runtimeVersion);
169
- const omission = record(plus.omission, "dshPlus.omission");
170
- const omissionPackage = text(omission.package);
171
- const omissionVersion = text(omission.version);
172
- if (!omissionPackage.startsWith("@sparkelf/") || valid(omissionVersion) === null) throw new Error("dshPlus.omission must name an @sparkelf package and an exact version");
173
- if (validRange(text(record(plus.compatibility, "dshPlus.compatibility").dsh)) === null) throw new Error("dshPlus.compatibility.dsh must be a semver range");
174
- const rawEntries = record(plus.patchSet, "dshPlus.patchSet").entries;
175
- if (!Array.isArray(rawEntries) || rawEntries.length === 0) throw new Error("dshPlus.patchSet.entries must be a non-empty array");
176
- const { redirects, ids } = deriveRedirects(rawEntries.map((value, index) => {
177
- const entry = record(value, "patchSet.entries[" + String(index) + "]");
178
- const target = record(entry.target, "patchSet.entries[" + String(index) + "].target");
179
- const targetFacts = { kind: text(target.kind) };
180
- if (target.packages !== void 0) Object.assign(targetFacts, { packages: stringArray(target.packages, "target.packages") });
181
- if (target.republish === false) Object.assign(targetFacts, { republish: false });
182
- if (typeof target.reason === "string") Object.assign(targetFacts, { reason: target.reason });
183
- return {
184
- id: text(entry.id),
185
- target: targetFacts
186
- };
187
- }), runtimeVersion);
188
- const dependencies = stringMap(profile.dependencies, "dshPlus.profile.dependencies");
189
- const allowBuilds = {};
190
- for (const [name, allowed] of Object.entries(record(profile.allowBuilds, "dshPlus.profile.allowBuilds"))) {
191
- if (typeof allowed !== "boolean") throw new Error("dshPlus.profile.allowBuilds." + name + " must be a boolean");
192
- allowBuilds[name] = allowed;
193
- }
194
- const editions = {};
195
- const rawEditions = plus.editions === void 0 ? {} : record(plus.editions, "dshPlus.editions");
196
- for (const [id, value] of Object.entries(rawEditions)) {
197
- const edition = record(value, "dshPlus.editions." + id);
198
- const rawPackages = edition.packages;
199
- if (rawPackages === void 0) throw new Error("dshPlus.editions." + id + ".packages is required");
200
- const names = Array.isArray(rawPackages) ? stringArray(rawPackages, "dshPlus.editions." + id + ".packages") : Object.keys(record(rawPackages, "dshPlus.editions." + id + ".packages"));
201
- for (const name of names) if (dependencyKey(dependencies, name) === void 0) throw new Error("edition \"" + id + "\" installs " + name + ", which dshPlus.profile.dependencies does not pin");
202
- const omit = stringArray(edition.omit ?? [], "dshPlus.editions." + id + ".omit");
203
- for (const name of omit) if (dependencies[name] === void 0 && manifest.dependencies?.[name] === void 0) throw new Error("edition \"" + id + "\" omits " + name + ", which the distribution does not declare");
204
- const excludePackages = stringArray(edition.excludePackages ?? [], "dshPlus.editions." + id + ".excludePackages");
205
- for (const name of excludePackages) {
206
- if (dependencies[name] === void 0 && !stringArray(edition.bundles ?? [], "x").includes(name)) throw new Error("edition \"" + id + "\" excludes " + name + ", which it does not install or mount");
207
- if (omit.includes(name)) throw new Error("edition \"" + id + "\" both excludes and omits " + name);
208
- for (const [other, spec] of Object.entries(dependencies)) if (/^npm:/u.test(spec) && spec.includes(name + "@")) throw new Error("edition \"" + id + "\" excludes " + name + " but " + other + " aliases it");
209
- }
210
- const bundles = stringArray(edition.bundles ?? [], "dshPlus.editions." + id + ".bundles");
211
- for (const name of bundles) if (omit.includes(name)) throw new Error("edition \"" + id + "\" mounts " + name + " but also omits it");
212
- editions[id] = {
213
- label: text(edition.label, id),
214
- profile: text(edition.profile, "plus"),
215
- bundles,
216
- packages: names,
217
- omit,
218
- excludePackages
219
- };
220
- }
221
- return {
222
- name: String(manifest.name),
223
- version: String(manifest.version),
224
- runtimeVersion,
225
- omissionSpec: "npm:" + omissionPackage + "@" + omissionVersion,
226
- bundles: stringArray(profile.bundles, "dshPlus.profile.bundles"),
227
- dependencies,
228
- allowBuilds,
229
- redirects,
230
- redirectIds: ids,
231
- editions
232
- };
233
- }
234
- /**
235
- * The dependency-table key that installs one package.
236
- *
237
- * A bundle published under a scope we own is installed through an alias: the official name a
238
- * consumer imports (`dsh-better-sidebar`) is the key, and the spec names our build
239
- * (`npm:@sparkelf/dsh-better-sidebar@…`). Editions name the real package, so the
240
- * lookup has to follow the alias or it reports a reviewed package as unpinned.
241
- *
242
- * @param dependencies - the distribution's dependency table.
243
- * @param name - package name an edition names.
244
- * @returns the key that installs it, or undefined when the distribution does not carry it.
245
- */
246
- function dependencyKey(dependencies, name) {
247
- if (dependencies[name] !== void 0) return name;
248
- for (const [key, spec] of Object.entries(dependencies)) if (/^npm:(@[^/]+\/[^@]+)@/u.exec(spec)?.[1] === name) return key;
249
- }
250
- /**
251
- * Project an edition into the profile npm and pnpm install.
252
- *
253
- * The distribution's reviewed order is the base; the edition names the bundle order and package
254
- * set it installs and the capabilities it must not run. Versions always come from
255
- * `profile.dependencies`, so an edition cannot pin a version the distribution did not review.
256
- * No edition means the full distribution, which is what a launcher start without a selection
257
- * materializes.
258
- *
259
- * @param facts - validated distribution facts.
260
- * @param editionId - edition to project, or undefined for the full distribution.
261
- * @returns the profile's dependencies, bundles, and override table.
262
- */
263
- function projectEdition(facts, editionId, extraExcludes = []) {
264
- const edition = editionId === void 0 ? void 0 : facts.editions[editionId];
265
- if (editionId !== void 0 && edition === void 0) throw new Error("unknown edition \"" + editionId + "\"; declared: " + (Object.keys(facts.editions).join(", ") || "(none)"));
266
- const excludedNames = new Set([...edition?.excludePackages ?? [], ...extraExcludes]);
267
- for (const name of excludedNames) if (!(facts.dependencies[name] !== void 0 || facts.bundles.includes(name))) throw new Error("exclude names " + name + ", which the distribution does not install or mount");
268
- const omittedNames = new Set(edition?.omit ?? []);
269
- const omitted = {};
270
- for (const name of omittedNames) omitted[name] = facts.omissionSpec;
271
- const dependencies = {};
272
- const sharedOfficials = Object.keys(facts.dependencies).filter((name) => name.startsWith("@deepseek-ai/dsh"));
273
- const packageNames = edition === void 0 ? [...new Set([...Object.keys(facts.dependencies), ...sharedOfficials])] : [...new Set([...edition.packages, ...sharedOfficials])];
274
- for (const name of packageNames) {
275
- if (omittedNames.has(name) || excludedNames.has(name)) continue;
276
- const key = dependencyKey(facts.dependencies, name) ?? name;
277
- const spec = facts.dependencies[key];
278
- if (spec === void 0) throw new Error(name + " is not a reviewed package");
279
- dependencies[key] = spec;
280
- }
281
- for (const [name, spec] of Object.entries(facts.redirects)) {
282
- if (omittedNames.has(name) || excludedNames.has(name)) continue;
283
- dependencies[name] = spec;
284
- }
285
- const bundles = (edition === void 0 ? [...facts.bundles] : [...new Set(edition.bundles)]).filter((name) => !excludedNames.has(name));
286
- for (const name of bundles) if (!facts.bundles.includes(name) && !(edition?.bundles ?? []).includes(name)) throw new Error("edition \"" + String(editionId) + "\" mounts bundle " + name + ", which the distribution does not declare");
287
- const overrides = {};
288
- for (const [name, spec] of Object.entries(facts.redirects)) {
289
- if (omittedNames.has(name) || excludedNames.has(name)) continue;
290
- overrides[name] = spec;
291
- }
292
- overrides["@deepseek-ai/dsh"] = facts.runtimeVersion;
293
- Object.assign(overrides, omitted);
294
- return {
295
- profileName: edition?.profile ?? "plus",
296
- dependencies,
297
- bundles,
298
- overrides,
299
- allowBuilds: facts.allowBuilds,
300
- omittedPackages: omitted
301
- };
302
- }
303
- /**
304
- * Assert every redirect target is served by a registry.
305
- *
306
- * A redirect names a published build; one that names a version the registry does not serve
307
- * installs nothing at all, and the failure surfaces as a resolver error that reads like a
308
- * packaging defect rather than a release that never happened.
309
- *
310
- * @param redirects - official name to `npm:` alias spec.
311
- * @param registry - npm registry base URL.
312
- * @returns nothing; throws on the first unavailable target.
313
- */
314
- async function assertRedirectsPublished(redirects, registry = "https://registry.npmjs.org") {
315
- for (const spec of Object.values(redirects)) {
316
- const match = /^npm:(@[^/]+\/[^@]+)@(.+)$/u.exec(spec);
317
- if (match === null) throw new Error("redirect " + spec + " is not an npm alias");
318
- const [, name, version] = match;
319
- if (name === void 0 || version === void 0) throw new Error("redirect " + spec + " is not an npm alias");
320
- if (!(await fetch(registry.replace(/\/$/u, "") + "/" + name.replace("/", "%2f") + "/" + version)).ok) throw new Error("redirect target " + name + "@" + version + " is not served by " + registry);
321
- }
322
- }
323
- /**
324
- * Write the profile manifest and the pnpm workspace the install reads.
325
- *
326
- * npm reads `overrides` from the root manifest and pnpm reads them from the workspace file, so
327
- * both are written from the same projection. Resolver settings a container needs (store location,
328
- * supported architectures, release-age window) belong to the caller and are appended to the
329
- * workspace file afterwards.
330
- *
331
- * @param directory - profile directory to write into.
332
- * @param facts - validated distribution facts.
333
- * @param editionId - edition to project.
334
- * @param extraExcludes - packages the caller drops on top of the edition's own exclusions.
335
- * @returns the projection that was written.
336
- */
337
- function writeProfileProjection(directory, facts, editionId, extraExcludes = []) {
338
- const projection = projectEdition(facts, editionId, extraExcludes);
339
- mkdirSync(directory, { recursive: true });
340
- const dependencies = {
341
- "@sparkelf/dsh-plus": facts.version,
342
- "@deepseek-ai/dsh": facts.runtimeVersion,
343
- ...projection.dependencies
344
- };
345
- writeFileSync(join(directory, "package.json"), JSON.stringify({
346
- name: "dsh-profile-" + projection.profileName,
347
- private: true,
348
- type: "module",
349
- dependencies,
350
- dsh: { profile: {
351
- bundles: projection.bundles,
352
- patchReload: "live"
353
- } }
354
- }, null, 2) + "\n");
355
- const workspace = [
356
- "packages:",
357
- " - .",
358
- "nodeLinker: hoisted",
359
- "autoInstallPeers: false",
360
- "",
361
- "overrides:",
362
- ...Object.keys(projection.overrides).sort().map((name) => " " + JSON.stringify(name) + ": " + (projection.overrides[name] ?? "")),
363
- "",
364
- "allowBuilds:",
365
- ...Object.keys(projection.allowBuilds).sort().map((name) => " " + JSON.stringify(name) + ": " + String(projection.allowBuilds[name])),
366
- ""
367
- ];
368
- writeFileSync(join(directory, "pnpm-workspace.yaml"), workspace.join("\n"));
369
- return projection;
370
- }
371
- //#endregion
372
78
  //#region lib/types/capabilities.js
373
79
  /** Capabilities offered at install time, in interview order. */
374
80
  const CAPABILITIES = [
375
81
  {
376
82
  id: "exa",
377
83
  title: "Web search (Exa)",
378
- detail: "Search the web through Exa instead of the built-in provider; needs an API key",
84
+ detail: "Route web search through the Exa provider the profile mounts; needs an API key",
379
85
  needsEndpoint: false
380
86
  },
381
87
  {
@@ -499,9 +205,11 @@ function capabilityEnvironment(answers, existing = "") {
499
205
  * The profile patch layer that turns the selected capabilities on.
500
206
  *
501
207
  * The file is data the profile's loader merges, so enabling a capability writes a
502
- * row rather than editing the deployment. An empty selection still writes the file,
503
- * because a layer that exists and mounts nothing is how a previously enabled
504
- * capability is turned back off.
208
+ * row rather than editing the deployment. Exa is the exception: the distribution
209
+ * mounts its provider unconditionally and the capability supplies only the key in the
210
+ * deployment env file, so no row is written for it. An empty selection still writes
211
+ * the file, because a layer that exists and mounts nothing is how a previously
212
+ * enabled capability is turned back off.
505
213
  *
506
214
  * The profile's own layer is a separate file with its own name: a deployment that
507
215
  * configured something by hand keeps it, and the capability rows are rewritten
@@ -558,7 +266,6 @@ function foreignPatchRows(existing) {
558
266
  function capabilityPatchLayer(answers, existing = "") {
559
267
  const enabled = new Set(answers.enabled);
560
268
  const rows = [];
561
- if (enabled.has("exa")) rows.push(" - id: web-search-exa", " name: '@deepseek-ai/dsh-web-search-exa'", " config:", " searchType: auto", " numResults: 8");
562
269
  if (enabled.has("computer-use")) 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'");
563
270
  if (enabled.has("officecli")) rows.push(" - id: officecli", " name: '@sparkelf/dsh-officecli'");
564
271
  if (enabled.has("mineru")) rows.push(" - id: mineru", " name: '@sparkelf/dsh-mineru'", " config:", " endpoint: " + (answers.mineruEndpoint ?? "http://127.0.0.1:8000/file_parse"));
@@ -566,7 +273,6 @@ function capabilityPatchLayer(answers, existing = "") {
566
273
  const foreign = foreignPatchRows(existing);
567
274
  if (rows.length > 0) lines.push("- insert:", ...rows);
568
275
  else lines.push("[]");
569
- if (enabled.has("exa")) lines.push("", "# Route web_search through Exa rather than the built-in provider.", "- id: web", " config:", " searchProvider: exa");
570
276
  if (foreign.length > 0) lines.push("", "# Rows this file carried before the capability interview; kept verbatim.", ...foreign);
571
277
  return lines.join("\n") + "\n";
572
278
  }
@@ -616,15 +322,15 @@ function readCapabilityRecord(home) {
616
322
  */
617
323
  function detectEnabledCapabilities(profilePatchText, envText) {
618
324
  const mounted = [];
619
- if (/^\s*- id: web-search-exa\s*$/mu.test(profilePatchText)) mounted.push("exa");
620
- if (/^\s*- id: mineru\s*$/mu.test(profilePatchText)) mounted.push("mineru");
621
- if (/^\s*- id: officecli\s*$/mu.test(profilePatchText)) mounted.push("officecli");
622
- if (/^\s*- id: computer-use\s*$/mu.test(profilePatchText)) mounted.push("computer-use");
623
325
  const env = [];
624
326
  for (const line of envText.split("\n")) {
625
327
  const name = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(line)?.[1];
626
328
  if (name !== void 0 && !env.includes(name)) env.push(name);
627
329
  }
330
+ if (env.includes("EXA_API_KEY") || /^\s*- id: web-search-exa\s*$/mu.test(profilePatchText)) mounted.push("exa");
331
+ if (/^\s*- id: mineru\s*$/mu.test(profilePatchText)) mounted.push("mineru");
332
+ if (/^\s*- id: officecli\s*$/mu.test(profilePatchText)) mounted.push("officecli");
333
+ if (/^\s*- id: computer-use\s*$/mu.test(profilePatchText)) mounted.push("computer-use");
628
334
  return {
629
335
  mounted,
630
336
  env
@@ -641,13 +347,6 @@ function detectEnabledCapabilities(profilePatchText, envText) {
641
347
  * @returns the insert payload lines, without the surrounding `- insert:` entry.
642
348
  */
643
349
  function capabilityRows(id) {
644
- if (id === "exa") return [
645
- " - id: web-search-exa",
646
- " name: '@deepseek-ai/dsh-web-search-exa'",
647
- " config:",
648
- " searchType: auto",
649
- " numResults: 8"
650
- ];
651
350
  if (id === "officecli") return [" - id: officecli", " name: '@sparkelf/dsh-officecli'"];
652
351
  if (id === "computer-use") return [
653
352
  " - id: computer-use",
@@ -689,7 +388,7 @@ function editCapabilityPatchLayer(existing, id, enable, mineruEndpoint) {
689
388
  " endpoint: " + (mineruEndpoint ?? "http://127.0.0.1:8000/file_parse")
690
389
  ];
691
390
  const rows = id === "mineru" && enable ? mineruRows : capabilityRows(id);
692
- const trimmed = (enable && rows !== void 0 ? insertCapabilityRows(withoutRows, rows, id === "exa") : withoutRows.text).replace(/\n+$/u, "");
391
+ const trimmed = (enable && rows !== void 0 ? insertCapabilityRows(withoutRows, rows) : withoutRows.text).replace(/\n+$/u, "");
693
392
  return trimmed === "" ? "\n" : trimmed + "\n";
694
393
  }
695
394
  /**
@@ -753,10 +452,9 @@ function dropOwnedRows(existing, ids, withSelector) {
753
452
  *
754
453
  * @param state - the layer with this capability's own rows already removed.
755
454
  * @param rows - the insert payload lines to add.
756
- * @param withSelector - whether Exa's `web` selector row must also be present.
757
455
  * @returns the layer's new text.
758
456
  */
759
- function insertCapabilityRows(state, rows, withSelector) {
457
+ function insertCapabilityRows(state, rows) {
760
458
  const lines = state.text.split("\n");
761
459
  const insertIndex = lines.findIndex((line) => /^- insert:\s*$/.test(line));
762
460
  if (insertIndex >= 0) {
@@ -777,7 +475,6 @@ function insertCapabilityRows(state, rows, withSelector) {
777
475
  if (trailing !== void 0) lines.push(trailing);
778
476
  }
779
477
  }
780
- if (withSelector && !/^\s*- id: web\s*$/mu.test(lines.join("\n"))) lines.push("", "# Route web_search through Exa rather than the built-in provider.", "- id: web", " config:", " searchProvider: exa", " fetchProvider: http");
781
478
  return lines.join("\n");
782
479
  }
783
480
  /**
@@ -1184,6 +881,7 @@ function readDistributionProfile(distributionDirectory, editionId, extraExcludes
1184
881
  runtimeVersion: facts.runtimeVersion,
1185
882
  bundles: projection.bundles,
1186
883
  dependencies: projection.dependencies,
884
+ compatibilityExemptions: facts.compatibilityExemptions,
1187
885
  allowBuilds: projection.allowBuilds,
1188
886
  overrides: projection.overrides,
1189
887
  omittedPackages: projection.omittedPackages,
@@ -1541,6 +1239,7 @@ function resolvePaths(anchor, env = process.env, editionId) {
1541
1239
  function ensureProfile(paths, editionId, extraExcludes = [], dryRun = false) {
1542
1240
  const manifestPath = join(paths.profileDirectory, "package.json");
1543
1241
  const distribution = readDistributionProfile(paths.distributionDirectory, editionId, extraExcludes);
1242
+ writeProfileCompatibility(paths.profileDirectory, distribution.compatibilityExemptions, distribution.runtimeVersion);
1544
1243
  if (existsSync(manifestPath)) {
1545
1244
  writeProfileOverrides(paths.profileDirectory, distribution.overrides, distribution.allowBuilds, {
1546
1245
  ...paths.omittedPackages,
@@ -3,6 +3,7 @@ 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
5
  import { readPatchSet } from "./patch-set.js";
6
+ import { writeProfileCompatibility } from "./manifest.js";
6
7
  import { dirname, isAbsolute, relative, resolve } from 'node:path';
7
8
  import { tmpdir } from 'node:os';
8
9
  import { satisfies, valid, validRange } from 'semver';
@@ -284,6 +285,20 @@ function prepareSelection(distributionDirectory, profileDirectory, dshRoot) {
284
285
  throw new Error('dshPlus.profile.allowBuilds.' + name + ' must be a boolean');
285
286
  allowBuilds[name] = allowed;
286
287
  }
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
+ }
287
302
  const patchPackageNames = resolvePatchPackageNames(plus);
288
303
  const dependencies = requireObject(distributionManifest.dependencies, 'Plus distribution dependencies');
289
304
  const dshManifest = readJsonObject(resolve(dshRoot, 'package.json'), 'DSH source manifest');
@@ -323,6 +338,7 @@ function prepareSelection(distributionDirectory, profileDirectory, dshRoot) {
323
338
  const pendingSourceFiles = [...sourceStates].flatMap(([file, state]) => state === 'pending' ? [file] : []);
324
339
  preflightSourcePatches(dshRoot, pendingSourceFiles);
325
340
  writeProfileRequirements(profileDirectory, profileDependencySpecs, allowBuilds);
341
+ writeProfileCompatibility(profileDirectory, compatibilityExemptions, dshVersion);
326
342
  runPnpm(profileDirectory, ['install', '--no-frozen-lockfile'], 'pnpm install Plus profile dependencies');
327
343
  const profileDependencies = Object.keys(profileDependencySpecs).sort().map((name) => {
328
344
  const installed = resolveInstalledPackage(profileDirectory, name);
@@ -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
  *