dsh-boost 0.1.2 → 0.1.4

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/dist/index.js CHANGED
@@ -83,6 +83,162 @@ function isVerifiedHostVersion(version) {
83
83
  };
84
84
  return core(version) === core(VERIFIED_HOST_VERSION);
85
85
  }
86
+ /**
87
+ * Parse the semver subset a declared `engines.dsh` range uses.
88
+ *
89
+ * The host's compatibility preflight runs `semver.satisfies(..., {
90
+ * includePrerelease: true })`. This module cannot import `semver` at runtime
91
+ * (it is a dev dependency, and the published graph must stay host-free), so the
92
+ * guard implements only what the manifest's range needs: `major.minor.patch`,
93
+ * an optional prerelease, and the comparison operators. Anything else is
94
+ * unparsable, and an unparsable range makes the guard advisory rather than
95
+ * wrong.
96
+ */
97
+ function parseSemVer(value) {
98
+ const match = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(value.trim());
99
+ if (match === null)
100
+ return undefined;
101
+ const majorText = match[1];
102
+ const minorText = match[2];
103
+ const patchText = match[3];
104
+ if (majorText === undefined || minorText === undefined || patchText === undefined) {
105
+ return undefined;
106
+ }
107
+ const major = Number(majorText);
108
+ const minor = Number(minorText);
109
+ const patch = Number(patchText);
110
+ if (!Number.isSafeInteger(major) || !Number.isSafeInteger(minor) || !Number.isSafeInteger(patch)) {
111
+ return undefined;
112
+ }
113
+ const prerelease = [];
114
+ const prereleaseText = match[4];
115
+ if (prereleaseText !== undefined) {
116
+ for (const identifier of prereleaseText.split('.')) {
117
+ if (/^\d+$/.test(identifier)) {
118
+ const numeric = Number(identifier);
119
+ if (!Number.isSafeInteger(numeric))
120
+ return undefined;
121
+ prerelease.push(numeric);
122
+ }
123
+ else {
124
+ prerelease.push(identifier);
125
+ }
126
+ }
127
+ }
128
+ return { major, minor, patch, prerelease };
129
+ }
130
+ /** Semver precedence for one prerelease identifier (numeric sorts first). */
131
+ function compareIdentifier(left, right) {
132
+ if (typeof left === 'number' && typeof right === 'number')
133
+ return left - right;
134
+ if (typeof left === 'number')
135
+ return -1;
136
+ if (typeof right === 'number')
137
+ return 1;
138
+ return left < right ? -1 : left > right ? 1 : 0;
139
+ }
140
+ /** Semver precedence: negative when `left` is older, positive when newer. */
141
+ function compareSemVer(left, right) {
142
+ for (const key of ['major', 'minor', 'patch']) {
143
+ const delta = left[key] - right[key];
144
+ if (delta !== 0)
145
+ return delta;
146
+ }
147
+ if (left.prerelease.length === 0 && right.prerelease.length === 0)
148
+ return 0;
149
+ // A release outranks every prerelease of the same core version.
150
+ if (left.prerelease.length === 0)
151
+ return 1;
152
+ if (right.prerelease.length === 0)
153
+ return -1;
154
+ const length = Math.max(left.prerelease.length, right.prerelease.length);
155
+ for (let index = 0; index < length; index += 1) {
156
+ const leftPart = left.prerelease[index];
157
+ const rightPart = right.prerelease[index];
158
+ // A shorter identifier list is lower when every shared part is equal.
159
+ if (leftPart === undefined)
160
+ return -1;
161
+ if (rightPart === undefined)
162
+ return 1;
163
+ const delta = compareIdentifier(leftPart, rightPart);
164
+ if (delta !== 0)
165
+ return delta;
166
+ }
167
+ return 0;
168
+ }
169
+ /**
170
+ * Whether `version` satisfies `range`, or `undefined` when either cannot be
171
+ * parsed.
172
+ *
173
+ * Supports the space-separated AND comparators (`>=`, `>`, `<=`, `<`, `=`, or
174
+ * bare) and `||` alternatives. An unevaluable range is not a mismatch: the
175
+ * guard is advisory, and warning on a range it does not understand would be
176
+ * worse than staying quiet.
177
+ */
178
+ function satisfiesRange(version, range) {
179
+ const parsed = parseSemVer(version);
180
+ if (parsed === undefined)
181
+ return undefined;
182
+ let evaluable = false;
183
+ for (const alternative of range.split('||')) {
184
+ const comparators = alternative.trim().split(/\s+/).filter(token => token !== '');
185
+ if (comparators.length === 0)
186
+ continue;
187
+ let matched = true;
188
+ let valid = true;
189
+ for (const token of comparators) {
190
+ const match = /^(>=|<=|>|<|=)?(.+)$/.exec(token);
191
+ const bound = match === null ? undefined : parseSemVer(match[2] ?? '');
192
+ if (match === null || bound === undefined) {
193
+ valid = false;
194
+ break;
195
+ }
196
+ const order = compareSemVer(parsed, bound);
197
+ const operator = match[1] ?? '=';
198
+ const satisfied = operator === '>='
199
+ ? order >= 0
200
+ : operator === '<='
201
+ ? order <= 0
202
+ : operator === '>'
203
+ ? order > 0
204
+ : operator === '<'
205
+ ? order < 0
206
+ : order === 0;
207
+ if (!satisfied) {
208
+ matched = false;
209
+ break;
210
+ }
211
+ }
212
+ if (!valid)
213
+ continue;
214
+ evaluable = true;
215
+ if (matched)
216
+ return true;
217
+ }
218
+ return evaluable ? false : undefined;
219
+ }
220
+ /**
221
+ * The `engines.dsh` range this build declares, read from the package manifest.
222
+ *
223
+ * The manifest is the one authority for "hosts this plugin accepts": the host's
224
+ * preflight reads the same field, so a guard with a hard-coded range would drift
225
+ * from the declaration it is supposed to enforce (review row 51). Memoised; a
226
+ * missing or malformed manifest makes the guard advisory.
227
+ */
228
+ let declaredHostRange = null;
229
+ function declaredHostRangeOf() {
230
+ if (declaredHostRange !== null)
231
+ return declaredHostRange;
232
+ try {
233
+ const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
234
+ const range = manifest.engines?.dsh;
235
+ declaredHostRange = typeof range === 'string' && range.trim() !== '' ? range.trim() : undefined;
236
+ }
237
+ catch {
238
+ declaredHostRange = undefined;
239
+ }
240
+ return declaredHostRange;
241
+ }
86
242
  /**
87
243
  * Stable host code: the resolved host version is not the verified one.
88
244
  *
@@ -167,25 +323,47 @@ function hostVersionOf(ctx) {
167
323
  }
168
324
  }
169
325
  /**
170
- * Log the resolved host version once and warn on a mismatch.
326
+ * Log the resolved host version once, warning only outside `engines.dsh`.
171
327
  *
172
328
  * The version guard is deliberately advisory. npm does not read `engines.dsh`;
173
329
  * the host enforces it only through the managed-install compatibility preflight,
174
330
  * which does not run for every composition. A warning here is the only signal
175
331
  * an embedded or mixed tree gets, and it must never stop the plugin: a version
176
332
  * this build did not verify may still work.
333
+ *
334
+ * The check is against the **declared range**, not exact equality (review row
335
+ * 51): `engines.dsh` is `>=0.2.2-rc.4 <0.2.3-0`, and the host's preflight
336
+ * accepts rc.5 and the 0.2.2 release. Warning on those told operators to
337
+ * distrust a host the manifest itself accepts. Inside the range but not the
338
+ * verified build is an informational note; outside it is the warning.
177
339
  */
