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,56 @@
1
+ /**
2
+ * The market's release channels: which build of ITSELF it offers.
3
+ *
4
+ * Only the market follows this. Other plugins are never pulled from a
5
+ * prerelease on the strength of a setting the user made about the market —
6
+ * opting into early builds is volunteering to try THIS plugin early, not to
7
+ * be handed every other author's unreleased work.
8
+ *
9
+ * The model lives in its own module because it is the part with rules
10
+ * rather than plumbing: three channels, one of them hidden, a mapping to
11
+ * npm dist-tags, and a resolution order that has already been got wrong
12
+ * once (see `resolveChannel`).
13
+ */
14
+ /** A channel the market can follow. */
15
+ export type Channel = 'stable' | 'beta' | 'dev';
16
+ /**
17
+ * The npm dist-tag each channel installs from.
18
+ *
19
+ * `dev` is published straight from a branch with no git tag behind it, so a
20
+ * version carries a timestamp and a short SHA (`1.15.0-dev.20260818-3f1432e`)
21
+ * and is never reused. That is what makes a dev build disposable: nothing in
22
+ * the repository's history refers to it.
23
+ */
24
+ export declare const DIST_TAG: Record<Channel, string>;
25
+ /**
26
+ * Every channel a user may pick. All three, always.
27
+ *
28
+ * `dev` was behind a developer-mode switch for one version, on the reasoning
29
+ * that a build published straight off a branch should not sit beside
30
+ * "stable" looking like a third degree of caution. The switch cost more than
31
+ * it bought: a stored mode, a route to change it, a rule for what happens to
32
+ * a dev choice when it is turned off, and a control whose own purpose needed
33
+ * explaining. A plainly labelled option a user can read is simpler than a
34
+ * hidden one plus the machinery that hides it — the label does the work the
35
+ * gate was doing.
36
+ */
37
+ export declare const CHANNELS: readonly Channel[];
38
+ /** Narrow an untrusted value to a Channel, or null. */
39
+ export declare function asChannel(value: unknown): Channel | null;
40
+ /**
41
+ * Which channel applies right now.
42
+ *
43
+ * A choice on record always wins — including "stable" while a prerelease is
44
+ * running, which is the only way back off a channel. Only the ABSENCE of a
45
+ * choice is derived, and then from what is actually running: installing
46
+ * `dsh-crate@beta` by hand IS the subscription, and treating that as
47
+ * "stable" costs updates rather than just clarity — on the stable channel
48
+ * `latest` (1.13.1) is not newer than an installed 1.14.0-beta.1, so the
49
+ * market answers "up to date" and the next beta is never offered.
50
+ *
51
+ * Which makes `undefined` load-bearing: it has to survive both the settings
52
+ * schema (no `.default`) and state.json (field omitted) or "never chose"
53
+ * silently becomes "chose stable".
54
+ *
55
+ */
56
+ export declare function resolveChannel(setting: Channel | undefined, version: string): Channel;
@@ -0,0 +1,353 @@
1
+ /**
2
+ * Profile composition diagnostics — issue #98 (phase 1): the check-only
3
+ * "plugin loading layer and conflict view".
4
+ *
5
+ * Pure filesystem analysis of one dsh profile directory; no processes, no
6
+ * network, no writes. It answers, for the profile the market is serving:
7
+ *
8
+ * 1. What is the actual bundle stack (dsh.profile.bundles order) and where
9
+ * does each layer come from (official in-box bundle vs community, the
10
+ * dependency spec, the resolved directory)?
11
+ * 2. Which loader entry ids does the composed tree contain, and are any
12
+ * duplicated across layers (the "duplicate loader entry id" boot failure
13
+ * from #98)? Which rows does a later layer override?
14
+ * 3. Does any installed plugin pull a DSH host core package
15
+ * (@deepseek-ai/dsh, @deepseek-ai/dsh-tools, @deepseek-ai/cordis, …) in
16
+ * as an ordinary dependency — the dsh-excel-chat failure mode where the
17
+ * plugin's copy gets hoisted to the profile root and shadows the host's
18
+ * version (tool calls die, minimal preset fails to mount)?
19
+ * 4. Are there multiple versions of one core package in the lockfile, and
20
+ * do plugin peerDependencies ranges match the resolved core version?
21
+ * 5. Do effective user/home patch entries reference npm package roots that
22
+ * are installed in the profile-visible node_modules ancestry?
23
+ *
24
+ * The composition step mirrors @deepseek-ai/dsh-app-boot's applyEntryPatches
25
+ * (same js-yaml dialect incl. `!!js` scalars), so the rows reported here are
26
+ * what actually mounts at boot.
27
+ */
28
+ export { findDshInstallDir } from './dsh-install.ts';
29
+ /** Boot-breaking or confirmed problems vs informational warnings. */
30
+ export interface CheckSummary {
31
+ ok: boolean;
32
+ errors: string[];
33
+ warnings: string[];
34
+ }
35
+ /** One layer of the bundle stack, in `dsh.profile.bundles` order. */
36
+ export interface BundleLayer {
37
+ name: string;
38
+ /** Dependency spec from the profile package.json (npm range, git, link:…). */
39
+ source: string;
40
+ /** 'official' = in-box dsh bundle; 'community' = everything else. */
41
+ kind: 'official' | 'community';
42
+ /** Resolved package directory; null when the package is not installed. */
43
+ directory: string | null;
44
+ /** Absolute path of the layer's patch file; null when undeclared/missing. */
45
+ patchPath: string | null;
46
+ /** Every declared patch file, in declaration order; `patchPath` is the first (#688). */
47
+ patchPaths: string[];
48
+ /**
49
+ * An in-box bundle whose directory could not be located — a gap in what
50
+ * this process can see, not a defect in the profile (#369). Distinct from
51
+ * `error`, which asserts the profile will not boot.
52
+ */
53
+ unresolvedInbox?: boolean;
54
+ /** Why this layer cannot load at boot (missing dir / no dsh.bundle / …). */
55
+ error: string | null;
56
+ /** Loader entry ids this bundle's patch inserts. */
57
+ entries: string[];
58
+ /** The patch file exists but could not be parsed as the entry-list dialect. */
59
+ parseError: string | null;
60
+ /** Author-declared ordering constraints (issue #98 phase 2), when present. */
61
+ order?: {
62
+ before?: string[];
63
+ after?: string[];
64
+ /** Violated rules for THIS bundle in the current stack order. */
65
+ conflicts?: Array<{
66
+ name: string;
67
+ reason: string;
68
+ }>;
69
+ };
70
+ }
71
+ /** One loader row of the composed tree, with the layer that introduced it. */
72
+ export interface LoaderRow {
73
+ id: string;
74
+ /** Bundle package name, 'user-patch' (profile cordis.patch.yml) or 'home-patch'. */
75
+ layer: string;
76
+ kind: 'insert' | 'patch';
77
+ name?: string;
78
+ }
79
+ /**
80
+ * A directory in `node_modules` that no declaration accounts for and that
81
+ * cannot be used either (#663).
82
+ *
83
+ * The shape this exists for: an update blocked by open files leaves the
84
+ * target directory without its `package.json`, and the declaration that
85
+ * pointed at it is gone (the market drops it so the next start can compose).
86
+ * What remains is invisible — nothing in the profile references it, and
87
+ * `pnpm install` will not repair an empty shell ("Already up to date", #663)
88
+ * — so a user who goes looking finds an empty directory and no explanation.
89
+ */
90
+ export interface ResidualDirectory {
91
+ /** Package name when it can be read, else the directory's own name. */
92
+ name: string;
93
+ /** Path relative to the profile, for the diagnostics listing. */
94
+ path: string;
95
+ kind: 'incomplete-package' | 'tmp-directory';
96
+ /**
97
+ * The profile still declares it. Then this is not junk: composition will
98
+ * try to load it, and the bundle layers above already report why it fails.
99
+ */
100
+ declared: boolean;
101
+ }
102
+ /** An id present in more than one composed row — the #98 duplicate-id boot failure. */
103
+ export interface DuplicateId {
104
+ id: string;
105
+ /** Every layer that inserts/defines this id. */
106
+ layers: string[];
107
+ count: number;
108
+ }
109
+ /** A non-insert patch row that merged into an existing entry (later layer wins). */
110
+ export interface OverrideRow {
111
+ id: string;
112
+ layer: string;
113
+ /** Layers that introduced the targeted entry earlier in the stack. */
114
+ overriddenLayers: string[];
115
+ }
116
+ /** A patch row that matched nothing at boot (dsh warns and skips it). */
117
+ export interface OrphanRow {
118
+ id: string;
119
+ layer: string;
120
+ reason: string;
121
+ }
122
+ /** Directional verdict for one confirmed peer mismatch (issue #201 diagnostics). */
123
+ export interface PeerRisk {
124
+ plugin: string;
125
+ peer: string;
126
+ range: string;
127
+ resolved: string;
128
+ direction: 'belowMin' | 'aboveMax';
129
+ }
130
+ export interface PeerWarning {
131
+ plugin: string;
132
+ peer: string;
133
+ range: string;
134
+ resolved: string;
135
+ reason: 'aboveMax' | 'optional';
136
+ }
137
+ /** classifyPeer result: risk / warning / none — none means informational. */
138
+ export type PeerVerdict = {
139
+ kind: 'risk';
140
+ risk: PeerRisk;
141
+ } | {
142
+ kind: 'warning';
143
+ warning: PeerWarning;
144
+ } | {
145
+ kind: 'none';
146
+ };
147
+ /** A plugin peerDependencies range vs the resolved version. */
148
+ export interface PeerMismatch {
149
+ plugin: string;
150
+ name: string;
151
+ range: string;
152
+ resolved: string | null;
153
+ /** False = confirmed incompatible; null = could not be evaluated. */
154
+ satisfied: boolean | null;
155
+ /**
156
+ * The declaring plugin marked this peer `optional` in
157
+ * `peerDependenciesMeta`. Carried so the summary can hold the same line
158
+ * `classifyPeer` already does: an optional peer that does not match is
159
+ * the plugin saying "I work without this", not a broken install (#275).
160
+ */
161
+ optional?: boolean;
162
+ /**
163
+ * The directional verdict, attached by `/dsh-crate/check` for rows that
164
+ * did not match. It is computed on the server because the client cannot
165
+ * read `peerDependenciesMeta` off disk, and the tiering would otherwise
166
+ * have to be guessed from the range string (#201).
167
+ */
168
+ verdict?: PeerVerdict;
169
+ }
170
+ /**
171
+ * Loader entries sharing one NAME across DIFFERENT layers — the Loader
172
+ * registers plugins by name, so a later layer's row with the same name
173
+ * shadows the earlier one at runtime. Same-layer rows sharing a name are
174
+ * routine (a bundle defining several entries under one name) and are never
175
+ * reported here. Unlike duplicate ids (report.duplicates), which fail the
176
+ * boot outright, shadowing names only decide which entry wins at runtime.
177
+ */
178
+ export interface DuplicateName {
179
+ name: string;
180
+ /** Every layer that inserts/defines a row with this name. */
181
+ layers: string[];
182
+ count: number;
183
+ }
184
+ /** Distinct resolved versions of one core package found in the lockfile. */
185
+ export interface MultiVersion {
186
+ name: string;
187
+ versions: string[];
188
+ /** Version hoisted at the profile root, when present. */
189
+ hoisted: string | null;
190
+ }
191
+ /** The full check report for one profile. */
192
+ export interface CheckReport {
193
+ profile: string;
194
+ scannedAt: number;
195
+ bundles: BundleLayer[];
196
+ rows: LoaderRow[];
197
+ duplicates: DuplicateId[];
198
+ duplicateNames: DuplicateName[];
199
+ overrides: OverrideRow[];
200
+ orphans: OrphanRow[];
201
+ peerMismatches: PeerMismatch[];
202
+ multiVersion: MultiVersion[];
203
+ /** Before/after rule conflicts in the CURRENT bundle order (issue #98 phase 2). */
204
+ orderConflicts: Array<{
205
+ name: string;
206
+ reason: string;
207
+ }>;
208
+ /** LOOT-style auto-fix: a community order satisfying every declared rule. */
209
+ suggestedOrder: {
210
+ ok: true;
211
+ order: string[];
212
+ } | {
213
+ ok: false;
214
+ cycle: string[];
215
+ } | null;
216
+ /**
217
+ * Leftover directories: incomplete packages and pnpm temp directories.
218
+ * Reported structurally rather than as warnings — same reasoning as
219
+ * `duplicateNames` above: a leftover that nothing references harms nothing
220
+ * today, and a warning on every profile that ever had an interrupted
221
+ * install would train people to ignore the list.
222
+ */
223
+ residuals: ResidualDirectory[];
224
+ summary: CheckSummary;
225
+ }
226
+ export interface CheckOptions {
227
+ /** DSH host install dir; auto-detected from the CLI entry or Desktop resources when omitted. */
228
+ dshInstallDir?: string;
229
+ /** Harness home for the home-level patch layer; defaults to $DSH_HOME or ~/.dsh. */
230
+ homeDir?: string;
231
+ }
232
+ /** Parse entry-list source with the DSH dialect; null when it is not a list. */
233
+ export declare function parsePatchText(text: string): unknown[] | null;
234
+ /** Parse one entry-list patch file with the DSH dialect; null when unreadable. */
235
+ export declare function parsePatchFile(path: string): unknown[] | null;
236
+ /** DSH host core packages: what the dsh installation ships under @deepseek-ai. */
237
+ export declare function corePackageNames(dshInstallDir: string | null): Set<string>;
238
+ /** Compare two semver strings: negative | zero | positive (prerelease < release of same base). */
239
+ /** Whether a string is a well-formed semver `compareSemver` can order. */
240
+ export declare function isSemver(value: string): boolean;
241
+ export declare function compareSemver(a: string, b: string): number;
242
+ /**
243
+ * Minimal range matcher for the peer-range check: `*`, exact (with or without =),
244
+ * ^, ~, >=, >, <=, <, whitespace-separated pairs, and `||` alternatives. Anything else
245
+ * returns null (unknown — reported, not asserted).
246
+ *
247
+ * Prerelease handling follows npm's semver rule, evaluated at the comparator
248
+ * SET level (one `||` alternative is one set): a version carrying a
249
+ * prerelease tag only satisfies a set when at least one comparator in that
250
+ * set shares the version's [major, minor, patch] tuple AND carries a
251
+ * prerelease of its own; then every comparator is checked normally. So
252
+ * `^0.1.0` never matches `0.2.0-rc.1` (nor `0.1.0-rc.5`), while
253
+ * `>=1.2.3-rc.1 <2.0.0` does match `1.2.3-rc.2` (issue #98 analysis).
254
+ * Discovery can opt into npm's `includePrerelease` behaviour because every
255
+ * published DSH host line is itself prerelease; diagnostics retain the npm
256
+ * default unless a caller explicitly asks for that wider admission.
257
+ *
258
+ * `includePrerelease` widens ADMISSION only — which prereleases may be
259
+ * considered at all. It does not move a `^` / `~` ceiling, so a cross-minor
260
+ * host line stays outside a range that declared the previous minor, exactly
261
+ * as node-semver decides it (see {@link exclusiveUpperBound}).
262
+ */
263
+ export declare function satisfiesRange(version: string, range: string, options?: {
264
+ includePrerelease?: boolean;
265
+ }): boolean | null;
266
+ interface ResolvableLoaderRow extends LoaderRow {
267
+ activation: 'required' | 'conditional';
268
+ }
269
+ export interface LayerInput {
270
+ label: string;
271
+ kind: 'bundle' | 'user' | 'home';
272
+ patches: unknown[];
273
+ parseError: string | null;
274
+ }
275
+ interface Composed {
276
+ rows: LoaderRow[];
277
+ resolvableRows: ResolvableLoaderRow[];
278
+ duplicates: DuplicateId[];
279
+ overrides: OverrideRow[];
280
+ orphans: OrphanRow[];
281
+ }
282
+ /**
283
+ * Apply the layer stack over an empty root exactly like the dsh boot include.
284
+ * Exported so the trial-start validation (src/trial.ts) can replay the
285
+ * composition with a candidate bundle order BEFORE anything is written.
286
+ */
287
+ export declare function composeLayers(layers: LayerInput[]): Composed;
288
+ /**
289
+ * Whether two rows sharing one loader id still stop the boot (#853).
290
+ *
291
+ * It depends on the loader, and the loader changed: up to
292
+ * `cordis-plugin-loader@1.0.3` `EntryGroup.update` threw
293
+ * `duplicate loader entry id` for a config array holding one id twice
294
+ * (measured against the published packages — 1.0.3 has the throw, 1.0.4 and
295
+ * 1.0.5 do not). From 1.0.4 the same array is folded into a Map keyed by id,
296
+ * so the LATER row wins and the earlier one is silently dropped.
297
+ *
298
+ * The market's rule was written against the old loader (#122: two bundles on
299
+ * one id really did refuse to start), and it is right on one. On a new one it
300
+ * is not a boot failure but a silent override — which is worth SAYING and not
301
+ * worth refusing every operation over. The reported shape is a package's own
302
+ * patch row plus a user-patch row on the same id: fatal forever meant every
303
+ * update of every plugin rolled back.
304
+ *
305
+ * An empty answer from the PROFILE lockfile is not "unknown" on the official
306
+ * Desktop: that host embeds the loader in `app.asar` and provides it to every
307
+ * profile, so no profile can ever name it (#943). Reading that as an old
308
+ * loader made the gate fatal for every update on 0.2.1-rc.2 — the exact report
309
+ * #853's fix was supposed to close. The host installation is asked before the
310
+ * evidence is treated as missing; only when both are silent does the
311
+ * conservative answer stand.
312
+ */
313
+ export declare function duplicateEntryIdsAreFatal(profileDirectory: string, dshInstallDir?: string | null): boolean;
314
+ /**
315
+ * Build the bundle layer stack for a profile under a GIVEN bundle order —
316
+ * the manifest order for analyzeProfile, or a candidate order for trial
317
+ * validation (src/trial.ts). Bundle resolution mirrors the boot exactly:
318
+ * the dsh installation anchor first (in-box bundles always come from the
319
+ * running dsh, never a profile-local copy), then Node's module search from
320
+ * the profile directory (covers community bundles and pnpm workspace-root
321
+ * hoisting). A single code path keeps the check report and the trial
322
+ * validation from ever disagreeing about what a bundle is or where it lives.
323
+ */
324
+ export declare function buildBundleLayers(profileDirectory: string, bundleNames: string[], specs: Record<string, string>, dshInstallDir: string | null): {
325
+ bundles: BundleLayer[];
326
+ layers: LayerInput[];
327
+ };
328
+ /**
329
+ * Which directories in `node_modules` are leftovers (#663).
330
+ *
331
+ * Two shapes, and both need to be VISIBLE rather than cleaned: a directory
332
+ * without a readable `package.json` (what a lock-blocked update leaves), and
333
+ * pnpm's `<name>_tmp_<pid>_<n>` staging directory (what an interrupted one
334
+ * leaves). Neither can be removed from in here in the case that produces
335
+ * them — the plugin's own process holds the directory open, so the rename
336
+ * and delete that would clear it are the operations that were just refused.
337
+ * Telling the user what is on disk, and which of it is merely junk, is the
338
+ * part this process can do.
339
+ *
340
+ * Bounded on purpose. The top level is scanned in full (that is where the
341
+ * profile's own packages live), plus one level inside the virtual store:
342
+ * pnpm stages a package's update in the `node_modules` beside it, so that is
343
+ * where a dependency's temp directory appears. It does NOT recurse through
344
+ * the whole virtual store: on a large Windows profile that is thousands of
345
+ * directories for a page the user opens by hand, and the store's OWN temp
346
+ * directories are already reclaimed by `cleanOrphanedStoreTmp`.
347
+ */
348
+ export declare function findResidualDirectories(profileDirectory: string, declared: ReadonlySet<string>): ResidualDirectory[];
349
+ /**
350
+ * Analyze one profile directory (issue #98, phase 1). Pure function of the
351
+ * directory contents — safe to call on every market open.
352
+ */
353
+ export declare function analyzeProfile(profileDirectory: string, options?: CheckOptions): CheckReport;
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Host-contract compatibility preflight for #195.
3
+ *
4
+ * Pure evaluation of what `analyzeProfile()` already reports: a confirmed
5
+ * peer mismatch (`satisfied === false`) is translated into a directional
6
+ * verdict:
7
+ *
8
+ * - `belowMin`: the resolved version is older than every alternative's lower
9
+ * bound — the environment is too old for the plugin's declared contract.
10
+ * - `aboveMax`: the resolved version is newer than every alternative's upper
11
+ * bound (or the exact pin). This is only a risk when the author expressed
12
+ * an explicit upper bound or exact pin; otherwise it is a warning, because
13
+ * the ecosystem currently has many sloppy `^0.0.1`-style declarations that
14
+ * work in practice.
15
+ *
16
+ * Everything else stays informational: `*`, prerelease-vs-`*` artifacts,
17
+ * unparseable ranges, and optional peers never produce a risk here.
18
+ */
19
+ import { type CheckOptions, type DuplicateName, type PeerRisk, type PeerWarning, type PeerVerdict } from './check.ts';
20
+ export type CompatibilityRisk = PeerRisk;
21
+ export type CompatibilityWarning = PeerWarning;
22
+ /** Re-exported so consumers can keep importing PeerVerdict from this module. */
23
+ export type { PeerVerdict };
24
+ export interface CompatibilityAssessment {
25
+ risks: CompatibilityRisk[];
26
+ warnings: CompatibilityWarning[];
27
+ /**
28
+ * Cross-layer duplicate loader NAMES, carried through from the same
29
+ * `analyzeProfile` run the peer checks already pay for (#230).
30
+ *
31
+ * The report has always computed these and deliberately kept them out of
32
+ * `summary.warnings`, because flagging an already-messy but working
33
+ * profile is a false positive nobody can act on. Diffing before against
34
+ * after is what makes them actionable: a collision this operation
35
+ * INTRODUCED is one the operation can also undo.
36
+ */
37
+ duplicateNames: DuplicateName[];
38
+ }
39
+ /**
40
+ * Whether a resolved version has crossed a `^` / `~` ceiling the author never
41
+ * wrote — the release-line break (`^0.1.x` judged by a 0.2 host).
42
+ *
43
+ * `hasExplicitUpperOrExact` says an implicit caret/tilde ceiling is too sloppy
44
+ * to call a risk, because authors write `^0.0.1` without meaning `<0.0.2-0`.
45
+ * That leniency earns its keep only while the host is still on a line the
46
+ * range named: the leftover failure is then the prerelease gate, which says
47
+ * nothing about the host's ability to load the plugin. `^0.1.x` under a 0.2
48
+ * host is a different claim — the declared line is behind us, and dsh's own
49
+ * gate (node-semver, the same bounds) refuses that release for exactly this
50
+ * reason. Both are `aboveMax` warnings to {@link classifyPeer}; the difference
51
+ * is whether a declared line is still shared.
52
+ *
53
+ * A `^0.0.x` range is excluded by design: it names no minor line to fall
54
+ * behind, and its ceiling has always been treated as noise rather than a
55
+ * declaration (see the sloppy-ceiling case in discovery-compatibility).
56
+ */
57
+ export declare function crossesImplicitCeiling(resolved: string, range: string): boolean;
58
+ /** Translate one confirmed peer mismatch into a directional verdict. */
59
+ export declare function classifyPeer(plugin: string, peer: string, range: string, resolved: string | null, optional: boolean): PeerVerdict;
60
+ /** Whether a peer is declared optional in the installed plugin manifest. */
61
+ export declare function isOptionalPeer(profileDirectory: string, plugin: string, peer: string): boolean;
62
+ /** Evaluate the current profile with the same machinery `/dsh-crate/check` uses. */
63
+ export declare function assessCompatibility(profileDirectory: string, options?: CheckOptions): CompatibilityAssessment;
64
+ /** Risks present after a mutation but absent before it. */
65
+ export declare function introducedRisks(before: CompatibilityAssessment, after: CompatibilityAssessment): CompatibilityRisk[];
66
+ /**
67
+ * Cross-layer name collisions present after a mutation but absent before it
68
+ * (#230 by @dxc-dxc).
69
+ *
70
+ * Keyed by NAME alone, not by the layer set: a collision the operation made
71
+ * worse — same name, now shadowing across one more layer — is still the same
72
+ * collision the profile already had, and re-reporting it would put the
73
+ * operator back in front of a problem they did not just cause.
74
+ *
75
+ * This is what makes surfacing these safe at all. The underlying
76
+ * `duplicateNames` is informational precisely because a healthy-but-messy
77
+ * profile can carry collisions indefinitely; only the newly introduced ones
78
+ * are attributable to the install that just ran, and therefore undoable by
79
+ * rolling it back.
80
+ */
81
+ export declare function introducedDuplicateNames(before: CompatibilityAssessment, after: CompatibilityAssessment): DuplicateName[];
82
+ /** Convenience wrapper matching the profile helper signature. */
83
+ export declare function assessProfile(profile: string, explicitDir?: string): CompatibilityAssessment;
@@ -0,0 +1,48 @@
1
+ import type { Registry, RegistryPlugin } from './registry.ts';
2
+ /**
3
+ * 判断一份 JSON 是否为 crate 目录。
4
+ *
5
+ * 只用结构特征,不依赖某个版本号:带 `entries` 数组且没有 `plugins` 数组的
6
+ * 就是 crate 形态,旧目录照常走 `asRegistry`,两套夹具互不干扰。
7
+ */
8
+ export declare function isCrateCatalog(value: unknown): boolean;
9
+ /**
10
+ * 把 crate 目录映射成市场内部的 Registry。
11
+ *
12
+ * @param value - 已经 `JSON.parse` 过的载荷。
13
+ * @returns 条目已校验、分类已归一化的目录。
14
+ * @throws 载荷不是对象、缺少 entries、或没有一条可用条目时抛出。
15
+ */
16
+ export declare function asCrateRegistry(value: unknown): Registry;
17
+ /**
18
+ * 单条 crate 条目转成 RegistryPlugin。
19
+ *
20
+ * @param entry - entries 数组里的一项,来源不可信,逐字段校验。
21
+ * @returns 映射结果;缺少仓库路径或展示名时返回 null,由调用方跳过。
22
+ */
23
+ export declare function asCratePlugin(entry: unknown): RegistryPlugin | null;
24
+ /**
25
+ * 条目类型转分类 id。
26
+ *
27
+ * @param type - crate 的 `t` 字段,可能是任何类型。
28
+ */
29
+ export declare function categoryOf(type: unknown): string;
30
+ /**
31
+ * 从安装命令里取出 npm 包名。
32
+ *
33
+ * 命令形如 `dsh plugin --profile web add @scope/name@1.2.3`;版本号与 tag 都要
34
+ * 去掉,带变量的地址(`github:...#${DSH_PLUGIN_REF}`)和本地绝对路径都不是
35
+ * npm 包名,返回 null 让安装回落到 GitHub 源。
36
+ *
37
+ * @param command - crate 的 `cmd` 字段,可能是任何类型。
38
+ * @returns 合法 npm 包名,或 null。
39
+ */
40
+ export declare function npmFromCommand(command: unknown): string | null;
41
+ /**
42
+ * 去掉安装源末尾的 `@版本` 或 `@tag`。
43
+ *
44
+ * 从下标 1 开始查找,避免把作用域包名开头的 `@` 当成版本分隔符。
45
+ *
46
+ * @param spec - 安装源,例如 `@scope/name@1.2.3`。
47
+ */
48
+ export declare function stripSpecVersion(spec: string): string;
@@ -0,0 +1,29 @@
1
+ /** Versioned, read-only diagnostics shared by the host route and client. */
2
+ export declare const DIAGNOSTIC_SCHEMA: 'dsh-crate/diagnostics/v1';
3
+ /** Conservative first set of known, identity-sensitive host contracts. */
4
+ export declare const KNOWN_SHARED_HOST_PACKAGES: readonly ['@deepseek-ai/cordis', '@deepseek-ai/dsh-attachment', '@deepseek-ai/dsh-llm', '@deepseek-ai/dsh-system-prompt', '@deepseek-ai/dsh-tools'];
5
+ export interface PackageManifestFact {
6
+ packageName: string;
7
+ manifest: unknown;
8
+ }
9
+ export interface SharedHostPackageDependencyFinding {
10
+ code: 'shared-host-package-dependency';
11
+ severity: 'warning';
12
+ subject: {
13
+ kind: 'package';
14
+ name: string;
15
+ };
16
+ evidence: {
17
+ basis: 'manifest-declaration';
18
+ dependency: string;
19
+ declaredRange: string;
20
+ declaredIn: 'dependencies';
21
+ };
22
+ }
23
+ export type DiagnosticFinding = SharedHostPackageDependencyFinding;
24
+ export interface DiagnosticReportV1 {
25
+ schema: typeof DIAGNOSTIC_SCHEMA;
26
+ findings: DiagnosticFinding[];
27
+ }
28
+ /** Build a stable diagnostic envelope from installed package manifests. */
29
+ export declare function diagnosePackageManifests(packages: readonly PackageManifestFact[]): DiagnosticReportV1;