dsh-crate 0.5.2 → 0.5.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.
Files changed (46) hide show
  1. package/assets/logo.svg +11 -33
  2. package/client/client.js +2271 -561
  3. package/lib/body-progress.js +4 -3
  4. package/lib/changelog.js +15 -2
  5. package/lib/discovery-cache.js +210 -0
  6. package/lib/discovery-compatibility.js +135 -90
  7. package/lib/drain.js +28 -9
  8. package/lib/dsh-cli.js +36 -6
  9. package/lib/github-install-target.js +53 -0
  10. package/lib/hot.js +400 -33
  11. package/lib/index.js +23 -9
  12. package/lib/install.js +37 -0
  13. package/lib/patch.js +123 -73
  14. package/lib/pending-rows.js +3 -4
  15. package/lib/pnpm-compat.js +234 -2
  16. package/lib/proc-text.js +16 -1
  17. package/lib/profile.js +17 -1
  18. package/lib/recovery.js +2 -1
  19. package/lib/registry.js +24 -16
  20. package/lib/release-candidates.js +4 -0
  21. package/lib/release-updates.js +9 -2
  22. package/lib/routes.js +459 -134
  23. package/lib/themes.js +42 -9
  24. package/lib/types/body-progress.d.ts +2 -1
  25. package/lib/types/changelog.d.ts +10 -1
  26. package/lib/types/discovery-cache.d.ts +38 -0
  27. package/lib/types/discovery-compatibility.d.ts +24 -14
  28. package/lib/types/dsh-cli.d.ts +19 -2
  29. package/lib/types/github-install-target.d.ts +11 -0
  30. package/lib/types/hot.d.ts +91 -7
  31. package/lib/types/index.d.ts +17 -0
  32. package/lib/types/install.d.ts +19 -0
  33. package/lib/types/patch.d.ts +6 -2
  34. package/lib/types/profile.d.ts +4 -1
  35. package/lib/types/registry.d.ts +9 -8
  36. package/lib/types/release-candidates.d.ts +2 -0
  37. package/lib/types/routes.d.ts +2 -2
  38. package/lib/types/themes.d.ts +7 -1
  39. package/lib/types/update-notification-settings.d.ts +5 -0
  40. package/lib/types/update-notifications.d.ts +51 -0
  41. package/lib/types/updates.d.ts +5 -1
  42. package/lib/update-notification-settings.js +6 -0
  43. package/lib/update-notifications.js +166 -0
  44. package/lib/updates.js +41 -11
  45. package/lib/verify.js +24 -2
  46. package/package.json +1 -1