178
340
  function reportHostVersion(ctx) {
179
341
  const version = hostVersionOf(ctx);
342
+ const range = declaredHostRangeOf();
180
343
  if (version === undefined) {
181
- ctx.logger?.info?.(`dsh-boost: dsh host version unknown (verified against ${VERIFIED_HOST_VERSION}); compatibility cannot be checked`);
344
+ ctx.logger?.info?.(`dsh-boost: dsh host version unknown (verified against ${VERIFIED_HOST_VERSION}${range === undefined ? '' : `; declared range ${range}`}); compatibility cannot be checked`);
345
+ return;
346
+ }
347
+ if (range === undefined) {
348
+ ctx.logger?.info?.(`dsh-boost: dsh host ${version}; the package declares no engines.dsh range, so compatibility cannot be checked`);
349
+ return;
350
+ }
351
+ const accepted = satisfiesRange(version, range);
352
+ if (accepted === undefined) {
353
+ ctx.logger?.info?.(`dsh-boost: dsh host ${version}; the declared range ${range} is not a semver range this guard understands, so compatibility cannot be checked`);
354
+ return;
355
+ }
356
+ if (!accepted) {
357
+ ctx.logger?.warn?.(`dsh-boost: ${ERR_HOST_VERSION_MISMATCH}: this build is verified against dsh ${VERIFIED_HOST_VERSION} (declared range ${range}), but the host reports ${version}, which is outside it; continuing, but a renamed host API may make the plugin inert`);
182
358
  return;
183
359
  }
184
360
  if (isVerifiedHostVersion(version)) {
185
361
  ctx.logger?.info?.(`dsh-boost: dsh host ${version} (verified)`);
186
362
  return;
187
363
  }
188
- ctx.logger?.warn?.(`dsh-boost: ${ERR_HOST_VERSION_MISMATCH}: this build is verified against dsh ${VERIFIED_HOST_VERSION}, but the host reports ${version}; continuing, but a renamed host API may make the plugin inert`);
364
+ // Inside the range the manifest accepts, so this is not a mismatch — just not
365
+ // the exact build the plugin was exercised against.
366
+ ctx.logger?.info?.(`dsh-boost: dsh host ${version} is within the declared range ${range}, but not the exact build this was verified against (${VERIFIED_HOST_VERSION}); continuing`);
189
367
  }
