dsh-crate 0.0.0-stage → 0.5.0

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 (132) hide show
  1. package/LICENSE +27 -0
  2. package/README.md +288 -2
  3. package/README.zh.md +263 -0
  4. package/UPDATE-API-V1.md +207 -0
  5. package/assets/logo.svg +37 -0
  6. package/client/client.js +18964 -0
  7. package/cordis.patch.yml +4 -0
  8. package/lib/accelerate.js +194 -0
  9. package/lib/agents.js +67 -0
  10. package/lib/backup.js +688 -0
  11. package/lib/body-progress.js +173 -0
  12. package/lib/catalog-local-match.js +160 -0
  13. package/lib/catalog-npm.js +180 -0
  14. package/lib/changelog.js +462 -0
  15. package/lib/channels.js +64 -0
  16. package/lib/check.js +1557 -0
  17. package/lib/compatibility.js +243 -0
  18. package/lib/crate-catalog.js +179 -0
  19. package/lib/diagnostics.js +49 -0
  20. package/lib/discovery-compatibility.js +447 -0
  21. package/lib/drain-journal.js +164 -0
  22. package/lib/drain.js +1043 -0
  23. package/lib/dsh-cli.js +1373 -0
  24. package/lib/dsh-install.js +259 -0
  25. package/lib/entry-identity.js +85 -0
  26. package/lib/gist.js +369 -0
  27. package/lib/groups.js +108 -0
  28. package/lib/home-paths.js +29 -0
  29. package/lib/host-recovery.js +187 -0
  30. package/lib/hot.js +871 -0
  31. package/lib/http.js +252 -0
  32. package/lib/index.js +394 -0
  33. package/lib/install.js +1147 -0
  34. package/lib/lifecycle.js +37 -0
  35. package/lib/log-redaction.js +24 -0
  36. package/lib/log.js +204 -0
  37. package/lib/ndjson.js +154 -0
  38. package/lib/net.js +174 -0
  39. package/lib/official-desktop.js +619 -0
  40. package/lib/order.js +284 -0
  41. package/lib/patch.js +943 -0
  42. package/lib/pending-rows.js +142 -0
  43. package/lib/pending-updates.js +346 -0
  44. package/lib/pnpm-compat.js +972 -0
  45. package/lib/presets.js +282 -0
  46. package/lib/probe-context.js +20 -0
  47. package/lib/proc-text.js +69 -0
  48. package/lib/profile.js +1978 -0
  49. package/lib/recovery.js +1059 -0
  50. package/lib/region-probe.js +93 -0
  51. package/lib/regions.js +283 -0
  52. package/lib/registry.js +308 -0
  53. package/lib/release-candidates.js +115 -0
  54. package/lib/release-updates.js +70 -0
  55. package/lib/restart.js +688 -0
  56. package/lib/routes.js +7960 -0
  57. package/lib/settings.js +164 -0
  58. package/lib/shelfry-catalog.js +179 -0
  59. package/lib/snapshot.js +506 -0
  60. package/lib/source-migration.js +164 -0
  61. package/lib/sources.js +1005 -0
  62. package/lib/state.js +38 -0
  63. package/lib/store.js +163 -0
  64. package/lib/themes.js +350 -0
  65. package/lib/trial.js +125 -0
  66. package/lib/types/accelerate.d.ts +85 -0
  67. package/lib/types/agents.d.ts +52 -0
  68. package/lib/types/backup.d.ts +171 -0
  69. package/lib/types/body-progress.d.ts +94 -0
  70. package/lib/types/catalog-local-match.d.ts +39 -0
  71. package/lib/types/catalog-npm.d.ts +77 -0
  72. package/lib/types/changelog.d.ts +131 -0
  73. package/lib/types/channels.d.ts +56 -0
  74. package/lib/types/check.d.ts +353 -0
  75. package/lib/types/compatibility.d.ts +83 -0
  76. package/lib/types/crate-catalog.d.ts +48 -0
  77. package/lib/types/diagnostics.d.ts +29 -0
  78. package/lib/types/discovery-compatibility.d.ts +145 -0
  79. package/lib/types/drain-journal.d.ts +25 -0
  80. package/lib/types/drain.d.ts +306 -0
  81. package/lib/types/dsh-cli.d.ts +481 -0
  82. package/lib/types/dsh-install.d.ts +106 -0
  83. package/lib/types/entry-identity.d.ts +68 -0
  84. package/lib/types/gist.d.ts +79 -0
  85. package/lib/types/groups.d.ts +34 -0
  86. package/lib/types/home-paths.d.ts +13 -0
  87. package/lib/types/host-recovery.d.ts +95 -0
  88. package/lib/types/hot.d.ts +405 -0
  89. package/lib/types/http.d.ts +114 -0
  90. package/lib/types/index.d.ts +52 -0
  91. package/lib/types/install.d.ts +463 -0
  92. package/lib/types/lifecycle.d.ts +14 -0
  93. package/lib/types/log-redaction.d.ts +2 -0
  94. package/lib/types/log.d.ts +43 -0
  95. package/lib/types/ndjson.d.ts +52 -0
  96. package/lib/types/net.d.ts +94 -0
  97. package/lib/types/official-desktop.d.ts +59 -0
  98. package/lib/types/order.d.ts +100 -0
  99. package/lib/types/patch.d.ts +218 -0
  100. package/lib/types/pending-rows.d.ts +81 -0
  101. package/lib/types/pending-updates.d.ts +161 -0
  102. package/lib/types/pnpm-compat.d.ts +102 -0
  103. package/lib/types/presets.d.ts +94 -0
  104. package/lib/types/probe-context.d.ts +14 -0
  105. package/lib/types/proc-text.d.ts +29 -0
  106. package/lib/types/profile.d.ts +551 -0
  107. package/lib/types/recovery.d.ts +342 -0
  108. package/lib/types/region-probe.d.ts +50 -0
  109. package/lib/types/regions.d.ts +134 -0
  110. package/lib/types/registry.d.ts +160 -0
  111. package/lib/types/release-candidates.d.ts +42 -0
  112. package/lib/types/release-updates.d.ts +15 -0
  113. package/lib/types/restart.d.ts +279 -0
  114. package/lib/types/routes.d.ts +130 -0
  115. package/lib/types/settings.d.ts +112 -0
  116. package/lib/types/shelfry-catalog.d.ts +48 -0
  117. package/lib/types/snapshot.d.ts +93 -0
  118. package/lib/types/source-migration.d.ts +100 -0
  119. package/lib/types/sources.d.ts +391 -0
  120. package/lib/types/state.d.ts +20 -0
  121. package/lib/types/store.d.ts +47 -0
  122. package/lib/types/themes.d.ts +46 -0
  123. package/lib/types/trial.d.ts +61 -0
  124. package/lib/types/update-api-v1.d.ts +83 -0
  125. package/lib/types/updates.d.ts +273 -0
  126. package/lib/types/verify.d.ts +277 -0
  127. package/lib/update-api-v1.js +273 -0
  128. package/lib/updates.js +981 -0
  129. package/lib/verify.js +904 -0
  130. package/locale/en.json +5 -0
  131. package/locale/zh.json +6 -0
  132. package/package.json +113 -4
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Minimal HTTP helpers shared by every market route: JSON serialization,
3
+ * same-origin enforcement for mutating endpoints, and a size-capped JSON
4
+ * body reader.
5
+ */
6
+ import type { IncomingMessage, ServerResponse } from 'node:http';
7
+ /** Write a JSON payload with no-store caching. */
8
+ export declare function sendJson(response: ServerResponse, status: number, payload: unknown): void;
9
+ /**
10
+ * The host's own request gate, when it publishes one (#603).
11
+ *
12
+ * DSH's Host Connection service exposes `requestRejection(request)`: its
13
+ * Host/Origin fence, then its browser login — 403, 401, or `undefined` for a
14
+ * request it would admit to its own API. The market's routes never passed
15
+ * through it: they are exact registrations on the bare webServer (see the
16
+ * trusted-hosts note below), so with the login on, a client holding no session
17
+ * could still read the market's state and install or remove plugins — which on
18
+ * a deployment behind a proxy or a tunnel is code execution on that machine for
19
+ * anyone who can reach the port. The fix is not a second login: it is asking
20
+ * the one the host already runs.
21
+ *
22
+ * `undefined` source (a host older than this service, 0.1.0-rc.8) leaves every
23
+ * route exactly as it was.
24
+ */
25
+ export type HostRequestGate = (request: IncomingMessage) => number | undefined;
26
+ /** Point the market at the host's request gate. Returns the previous source. */
27
+ export declare function setRequestGateSource(source: () => HostRequestGate | undefined): () => HostRequestGate | undefined;
28
+ /**
29
+ * Answer the request with the host's rejection, if it has one.
30
+ * @returns true when the request was refused and answered here.
31
+ */
32
+ export declare function refuseUnadmitted(request: IncomingMessage, response: ServerResponse): boolean;
33
+ /** Point the fence at the host's declared authorities. Returns the previous source. */
34
+ export declare function setTrustedHostsSource(source: () => readonly string[]): () => readonly string[];
35
+ /**
36
+ * The authorities this deployment declared, as the fence reads them right now.
37
+ *
38
+ * `sameOrigin` consults them through the private source above. The privileged
39
+ * routes (the backup export, the self-uninstall, the one-click restart) need
40
+ * the same list, and a second private copy of it would be a second thing to
41
+ * keep in step — the fence that guards the market's ordinary routes and the
42
+ * fence that guards its privileged ones have to agree about what this
43
+ * deployment serves.
44
+ *
45
+ * Read per request, exactly as the source itself is: a deployment that
46
+ * declares an authority later is honoured from that request on.
47
+ */
48
+ export declare function declaredTrustedHosts(): readonly string[];
49
+ /**
50
+ * Whether a request authority is one of the declared ones.
51
+ *
52
+ * Mirrors @deepseek-ai/dsh-client-connection's rule, because the two fences
53
+ * have to agree: an entry with an explicit port matches that exact authority,
54
+ * a port-less entry matches the hostname on any port (the shape the CLI
55
+ * derives for IP-literal LAN serving, where the bound port may be assigned by
56
+ * the OS). Both sides compare through WHATWG normalization, so case and a
57
+ * redundant `:80` never decide trust.
58
+ */
59
+ export declare function trustedAuthority(host: string, trustedHosts: readonly string[]): boolean;
60
+ /**
61
+ * True when the request's Origin, IF IT HAS ONE, matches its Host — required
62
+ * on every POST route.
63
+ *
64
+ * An absent Origin is allowed (#648). The check exists to stop another web
65
+ * page from driving this loopback API, and the Fetch spec has browsers send
66
+ * `Origin` on every POST — including same-origin and cross-origin form
67
+ * submissions. A request that arrives WITHOUT it therefore did not come from
68
+ * a page at all, and a non-browser client can set any Origin it likes, so
69
+ * refusing the header's absence bought nothing while breaking a whole
70
+ * supported host: the Desktop app's own proxy strips `origin`, `host`,
71
+ * `cookie` and `sec-fetch-site` before forwarding to the in-process host and
72
+ * injects a cookie only that host can sign. Every mutating request from the
73
+ * Desktop build was answered 403 `untrusted origin`.
74
+ *
75
+ * What still holds after the change, and is the part worth keeping:
76
+ *
77
+ * - a cross-site page is refused — its Origin is present and different;
78
+ * - `Origin: null` (a sandboxed iframe, a `data:` document) is refused, because
79
+ * `null` is a present-but-unparseable origin, not an absent one;
80
+ * - a same-host-but-different-port request is refused, except that a loopback
81
+ * Host accepts a port-less same-hostname Origin (#1031: Chrome 151+ omits
82
+ * the port on loopback Origins, and the dsh core fence follows the same
83
+ * rule);
84
+ * - an EMPTY Origin is refused too: the header being present and unparseable
85
+ * is not the same statement as its being absent, and only absence is what
86
+ * a stripping proxy produces.
87
+ *
88
+ * The header's absence is a statement about the client, not about intent, and
89
+ * the intent is the only thing this can judge.
90
+ *
91
+ * @param request - the incoming request.
92
+ * @returns whether the request may mutate market state.
93
+ */
94
+ /**
95
+ * Whether a `Host` header names a loopback authority (#678).
96
+ *
97
+ * `Origin === Host` alone does not stop a DNS-rebinding page: the attacker
98
+ * serves their page from `evil.com`, resolves that name to 127.0.0.1, and
99
+ * the browser then connects to the loopback listener while sending
100
+ * `Origin: http://evil.com` AND `Host: evil.com` — an equality that holds
101
+ * for the attacker. `Host` is the one header the attack cannot forge, so it
102
+ * is what has to name a loopback authority.
103
+ *
104
+ * `localhost` is included because browsers and RFC 6761 pin it to loopback;
105
+ * a subdomain like `localhost.evil.com` does not match, and the port is
106
+ * dropped before comparing.
107
+ *
108
+ * @param host - the request's `Host` header.
109
+ * @returns whether it names a loopback authority.
110
+ */
111
+ export declare function loopbackAuthority(host: string | undefined): boolean;
112
+ export declare function sameOrigin(request: IncomingMessage): boolean;
113
+ /** Read and parse a JSON request body, rejecting anything over 4 KiB. */
114
+ export declare function readJsonBody(request: IncomingMessage, maxBytes?: number): Promise<unknown>;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * dsh-crate host entry: mounts the market's HTTP routes once the profile
3
+ * composes the webServer and shell services.
4
+ */
5
+ import type { Context } from '@deepseek-ai/cordis';
6
+ import { type MarketConfig } from './routes.ts';
7
+ export declare const name = "dsh-crate";
8
+ /** Optional cordis.yml configuration; profile defaults to `web`. */
9
+ export type Config = Partial<Pick<MarketConfig, 'profile' | 'allowRestart' | 'maxSnapshots' | 'buildEnv'>>;
10
+ /**
11
+ * The launcher's `profileContext` in one line, for the exported log (#744).
12
+ *
13
+ * Only the facts that decide the branch: whether the service is there, and
14
+ * whether its shape is one `launchedProfile` accepts. Never the directory
15
+ * itself — the log already carries the profile path where it is needed.
16
+ */
17
+ export declare function describeProfileContext(value: unknown): string;
18
+ /**
19
+ * The deployment's declared authorities, read from the host (#729).
20
+ *
21
+ * DSH's own /api fence accepts loopback OR an authority the operator declared
22
+ * (`dsh web --trusted-host <name>`, plus the LAN literals the CLI derives when
23
+ * bound to 0.0.0.0). The market's routes are `exact` registrations on the bare
24
+ * webServer, and exact matches win over that fence's prefix, so they never
25
+ * pass through it — and a loopback-only rule of its own made every mutating
26
+ * route 403 on any deployment reached by a name.
27
+ *
28
+ * The `connection` service is optional: a host without it leaves the fence
29
+ * exactly as it was, which is the behaviour every release so far has had.
30
+ * @returns a restore function for the effect that installed it.
31
+ */
32
+ export declare function useTrustedHosts(ctx: Context): () => void;
33
+ /**
34
+ * Feed host detection the install anchor the launcher published.
35
+ *
36
+ * The CLI is located by walking `process.argv[1]` up to its package, and the
37
+ * official Desktop by Electron's resources directory. An embedded host — a
38
+ * packaged app that boots the dsh core tree in-process — has neither, so
39
+ * `dshHostInfo()` answered null there and every host-version surface read
40
+ * "unknown": Discover's compatibility filter (#473), the pre-install refusal
41
+ * (#404), and the exported log's `dsh host:` line (#426). The launcher does
42
+ * publish where its runtime is (`profileContext.installAnchor`), so hand
43
+ * that to detection. Read through a live source, not a mount-time copy:
44
+ * launchers may provide `profileContext` after the market mounts (the same
45
+ * timing problem the origins above handle), and a frozen value would answer
46
+ * "unknown" for the whole session on exactly those hosts.
47
+ *
48
+ * Exported for the specs that cover this wiring.
49
+ * @returns a restore function for the effect that installed it.
50
+ */
51
+ export declare function useLauncherInstallAnchor(ctx: Context): () => void;
52
+ export declare function apply(ctx: Context, config?: Config): void;
@@ -0,0 +1,463 @@
1
+ /**
2
+ * Install orchestration: collection-repo retargeting, post-install
3
+ * validation that keeps broken pieces from bricking the next boot, and
4
+ * update staleness detection. Every function takes the plugin runner as a
5
+ * parameter so tests can substitute a recording fake.
6
+ */
7
+ import type { InstallResult, PluginRunner } from './dsh-cli.ts';
8
+ /**
9
+ * One-shot bypass for pnpm's fresh-release hold; scoped to a single command.
10
+ *
11
+ * Spelled like the .npmrc key, not the camelCase pnpm-workspace.yaml one:
12
+ * from pnpm 12.3.0 (the native CLI) `--config.minimumReleaseAge=0` is
13
+ * silently ignored — no unknown-option error — so the retry ran without the
14
+ * bypass and failed exactly like the first attempt (#600).
15
+ * `--config.minimum-release-age=0` is honoured by pnpm 10, 11 and 12 alike.
16
+ * That is specific to this key, not a rule for `--config.*`: the native CLI
17
+ * ignores `--config.fetch-timeout` in both spellings, which is why
18
+ * FETCH_TIMEOUT_OVERRIDE below is not respelled here (#615).
19
+ */
20
+ export declare const RELEASE_AGE_OVERRIDE = "--config.minimum-release-age=0";
21
+ /**
22
+ * Longer per-request fetch timeout for one retried command. pnpm's default
23
+ * 60-second limit aborts large tarball downloads (github: sources fetch the
24
+ * WHOLE repo even for a `#path:` subdirectory plugin) on slow networks; a
25
+ * plain retry fails again at the same limit, so the recovery re-runs with
26
+ * this override once. Scoped to a single command like RELEASE_AGE_OVERRIDE.
27
+ *
28
+ * pnpm 12 ignores this flag on the command line in either spelling (#615).
29
+ * On the CLI runner, runDshPlugin repeats every `--config.<key>` override
30
+ * as PNPM_CONFIG_<KEY>, which pnpm 11 and 12 both read, so the retried
31
+ * command really does get the longer limit there. The Desktop runtime hands
32
+ * its host argv only, so on a Desktop host the retry still depends on that
33
+ * host's pnpm reading the flag. The flag stays: pnpm 11 and earlier read
34
+ * it, and it costs nothing on the versions that do not.
35
+ */
36
+ export declare const FETCH_TIMEOUT_OVERRIDE = "--config.fetchTimeout=600000";
37
+ /**
38
+ * Stop pnpm downloading a plugin's peer dependencies (#289 by @00080000).
39
+ *
40
+ * The last resort for a peer that cannot be downloaded because it does not
41
+ * exist on any registry: the dsh runtime injects several `@deepseek-ai/*`
42
+ * packages and never publishes them, and since pnpm 8 `auto-install-peers`
43
+ * defaults on, so pnpm walks the peer list and 404s on one.
44
+ *
45
+ * Only on the retry, never by default. Turning it off wholesale would also
46
+ * stop pnpm installing the peers a plugin legitimately needs from npm, and
47
+ * that failure would surface much later — as a missing module at runtime
48
+ * rather than a clear error at install time. Narrow beats early here.
49
+ *
50
+ * Verified against pnpm 10.29.3: `peerDependencyRules.ignoreMissing` does
51
+ * NOT prevent the fetch (it only silences the warning), so this flag is the
52
+ * only lever that actually works.
53
+ *
54
+ * pnpm 12 ignores this flag on the command line too (12.4.1 auto-installs
55
+ * the peer regardless); runDshPlugin repeats it as
56
+ * PNPM_CONFIG_AUTO_INSTALL_PEERS, which 12 reads (#615).
57
+ */
58
+ export declare const AUTO_INSTALL_PEERS_OFF = "--config.auto-install-peers=false";
59
+ /**
60
+ * Whether an unresolvable package is a host peer pnpm went looking for on
61
+ * its own, rather than something the profile actually asks for.
62
+ *
63
+ * The same 404 means two different things and wants two different answers.
64
+ * A `@deepseek-ai/*` package that IS in the profile manifest is a ghost
65
+ * entry — left by an earlier failed operation, or hand-added — and the user
66
+ * has to remove that line; retrying would only fail again. One that is NOT
67
+ * in the manifest was never asked for by anybody: pnpm reached it by walking
68
+ * an installed plugin's peerDependencies, which in this ecosystem name what
69
+ * the runtime provides rather than what npm carries.
70
+ *
71
+ * Reading the manifest is what separates them, so this cannot live in the
72
+ * pure classifier.
73
+ */
74
+ export declare function isUnpublishedHostPeer(pkg: string | undefined, profile: string, explicitDir?: string): boolean;
75
+ /**
76
+ * Run one plugin command with automatic recovery from three known pnpm traps:
77
+ *
78
+ * - pnpm-major drift (#20 bug 2): a modules directory built by a different
79
+ * pnpm major fails mutation; pnpm's documented remedy is one `install` to
80
+ * recreate it — do that silently and retry the original command once.
81
+ * - release-age lockfile lock (#39): once a too-young release is in the
82
+ * lockfile, pnpm 11 rejects EVERY later add/remove during verification —
83
+ * retry once with the one-shot minimumReleaseAge bypass (safe: the young
84
+ * package is already installed; the bypass only lets pnpm touch the
85
+ * lockfile again).
86
+ * - per-request fetch timeout: large tarballs (github: sources fetch the
87
+ * whole repo even for a `#path:` subdirectory) on slow networks blow
88
+ * pnpm's default 60-second limit; a plain retry fails again at the same
89
+ * limit, so retry once with a longer fetchTimeout.
90
+ *
91
+ * Any recognized failure that survives gets its bilingual explanation
92
+ * appended to stderr so the UI shows an actionable message instead of a
93
+ * wall of text (#20 bug 3). Cancelled runs are never recovered.
94
+ *
95
+ * The release-age bypass can be declined (`releaseAgeBypass: false`). Its
96
+ * safety argument above assumes the young package is already installed; a
97
+ * fresh install pinned to the registry's latest (#594) is the one case
98
+ * where it is not — there the bypass would be what installs the young
99
+ * version, over a minimumReleaseAge the profile set on purpose — so the
100
+ * install route declines it and falls back to the bare name instead.
101
+ *
102
+ * `marketFlags: false` says the host runs pnpm itself and takes no options
103
+ * from us (the official Desktop bridge, #732). The four recoveries below
104
+ * each decorate a command with an option, so on such a host they are skipped
105
+ * rather than sent and refused — and because their classifier messages say
106
+ * the market retried, the note appended at the end says it did not.
107
+ */
108
+ export declare function withHoistRecovery(run: PluginRunner, profile: string, pluginArgs: string[], profileDirectory?: string, options?: {
109
+ releaseAgeBypass?: boolean;
110
+ marketFlags?: boolean;
111
+ preserveProfilePolicy?: boolean;
112
+ }): Promise<InstallResult>;
113
+ /**
114
+ * The tail of the diagnostics file the dsh CLI pointed at, when it pointed at
115
+ * one (#672).
116
+ *
117
+ * `dsh plugin` writes pnpm's entire output to a file and prints only
118
+ * `dsh: pnpm failed; diagnostics: <path>`. For a failure the market cannot
119
+ * classify, that line is all it has — the reasons people reported (#244,
120
+ * #192, #138) were all "the UI shows one unhelpful line" for causes that
121
+ * were written down somewhere the UI never looked.
122
+ *
123
+ * Bounded on purpose: absolute paths only, a regular file, and at most the
124
+ * last {@link DIAGNOSTICS_TAIL_BYTES}. The path comes from our own child, but
125
+ * the market only ever needs the end of a log, and reading an arbitrary
126
+ * amount of an arbitrary file is not worth anything it could add.
127
+ *
128
+ * @returns the path and the text, or null when the output names no readable
129
+ * diagnostics file.
130
+ */
131
+ export declare function diagnosticsTail(result: {
132
+ stdout: string;
133
+ stderr: string;
134
+ }): {
135
+ path: string;
136
+ text: string;
137
+ } | null;
138
+ /**
139
+ * Whether pnpm never started at all, so the profile cannot have been touched.
140
+ *
141
+ * Worth its own question because the update route answers a failed run by
142
+ * reinstalling the previous build and reporting loudly when it cannot verify
143
+ * that (#502 by @Ztyss): three updates in a row told the user their profile
144
+ * might be broken and to inspect it before restarting, when in fact nothing
145
+ * had been written — the command line could not launch pnpm, so package.json
146
+ * and node_modules were exactly as they had been.
147
+ * @param result - the failed run.
148
+ * @returns true when the failure happened before pnpm could run.
149
+ */
150
+ export declare function pnpmNeverStarted(result: InstallResult): boolean;
151
+ /**
152
+ * Whether pnpm refused a too-young release without writing to the profile.
153
+ *
154
+ * Same nature as wroteNothing / pnpmNeverStarted for the update route's
155
+ * rollback (#919): pnpm DID start, read the lockfile, then exited 1 on
156
+ * ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION (or the sibling mature-match /
157
+ * resolution-policy shapes). Nothing was installed or removed, so restoring
158
+ * "the previous build" is alarm about an untouched profile — and on the
159
+ * official desktop bridge it pairs every wait with a false
160
+ * "restoration could not be verified" line that covers the real reason.
161
+ * @param result - the failed run.
162
+ * @returns true when the failure is pnpm's fresh-release gate.
163
+ */
164
+ export declare function pnpmRefusedYoungRelease(result: InstallResult): boolean;
165
+ /**
166
+ * Whether an environment variable names the top-level fresh-release window
167
+ * and carries a plain non-negative integer.
168
+ *
169
+ * DSH Desktop sets `pnpm_config_minimum_release_age=0` for every pnpm call,
170
+ * so a numeric environment value is a window the market can follow — not an
171
+ * unverifiable external policy (#1053).
172
+ *
173
+ * Measured 2026-10-30 against a release published 8 hours earlier, with
174
+ * `minimumReleaseAge: 100000` + `minimumReleaseAgeStrict: true` in the
175
+ * workspace file (so a block or a pass is unmistakable):
176
+ *
177
+ * - pnpm 11.7.0 and 12.16.1 honour `pnpm_config_minimum_release_age` — the
178
+ * install goes through, i.e. the environment overrides even a strict
179
+ * workspace policy — and ignore `npm_config_minimum_release_age`;
180
+ * - pnpm 10.20.0 ignores the `pnpm_config_` spelling (the `npm_config_` one
181
+ * is what it reads).
182
+ *
183
+ * That is why this value outranks the file here rather than merely adding to
184
+ * it: on the engines the Desktop ships, it IS the effective policy.
185
+ */
186
+ export declare function isNumericReleaseAgeWindow(key: string, value: string | undefined): boolean;
187
+ /**
188
+ * The profile's fresh-release wait window in ms (#919).
189
+ *
190
+ * Reads `minimumReleaseAge` (minutes) from pnpm-workspace.yaml, then
191
+ * `minimum-release-age` from `.npmrc`. A numeric environment window — the
192
+ * Desktop manager sets one for every pnpm call — takes precedence over both,
193
+ * because that is the value its pnpm actually uses (#1053). A key that is
194
+ * present but not a number returns null — callers must not invent a remaining
195
+ * wait. When neither file nor the environment names the key, pnpm's default
196
+ * 1440 minutes applies.
197
+ */
198
+ export declare function readMinimumReleaseAgeMs(profile: string, explicitDir?: string): number | null;
199
+ /**
200
+ * The `name@version` pnpm actually refused, when its refusal named one (#944).
201
+ *
202
+ * {@link remainingReleaseAgeWait} reads only the timestamp on the same line,
203
+ * which is fine while the offender IS the package being installed. It is not
204
+ * always: a plugin install can be refused by a DIFFERENT, younger package that
205
+ * is already in the lockfile, because pnpm verifies the whole lockfile before
206
+ * any mutation (#39). #944 hit exactly that — updating `dsh-cost-meter` failed
207
+ * with `dsh-crate@1.66.44` named in the error, and the note then told the user
208
+ * to wait out *the plugin's* version, which was not the version holding them.
209
+ *
210
+ * Only the entry pnpm prints in its violation line is read (` <name>@<version>
211
+ * was published at …`), so this cannot invent an offender from unrelated text.
212
+ * Null when no such line is present — callers must then keep their existing
213
+ * wording rather than guess.
214
+ */
215
+ export declare function refusedReleaseAgePackage(output: string): {
216
+ name: string;
217
+ version: string;
218
+ } | null;
219
+ /**
220
+ * How long is left in the fresh-release wait, when pnpm named the publish
221
+ * time in its refusal (#919). Null when the output has no usable timestamp.
222
+ */
223
+ export declare function remainingReleaseAgeWait(output: string, now?: number, windowMs?: number): number | null;
224
+ /**
225
+ * Whether pnpm failed because the running host holds the package's files
226
+ * open, so nothing pnpm runs from inside that host can replace them.
227
+ *
228
+ * Worth asking for the same reason as pnpmNeverStarted: the update route
229
+ * answers a failed run by reinstalling the previous build, and that reinstall
230
+ * performs the very rename that just failed, against the same open handles
231
+ * (#608 by @Euezb). It cannot win — pnpm retries the rename for about three
232
+ * minutes before giving up — and the route then told the user their profile
233
+ * might be broken and to inspect it before restarting, when nothing had been
234
+ * reinstalled and the previous build was still there to be checked.
235
+ * @param result - the failed run.
236
+ * @returns true when pnpm was stopped by files the host holds open.
237
+ */
238
+ export declare function pnpmBlockedByOpenFiles(result: InstallResult): boolean;
239
+ /**
240
+ * Whether a failed run is the running host colliding with a second profile
241
+ * boot (#975).
242
+ *
243
+ * Market install / update / uninstall spawn `dsh plugin …`. On a live
244
+ * `dsh web` that child can boot the profile again, bind the same port, and
245
+ * exit 1 AFTER pnpm has already written. The signature is DSH's own boot
246
+ * failure — `listen EADDRINUSE` plus `Full diagnostics` pointing at a
247
+ * `startup-*.log` — not a pnpm classifier code. All three pieces are
248
+ * required so a stray EADDRINUSE or an unrelated diagnostics line cannot
249
+ * flip a real failure into success.
250
+ */
251
+ export declare function isHostPortCollision(result: {
252
+ stdout: string;
253
+ stderr: string;
254
+ }): boolean;
255
+ /**
256
+ * Whether this install left at least one new, loadable plugin on disk (#975).
257
+ *
258
+ * Read-only half of the #18 guard: a name that landed without a dsh surface
259
+ * or entry is not this operation's intent, so the caller still rolls back.
260
+ * The route then runs the full validator on the success path.
261
+ */
262
+ export declare function installApplied(profile: string, before: ReadonlySet<string>, explicitDir?: string): boolean;
263
+ /**
264
+ * Whether this update changed the installed version or git commit (#975).
265
+ *
266
+ * Same question `isStaleUpdate` asks, but a missing after-value is "did not
267
+ * land", not "not stale". The package must still be on disk.
268
+ *
269
+ * Git commits use the same two reads as `gitIdentityCommit` in routes.ts:
270
+ * `type: git` first, then the archive/codeload URL a floating `github:`
271
+ * install actually leaves.
272
+ */
273
+ export declare function updateApplied(check: {
274
+ profile: string;
275
+ name: string;
276
+ isGit: boolean;
277
+ beforeVersion: string | null;
278
+ beforeCommit: string | null;
279
+ spec?: string;
280
+ explicitDir?: string;
281
+ }): boolean;
282
+ /**
283
+ * The most specific description of a failed run available, for logs.
284
+ *
285
+ * pnpm's structured error beats the stderr tail whenever there is one — see
286
+ * withHoistRecovery above for why the tail is nearly worthless here.
287
+ */
288
+ export declare function failureDetail(result: InstallResult, limit?: number): string;
289
+ /**
290
+ * Some registry entries point at collection repos whose actual plugin lives
291
+ * in a subdirectory — the root has no package.json (or a workspace root with
292
+ * no dsh surface), and pnpm installs the bare fileset with exit 0. Detect
293
+ * that junk install, drop it, and re-add each plugin subdirectory through
294
+ * pnpm's `#path:` selector (#18).
295
+ * @returns overall success (true when nothing needed retargeting).
296
+ */
297
+ export declare function retargetCollections(run: PluginRunner, profile: string, before: Set<string>, target: string, explicitDir?: string): Promise<boolean>;
298
+ /**
299
+ * Fake-success guard (#18): validate every package the install added. A
300
+ * piece without a dsh manifest or without its declared entry artifact
301
+ * (source-only checkout, build blocked by pnpm allowBuilds) would brick the
302
+ * next boot, so it is removed on the spot.
303
+ *
304
+ * Since #122 this also covers duplicate loader entry ids: cordis refuses to
305
+ * load a tree containing two entries with one id, so a TUI bundle landing in
306
+ * a web profile (both declare `id: storage`) leaves DSH unable to START —
307
+ * an error naming neither plugin, from which the market's own page is
308
+ * unreachable. Such a package is removed like any other bricking piece.
309
+ * @returns names added by this run, names kept, names removed as broken,
310
+ * and the id conflicts found. `added` is reported separately from `keep`
311
+ * because an EMPTY `added` is a different failure from "everything added was
312
+ * unloadable": it means the install reported success without touching the
313
+ * profile at all, which is a broken plugin-command channel rather than
314
+ * anything wrong with the plugin (#258).
315
+ */
316
+ export declare function validateAddedPlugins(run: PluginRunner, profile: string, before: Set<string>, explicitDir?: string, hostDirectory?: string | null): Promise<{
317
+ added: string[];
318
+ keep: string[];
319
+ removedBroken: string[];
320
+ conflicts: {
321
+ name: string;
322
+ id: string;
323
+ owner: string;
324
+ }[];
325
+ }>;
326
+ /**
327
+ * The node_modules root of the DSH host deployment `directory` belongs to.
328
+ *
329
+ * CLI layouts install the host as `<prefix>/node_modules/@deepseek-ai/dsh`,
330
+ * so the shared root is two dirname steps up; a flat Desktop layout keeps
331
+ * the host package at the deployment root (#662's
332
+ * `<desktop-app>\dependencies\dsh`), with its pnpm-managed node_modules
333
+ * directly beside its package.json. `dshHostInfo()` already distinguishes
334
+ * the two — this is pure path arithmetic on whichever directory it returned.
335
+ */
336
+ export declare function hostNodeModulesRoot(directory: string): string;
337
+ /**
338
+ * Normalize a link target for path comparison: restore the UNC device form
339
+ * (`\\?\UNC\server\share` back to `\\server\share` — stripped of its prefix
340
+ * it is no longer absolute and resolve() would re-root it against the
341
+ * cwd), then remove the NT device prefixes `\\?\` and the subst-style
342
+ * `\??\` mklink stores. Measured on Node 24/win32: readlinkSync returns
343
+ * the plain absolute path, so these branches only matter for links created
344
+ * outside Node — but a comparison must not silently miss because of them.
345
+ */
346
+ export declare function normalizedLinkTarget(target: string): string;
347
+ /**
348
+ * Remove the host-side bridge link a confirmed uninstall leaves dangling
349
+ * (#662). The official boot projects profile packages into the host
350
+ * deployment's node_modules as links (Junction or SymbolicLink — lstat
351
+ * reports both as symlinks) and never reclaims them, and `dsh plugin
352
+ * remove` knows nothing about them, so without this the link outlives the
353
+ * package it pointed at and every tool that lstats its way through
354
+ * node_modules (rg first among them) fails on it.
355
+ *
356
+ * The gate is deliberately total: only `<host node_modules>/<name>` is ever
357
+ * touched, only when that entry is a link whose normalized target is
358
+ * exactly this profile's copy of `name`, and only when that copy is really
359
+ * gone — a live bridge for a package that is still installed must survive.
360
+ * A null `hostDirectory` (no host locatable — a plain `dsh web` from a
361
+ * global install) is a documented no-op.
362
+ *
363
+ * @returns whether a dangling bridge was removed. Never throws: the removal
364
+ * this cleans up after already succeeded, and a cleanup failure must not
365
+ * fail the uninstall that triggered it.
366
+ */
367
+ export declare function removeDanglingHostBridge(name: string, profileDirectory: string, hostDirectory: string | null): boolean;
368
+ /**
369
+ * Group flat `{id, owner}` conflict hits by the installed plugin that owns
370
+ * them. What the user has to decide is which PLUGINS to uninstall, not which
371
+ * ids to resolve, so one row per owner is the unit the market renders and
372
+ * acts on. Flattening the other way (one row per id) also misattributes when
373
+ * a candidate clashes with several installed plugins at once.
374
+ * @param conflicts flat hits as returned by {@link validateAddedPlugins}.
375
+ * @returns one entry per owner, owners and ids both in first-seen order.
376
+ */
377
+ export declare function groupConflictsByOwner(conflicts: readonly {
378
+ id: string;
379
+ owner: string;
380
+ }[]): {
381
+ owner: string;
382
+ ids: string[];
383
+ }[];
384
+ /**
385
+ * Whether a clean-exit update actually changed nothing — pnpm's
386
+ * minimumReleaseAge silently keeps the old version and exits 0 when the new
387
+ * release is "too young" (#13, #22), so a clean exit alone does not mean the
388
+ * update happened.
389
+ */
390
+ export declare function isStaleUpdate(check: {
391
+ isGit: boolean;
392
+ beforeVersion: string | null;
393
+ afterVersion: string | null;
394
+ beforeCommit: string | null;
395
+ afterCommit: string | null;
396
+ }): boolean;
397
+ /**
398
+ * The package pnpm's fetcher refused to prepare because its build script is
399
+ * not allowlisted — `The git-hosted package "name@2.8.0" needs to execute
400
+ * build scripts but is not in the "allowBuilds" allowlist.` Null when the
401
+ * output is not this failure. Unlike ignored-builds, the package is NOT in
402
+ * node_modules yet (the fetcher rejects before materialization, #68).
403
+ */
404
+ export declare function parsePrepareNotAllowed(stdout: string, stderr: string): string | null;
405
+ /**
406
+ * The allowBuilds key pnpm itself printed for a prepare refusal, when it
407
+ * printed one (#698).
408
+ *
409
+ * pnpm 11 ends ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED with the exact line to
410
+ * add — measured on 11.8.0 against the reported plugin:
411
+ *
412
+ * For example:
413
+ * allowBuilds:
414
+ * @dsh-external/dsh-super-injector@https://codeload.github.com/…/tar.gz/<sha>: true
415
+ *
416
+ * For a TRANSITIVE git dependency that key is the only knowledge anyone has
417
+ * of its source: the package is in neither node_modules, package.json nor
418
+ * the catalog. pnpm 10 prints an `onlyBuiltDependencies` example with the
419
+ * bare name instead, and gets null here — the bare name is what it needs.
420
+ *
421
+ * @returns the key, or null when the output carries no allowBuilds example.
422
+ */
423
+ export declare function parsePrepareKey(stdout: string, stderr: string): string | null;
424
+ /**
425
+ * The allowBuilds key pnpm derives for one ignored build — its own
426
+ * `allowBuildKeyFromIgnoredBuild`, transcribed.
427
+ *
428
+ * pnpm keeps the whole dep path when what follows the name's `@` is not a
429
+ * semver version (a git remote, a codeload archive, a tarball URL — all of them
430
+ * contain `:`, `/` or `#`), and collapses to the bare name otherwise. It writes
431
+ * the result into `allowBuilds` and matches an existing entry against it
432
+ * verbatim, so the market has to agree with it exactly: a bare name authorizes
433
+ * a registry dependency and nothing else, while a git dependency is authorized
434
+ * only by its full `name@git+…#<sha>` dep path.
435
+ */
436
+ export declare function allowBuildKeyFromIgnoredBuild(depPath: string): string;
437
+ /**
438
+ * The packages pnpm reported as having their build scripts ignored, each with
439
+ * the allowBuilds key pnpm itself keys that decision by.
440
+ *
441
+ * pnpm prints the dependency's full dep path — `name@git+https://…#<sha>` for
442
+ * a git source, `name@1.2.3` for a registry one — and `parseIgnoredBuilds`
443
+ * below has always collapsed both to the bare name. That is right for a
444
+ * registry dependency and drops the only key a git dependency is authorized
445
+ * by, which is what left approve-and-retry unable to make progress on one.
446
+ *
447
+ * `name` is what the approve-builds route matches its request against; `key`
448
+ * is the entry to write. They are equal for a registry dependency.
449
+ *
450
+ * Entries may also arrive inside pnpm's ndjson error line, where the sentence
451
+ * is followed by `","code":…`; the walk stops at the first character no dep
452
+ * path can contain, so the surrounding JSON is not swallowed.
453
+ */
454
+ export declare function parseIgnoredBuildEntries(stdout: string, stderr: string): Array<{
455
+ name: string;
456
+ key: string;
457
+ }>;
458
+ /**
459
+ * Package names pnpm reported as having their build scripts ignored
460
+ * ("Ignored build scripts: esbuild, koffi."). Empty when none.
461
+ * (#6 by @qichuang321.)
462
+ */
463
+ export declare function parseIgnoredBuilds(stdout: string, stderr: string): string[];
@@ -0,0 +1,14 @@
1
+ /** Bound asynchronous loader work without pretending that timeout cancels it. */
2
+ export declare class LifecycleWaitError extends Error {
3
+ }
4
+ /**
5
+ * The refusal `waitForLifecycle` gives a second caller while the first call's
6
+ * work is still in flight. A distinct subclass, so a caller can tell "the same
7
+ * operation I already know about has not finished" from a fresh failure
8
+ * without matching on message text (#788). It stays a LifecycleWaitError, so
9
+ * every existing `instanceof LifecycleWaitError` check keeps its meaning.
10
+ */
11
+ export declare class LifecyclePendingError extends LifecycleWaitError {
12
+ }
13
+ /** Never start a second mutation on a loader object whose earlier work is pending. */
14
+ export declare function waitForLifecycle<T>(key: object, start: () => T | Promise<T>, label: string): Promise<T>;
@@ -0,0 +1,2 @@
1
+ /** Mask only this user's home prefix, leaving the rest of each path intact. */
2
+ export declare function redactHomePaths(text: string): string;