package/lib/drain.js CHANGED
@@ -52,6 +52,15 @@ function record(value) {
52
52
  function text(value) {
53
53
  return typeof value === 'string' && value.trim() !== '' ? value.trim() : null;
54
54
  }
55
+ /** True when the executor reported a completed change. */
56
+ function landed(result) {
57
+ const payload = record(result.payload);
58
+ return result.status >= 200 && result.status < 300 && payload?.ok !== false && payload?.cancelled !== true;
59
+ }
60
+ /** Mark a finished result as having outlived its market instance. */
61
+ function markReloaded(result) {
62
+ return { ...result, payload: { ...(record(result.payload) ?? {}), marketReloaded: true } };
63
+ }
55
64
  /** User-facing failure text, stripped of control characters and home paths. */
56
65
  function safeMessage(value) {
57
66
  const raw = text(value);
@@ -431,7 +440,13 @@ export class DrainCoordinator {
431
440
  if (this.disposeRequested)
432
441
  this.detach();
433
442
  }
434
- if (this.disposeRequested) {
443
+ if (this.disposeRequested && !operation.cancelRequested && !this.barrierBroken && landed(result)) {
444
+ // The executor returned success: the package is on disk. The market being
445
+ // unloaded afterwards does not make that a cancellation (#1151).
446
+ result = markReloaded(result);
447
+ this.finishFromResult(operation, result);
448
+ }
449
+ else if (this.disposeRequested) {
435
450
  result = {
436
451
  status: 503,
437
452
  payload: {
@@ -455,12 +470,12 @@ export class DrainCoordinator {
455
470
  payload: {
456
471
  ok: false,
457
472
  failureCode: 'AGENT_BARRIER_LOST',
458
- error: 'an Agent could not be held at the maintenance boundary; verify the installed files before retrying',
473
+ error: '有会话在操作进行中恢复了活动,文件可能已经改动。先在「已安装」里看看结果,等会话空闲后再试。 / A session became active while the operation ran, so files may have changed. Check Installed for the result, then retry once sessions are idle.',
459
474
  },
460
475
  };
461
476
  this.finish(operation, 'failed', {
462
477
  code: 'AGENT_BARRIER_LOST',
463
- message: 'an Agent could not be held at the maintenance boundary; verify the installed files before retrying',
478
+ message: '有会话在操作进行中恢复了活动,文件可能已经改动。先在「已安装」里看看结果,等会话空闲后再试。 / A session became active while the operation ran, so files may have changed. Check Installed for the result, then retry once sessions are idle.',
464
479
  }, null);
465
480
  }
466
481
  else {
@@ -479,7 +494,7 @@ export class DrainCoordinator {
479
494
  if (this.barrierBroken) {
480
495
  this.finish(operation, 'failed', {
481
496
  code: 'AGENT_BARRIER_LOST',
482
- message: 'an Agent could not be held at the maintenance boundary; the plugin operation was not started',
497
+ message: '有会话恢复了活动,这次没有改任何文件。等会话空闲后再试。 / A session became active; nothing was changed. Retry once sessions are idle.',
483
498
  }, null);
484
499
  return;
485
500
  }
@@ -491,7 +506,7 @@ export class DrainCoordinator {
491
506
  else if (this.barrierBroken) {
492
507
  this.finish(operation, 'failed', {
493
508
  code: 'AGENT_BARRIER_LOST',
494
- message: 'an Agent could not be held at the maintenance boundary; the plugin operation was not started',
509
+ message: '有会话恢复了活动,这次没有改任何文件。等会话空闲后再试。 / A session became active; nothing was changed. Retry once sessions are idle.',
495
510
  }, null);
496
511
  }
497
512
  else {
@@ -544,9 +559,13 @@ export class DrainCoordinator {
544
559
  operation.startedAt = this.now();
545
560
  this.notify(operation);
546
561
  const result = await operation.execute(operation.intent, operation.onPhase);
547
- // The executor can return success after a cancel or unload landed too
548
- // late for its last gate. The Host's state wins: the user asked to stop
549
- // or the market is gone, so this is not reported as a completed change.
562
+ // A cancel wins over a late success: the user asked to stop. An unload
563
+ // does not: a success result means the package command finished and the
564
+ // files are on disk, so it is recorded as done (#1151).
565
+ if (this.disposeRequested && !operation.cancelRequested && !this.barrierBroken && landed(result)) {
566
+ this.finishFromResult(operation, markReloaded(result));
567
+ return;
568
+ }
550
569
  if (this.disposeRequested) {
551
570
  this.finish(operation, 'cancelled', {
552
571
  code: 'MARKET_UNLOADED',
@@ -561,7 +580,7 @@ export class DrainCoordinator {
561
580
  if (this.barrierBroken) {
562
581
  this.finish(operation, 'failed', {
563
582
  code: 'AGENT_BARRIER_LOST',
564
- message: 'an Agent started work while the package operation was running; verify the installed files before retrying',
583
+ message: '有会话在操作进行中恢复了活动,文件可能已经改动。先在「已安装」里看看结果,等会话空闲后再试。 / A session became active while the operation ran, so files may have changed. Check Installed for the result, then retry once sessions are idle.',
565
584
  }, null);
566
585
  return;
567
586
  }
package/lib/dsh-cli.js CHANGED
@@ -971,20 +971,50 @@ export const BOOT_ID = `${String(process.pid)}-${String(Date.now())}`;
971
971
  * it (defense in depth on top of per-route validation — the win32 bare-dsh
972
972
  * fallback runs through a shell). Suggested in #16 by @anupamme.
973
973
  *
974
- * `^`, `~` and `=` are intentionally allowed: restore/install flows turn
975
- * manifest specs such as "dsh-better-sidebar": "^0.14.0" into targets like
974
+ * `^`, `~` and `=`: restore/install flows turn manifest specs such as
975
+ * "dsh-better-sidebar": "^0.14.0" into targets like
976
976
  * `dsh-better-sidebar@^0.14.0`, and regex-valid semver ranges must not be
977
977
  * mistaken for shell injection (whitespace and shell metacharacters remain
978
978
  * rejected — the win32 bare-dsh fallback is the reason to keep them out).
979
+ *
980
+ * `&` is deliberately absent: a bare `&` backgrounds the child and must stay
981
+ * rejected. The one shape that needs it — pnpm's monorepo selector,
982
+ * `#<ref>&path:/packages/x` — is admitted by `isSafePluginTarget` instead.
979
983
  */
980
984
  export const TARGET_RE = /^[A-Za-z0-9@:./_#+~^=-]+$/;
985
+ /** pnpm's monorepo selector inside a git target: `&path:/<subdirectory>`. */
986
+ const GIT_SUBPATH_SELECTOR_RE = /^&path:\/[A-Za-z0-9._\-/]*$/;
987
+ /**
988
+ * Whether one plugin target is safe to hand to a spawned pnpm.
989
+ *
990
+ * A target is safe when `TARGET_RE` accepts it whole, or when it is that same
991
+ * allowlisted head followed only by `&path:` selectors. pnpm spells a
992
+ * monorepo subdirectory as `github:owner/repo#<ref>&path:/packages/x`, which
993
+ * `TARGET_RE` alone rejects — every GitHub subpath install then failed as
994
+ * "unsafe plugin target".
995
+ *
996
+ * @param target - the last argv element the caller built.
997
+ * @returns true when no segment could be read as a shell separator.
998
+ */
999
+ export function isSafePluginTarget(target) {
1000
+ if (TARGET_RE.test(target))
1001
+ return true;
1002
+ if (!target.includes('&'))
1003
+ return false;
1004
+ // Every `&` must OPEN a selector: a trailing `&`, `&&`, or `& ` leaves a
1005
+ // segment that is not one, and the head itself still has to pass TARGET_RE.
1006
+ const [head = '', ...selectors] = target.split('&');
1007
+ if (!TARGET_RE.test(head))
1008
+ return false;
1009
+ return selectors.every(selector => GIT_SUBPATH_SELECTOR_RE.test(`&${selector}`));
1010
+ }
981
1011
  /** Mutating pnpm commands get the structured reporter appended. */
982
1012
  const NDJSON_COMMANDS = new Set(['add', 'remove', 'install', 'update']);
983
1013
  /** Apply profile-specific pnpm compatibility and the structured reporter. */
984
1014
  function preparePluginArgs(profileDirectory, pluginArgs) {
985
1015
  let args = pluginArgsFor(profileDirectory, [...pluginArgs]);
986
1016
  const target = args[args.length - 1] ?? '';
987
- if (!TARGET_RE.test(target)) {
1017
+ if (!isSafePluginTarget(target)) {
988
1018
  return { error: `unsafe plugin target rejected: ${JSON.stringify(target)}` };
989
1019
  }
990
1020
  if (NDJSON_COMMANDS.has(args[0]))
@@ -1096,7 +1126,7 @@ export function runHostPnpm(invocation, cwd, args) {
1096
1126
  timedOut,
1097
1127
  stdout: stdoutBytes.text(),
1098
1128
  stderr: stderrBytes.text(),
1099
- cancelled: cancelRequested,
1129
+ cancelled: cancelRequested && code !== 0,
1100
1130
  });
1101
1131
  });
1102
1132
  });
@@ -1177,7 +1207,7 @@ export function runDshPlugin(profile, pluginArgs) {
1177
1207
  timedOut,
1178
1208
  stdout: stdoutBytes.text(),
1179
1209
  stderr: stderrBytes.text(),
1180
- cancelled: cancelRequested,
1210
+ cancelled: cancelRequested && code !== 0,
1181
1211
  ...(pnpmError !== null ? { pnpmError } : {}),
1182
1212
  ...(pnpmErrorCode !== null ? { pnpmErrorCode } : {}),
1183
1213
  ...(ignoredBuilds.length > 0 ? { ignoredBuilds } : {}),
@@ -1285,7 +1315,7 @@ export function createDesktopPluginRuntime(service, activeProfileDir, invokingDi
1285
1315
  timedOut,
1286
1316
  stdout: stdoutBytes.text(),
1287
1317
  stderr: stderrBytes.text(),
1288
- cancelled: active.userCancelled,
1318
+ cancelled: active.userCancelled && failed,
1289
1319
  ...(ignoredBuilds.length > 0 ? { ignoredBuilds } : {}),
1290
1320
  ...(pnpmError !== null ? { pnpmError } : {}),
1291
1321
  ...(pnpmErrorCode !== null ? { pnpmErrorCode } : {}),
@@ -0,0 +1,53 @@
1
+ import { resolveHeadCommit } from './accelerate.js';
2
+ import { readBodyWhileProgressing } from './body-progress.js';
3
+ import { marketFetch } from './net.js';
4
+ import { githubRoutesFor, rememberGithubRoute, throughProxy } from './regions.js';
5
+ import { NPM_NAME_RE } from './sources.js';
6
+ const ROOT_TARGET_RE = /^github:([A-Za-z0-9_.-]+\/([A-Za-z0-9_.-]+))(?:#([0-9a-f]{40}))?$/;
7
+ const FETCH_TIMEOUT_MS = 4000;
8
+ const MAX_MANIFEST_BYTES = 256 * 1024;
9
+ /**
10
+ * A package-like catalog name can point to the workspace root by mistake
11
+ * (#1208). Check a commit's manifest before handing that root to the host:
12
+ * Desktop can unpack it before refusing a package with no bundle.
13
+ *
14
+ * The curated catalog also lists entire collections (#18) and uses display
15
+ * names for ordinary Git plugins. Only a declared workspace with no DSH
16
+ * surface and a different root name gives enough evidence to refuse the add.
17
+ */
18
+ export async function mismatchedWorkspaceRoot(target, name, region) {
19
+ const source = ROOT_TARGET_RE.exec(target);
20
+ if (source === null || !NPM_NAME_RE.test(name) || source[2].toLowerCase() === name)
21
+ return null;
22
+ const repo = source[1];
23
+ const commit = source[3] ?? await resolveHeadCommit(repo, region);
24
+ if (commit === null)
25
+ return null;
26
+ const url = `https://raw.githubusercontent.com/${repo}/${commit}/package.json`;
27
+ const signal = AbortSignal.timeout(FETCH_TIMEOUT_MS);
28
+ for (const route of githubRoutesFor('raw', region)) {
29
+ if (signal.aborted)
30
+ break;
31
+ try {
32
+ const response = await marketFetch(throughProxy(route, url), { signal, redirect: 'manual' });
33
+ if (!response.ok) {
34
+ await response.body?.cancel();
35
+ continue;
36
+ }
37
+ const bytes = await readBodyWhileProgressing(response, FETCH_TIMEOUT_MS, 'GitHub package manifest', MAX_MANIFEST_BYTES);
38
+ const manifest = JSON.parse(new TextDecoder().decode(bytes));
39
+ if (manifest === null || typeof manifest !== 'object' || Array.isArray(manifest))
40
+ continue;
41
+ rememberGithubRoute('raw', route);
42
+ const paths = Array.isArray(manifest.workspaces) ? manifest.workspaces : manifest.workspaces?.packages;
43
+ return manifest.dsh === undefined && typeof manifest.name === 'string' && NPM_NAME_RE.test(manifest.name)
44
+ && manifest.name !== name && Array.isArray(paths) && paths.some(path => typeof path === 'string' && path.trim() !== '')
45
+ ? manifest.name
46
+ : null;
47
+ }
48
+ catch {
49
+ // A missing or inaccessible manifest cannot establish what the root is.
50
+ }
51
+ }
52
+ return null;
53
+ }