190
368
  /**
191
369
  * Duplicate applies observed in this process.
@@ -1165,10 +1343,57 @@ export function apply(ctx, config) {
1165
1343
  return meter.kind() === 'host';
1166
1344
  },
1167
1345
  get hasSpill() {
1168
- return spillService() !== undefined;
1346
+ // `refresh`, not the memo: a status call reports the host *now*, so a
1347
+ // provider that was replaced or disposed since the last write must not
1348
+ // keep `hasSpill` true (review rows 6 and 50).
1349
+ return spillService.refresh() !== undefined;
1350
+ },
1351
+ get spillUsable() {
1352
+ // Presence is not capability: `{}` resolves, so `hasSpill` alone would
1353
+ // report a healthy projection path until the first `saveText` fails
1354
+ // (review row 50). Probe the method shape, never call it — a status
1355
+ // read must not write a spill artifact. A broken binding is dropped so
1356
+ // a replaced provider is picked up by the next status.
1357
+ try {
1358
+ const backend = spillService.refresh();
1359
+ if (backend === undefined)
1360
+ return false;
1361
+ if (typeof backend.saveText === 'function')
1362
+ return true;
1363
+ spillService.reset();
1364
+ return false;
1365
+ }
1366
+ catch {
1367
+ spillService.reset();
1368
+ return false;
1369
+ }
1169
1370
  },
1170
1371
  get hasWorkspaceRegistry() {
1171
- return registry() !== undefined;
1372
+ // Live fact: a registry that appeared, disappeared or was replaced
1373
+ // since `apply` must be reported as it is now.
1374
+ return registry.refresh() !== undefined;
1375
+ },
1376
+ get workspaceRegistryBroken() {
1377
+ // `resolve.ts` swallows a throwing `list()` per call by design: one
1378
+ // invisible session must not crash a hook. That swallow is exactly why
1379
+ // the failure needs a status-time probe, or every session is judged
1380
+ // invisible while `degraded` stays empty (review row 6). A non-array is
1381
+ // the same fail-closed answer in the resolver, so it is the same
1382
+ // degradation here. `refresh` re-reads the binding so a repaired
1383
+ // provider clears the code on the very next status.
1384
+ try {
1385
+ const backend = registry.refresh();
1386
+ if (backend === undefined)
1387
+ return false;
1388
+ if (Array.isArray(backend.list()))
1389
+ return false;
1390
+ registry.reset();
1391
+ return true;
1392
+ }
1393
+ catch {
1394
+ registry.reset();
1395
+ return true;
1396
+ }
1172
1397
  },
1173
1398
  };
1174
1399
  const fixedOverhead = measureBoostFixedOverhead();