@deepseek-ai/dsh-plugin-manager 0.2.2-rc.1 → 0.2.2-rc.2

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 (70) hide show
  1. package/README.i18n.yaml +4 -4
  2. package/README.md +6 -5
  3. package/README.zh.md +6 -5
  4. package/lib/index.js +255 -68
  5. package/lib/typert.host.js +84 -66
  6. package/lib/typert.remote-client.d.ts.map +1 -0
  7. package/lib/typert.remote-client.js +77 -59
  8. package/lib/types/build-approval.d.ts.map +1 -0
  9. package/lib/types/build-approval.js.map +1 -0
  10. package/lib/types/bundle-detail.d.ts.map +1 -0
  11. package/lib/types/bundle-detail.js.map +1 -0
  12. package/lib/types/diagnostic.d.ts.map +1 -0
  13. package/lib/types/diagnostic.js +1 -0
  14. package/lib/types/diagnostic.js.map +1 -0
  15. package/lib/types/failure.d.ts.map +1 -0
  16. package/lib/types/failure.js.map +1 -0
  17. package/lib/types/git-transport.d.ts.map +1 -0
  18. package/lib/types/git-transport.js.map +1 -0
  19. package/lib/types/github-connection.d.ts +16 -5
  20. package/lib/types/github-connection.d.ts.map +1 -0
  21. package/lib/types/github-connection.js +18 -8
  22. package/lib/types/github-connection.js.map +1 -0
  23. package/lib/types/index.d.ts +39 -10
  24. package/lib/types/index.d.ts.map +1 -0
  25. package/lib/types/index.js +144 -46
  26. package/lib/types/index.js.map +1 -0
  27. package/lib/types/install-failure.d.ts.map +1 -0
  28. package/lib/types/install-failure.js.map +1 -0
  29. package/lib/types/install-spec.d.ts +13 -1
  30. package/lib/types/install-spec.d.ts.map +1 -0
  31. package/lib/types/install-spec.js +41 -1
  32. package/lib/types/install-spec.js.map +1 -0
  33. package/lib/types/official-install-target.d.ts.map +1 -0
  34. package/lib/types/official-install-target.js.map +1 -0
  35. package/lib/types/operations.d.ts +16 -4
  36. package/lib/types/operations.d.ts.map +1 -0
  37. package/lib/types/operations.js +38 -5
  38. package/lib/types/operations.js.map +1 -0
  39. package/lib/types/patch.d.ts.map +1 -0
  40. package/lib/types/patch.js.map +1 -0
  41. package/lib/types/registry.d.ts.map +1 -0
  42. package/lib/types/registry.js.map +1 -0
  43. package/lib/types/run-tree.d.ts.map +1 -0
  44. package/lib/types/run-tree.js.map +1 -0
  45. package/lib/types/tools.d.ts.map +1 -0
  46. package/lib/types/tools.js +2 -1
  47. package/lib/types/tools.js.map +1 -0
  48. package/lib/types/types.d.ts +31 -5
  49. package/lib/types/types.d.ts.map +1 -0
  50. package/lib/types/types.js.map +1 -0
  51. package/lib/types/versions.d.ts.map +1 -0
  52. package/lib/types/versions.js.map +1 -0
  53. package/package.json +39 -35
  54. package/src/build-approval.ts +96 -0
  55. package/src/bundle-detail.ts +104 -0
  56. package/src/diagnostic.ts +86 -0
  57. package/src/failure.ts +29 -0
  58. package/src/git-transport.ts +72 -0
  59. package/src/github-connection.ts +102 -0
  60. package/src/index.ts +1458 -0
  61. package/src/install-failure.ts +44 -0
  62. package/src/install-spec.ts +159 -0
  63. package/src/official-install-target.ts +58 -0
  64. package/src/operations.ts +695 -0
  65. package/src/patch.ts +78 -0
  66. package/src/registry.ts +98 -0
  67. package/src/run-tree.ts +77 -0
  68. package/src/tools.ts +164 -0
  69. package/src/types.ts +477 -0
  70. package/src/versions.ts +80 -0
package/src/types.ts ADDED
@@ -0,0 +1,477 @@
1
+ /** Public plugin management records shared with clients. */
2
+ import type { Branded } from '@deepseek-ai/dsh-brand'
3
+ import type { PluginLocalizedMeta } from '@deepseek-ai/dsh-package-manifest'
4
+ import type { PluginInventoryEntry } from '@deepseek-ai/dsh-host-plugin-inventory/types'
5
+ export type { PluginEntryId } from '@deepseek-ai/dsh-host-plugin-inventory/types'
6
+ import type { PluginEntryId } from '@deepseek-ai/dsh-host-plugin-inventory/types'
7
+ import type {} from '@deepseek-ai/dsh-typert-protocol'
8
+ import type { DetailFailureReason } from '@deepseek-ai/dsh-plugin-detail/types'
9
+
10
+ declare module '@deepseek-ai/dsh-typert-protocol' {
11
+ interface RemoteErrorDetailsMap {
12
+ /** The profile lists no such bundle, or its directory cannot be resolved. */
13
+ 'plugin-manager/unknown-bundle': { readonly name: string }
14
+ /** The display language is not a BCP 47 language id. */
15
+ 'plugin-manager/invalid-language': { readonly language: string }
16
+ /**
17
+ * A bundle's detail document or image exists but cannot be read: `too-large` beyond a size limit, `network` when the
18
+ * npm file CDNs cannot be reached, `invalid` for a malformed locale file or `meta.detail`, or a named file that does
19
+ * not exist. Bundle files come from local directories and public CDNs, which never answer `denied`.
20
+ */
21
+ 'plugin-manager/detail-unavailable': { readonly reason: DetailFailureReason }
22
+ }
23
+ }
24
+
25
+ /** Reasons a profile control cannot modify its target. */
26
+ export type ReadOnlyReason = 'management-required' | 'unaddressable'
27
+
28
+ /** A package whose declared DSH requirements reject the running DSH version, without an exemption for the exact pair. */
29
+ export interface IncompatiblePlugin {
30
+ name: string
31
+ version: string
32
+ runtimeVersion: string
33
+ /** Only the requirements the running version does not satisfy, keyed `engines.dsh` or by DSH peer package name. */
34
+ requirements: Record<string, string>
35
+ }
36
+
37
+ /** Localizable management failure and optional external diagnostic. */
38
+ export interface ManagementError {
39
+ code: ReadOnlyReason | 'unknown-plugin' | 'invalid-spec' | 'already-installed' | 'ambiguous-install' | 'not-bundle' | 'not-removable' | 'stop-profile' | 'bundle-in-use' | 'stale-approval' | 'incompatible-version' | 'unsupported-platform' | 'unexpected-package' | 'operation-error'
40
+ diagnostic?: string
41
+ /** Present with `incompatible-version`: the packages the running DSH version rejects. */
42
+ incompatible?: IncompatiblePlugin[]
43
+ }
44
+
45
+ /**
46
+ * Why a change waits for the next start: `no-hmr` profiles apply changes only at startup; `package-moved` changes map an
47
+ * installed package to another directory without removing it first, or change or locally override a package the DSH
48
+ * installation provides; `host-module` changes reach
49
+ * modules the running process itself imports; `unmanaged-plugin` changes reach a plugin running outside a Loader entry;
50
+ * `module-comparison` means loaded modules could not be compared with disk.
51
+ */
52
+ export type RestartReason = 'no-hmr' | 'package-moved' | 'host-module' | 'unmanaged-plugin' | 'module-comparison'
53
+
54
+ /** One running-profile entry and its persistent control availability. */
55
+ export type PluginInfo = PluginInventoryEntry & (
56
+ | { patchId: string; readOnlyReason?: never }
57
+ | { patchId?: never; readOnlyReason: ReadOnlyReason }
58
+ )
59
+
60
+ /** One row a bundle's patch declares, with its live entry while the bundle contributes it. */
61
+ export interface BundleRowInfo {
62
+ /** The row id as the patch declares it. */
63
+ rowId: string
64
+ /** The module the row names. */
65
+ moduleName: string
66
+ /** Local package display metadata, including rows whose bundle is disabled. */
67
+ meta?: PluginLocalizedMeta
68
+ /** The Loader entry carrying this row, when exactly one live entry has its id. */
69
+ entryId?: PluginEntryId
70
+ }
71
+
72
+ /** One shipped, profile-installed, or discoverable on-demand bundle. */
73
+ export interface BundleInfo {
74
+ name: string
75
+ /** Project-maintained shipped optional bundle or on-demand catalog entry, independent of installation and selection. */
76
+ official: boolean
77
+ /** Readable package location; on-demand catalog entries exclude undeclared transitive copies, and declared files may be missing. */
78
+ availability: 'installation' | 'profile' | 'missing'
79
+ /** Exact released Host version or same-checkout development link offered for an on-demand catalog entry. */
80
+ installTarget?: { spec: string; version: string }
81
+ version?: string
82
+ /** Local display text with available translations or literal fallbacks, or a metadata diagnostic. */
83
+ meta?: PluginLocalizedMeta
84
+ /** Untranslated `description` of this bundle's package manifest. */
85
+ description?: string
86
+ /** Default GUI visibility after package and Host checks; selected or profile-installed bundles remain manageable. */
87
+ listedByDefault?: boolean
88
+ /**
89
+ * Selected in the profile manifest; a selected bundle whose layer was skipped carries the load `error`, and none of
90
+ * its `rows` has an `entryId`.
91
+ */
92
+ enabled: boolean
93
+ /** Whether the profile declares this dependency; availability separately reports whether its files can be read. */
94
+ installed: boolean
95
+ /**
96
+ * Present for a profile dependency the installation does not also supply: the spec `pnpm add` accepts, with local
97
+ * paths made absolute and the user information of an http(s) URL removed.
98
+ */
99
+ source?: string
100
+ /**
101
+ * Whether the installation ships the bundle for the person to switch on: named by the launcher's `OPTIONAL_BUNDLES`,
102
+ * held by the installation's dependencies, selected by no shipped template, and never removable.
103
+ */
104
+ optional: boolean
105
+ removable: boolean
106
+ /**
107
+ * How `updateBundle` replaces the bundle, absent when it cannot: `registry` for a third-party profile dependency saved
108
+ * as a registry spec under its own name, whose newer versions `listVersions` reads; `git` for one saved as a Git spec
109
+ * pinned to a full commit, which updates to another commit of the same repository directory. Either needs a semver
110
+ * manifest version and no plugin management.
111
+ */
112
+ update?: 'registry' | 'git'
113
+ readOnlyReason?: ReadOnlyReason
114
+ error?: ManagementError
115
+ /** The rows the bundle's patch inserts, in declaration order; empty when the patch cannot be read. */
116
+ rows: BundleRowInfo[]
117
+ /** Ids of rows the bundle's patch changes without declaring them: the built-in rows it configures or disables. */
118
+ overrides: string[]
119
+ }
120
+
121
+ /** A registry to install from: an http(s) URL, or null for the one pnpm's own configuration names. */
122
+ export type Registry = string | null
123
+
124
+ /** The registries the manager asks: the configured first one, its fallbacks in order, and what pnpm's own configuration names. */
125
+ export interface PluginRegistries {
126
+ readonly registry: Registry
127
+ readonly fallbackRegistries: readonly string[]
128
+ /** The URL pnpm's own configuration names in the profile, read from pnpm; null when it could not be read. */
129
+ readonly resolved: string | null
130
+ }
131
+
132
+ /** How a package operation failed, read off how it ended and what it printed. */
133
+ export type PluginInstallFailureKind =
134
+ | 'pnpm-missing'
135
+ | 'timeout'
136
+ | 'not-found'
137
+ | 'no-matching-version'
138
+ | 'network'
139
+ | 'disk-full'
140
+ | 'permission'
141
+ | 'build-blocked'
142
+ | 'integrity'
143
+ | 'unknown'
144
+
145
+ /** Package operation completion, including Git checks and a retrieval path for unabridged diagnostics. */
146
+ export interface PackageResult {
147
+ /** The status the run is read as having ended with; a run the manager terminated records the coerced status 1. */
148
+ exitCode: number
149
+ output: string
150
+ truncated: boolean
151
+ logPath: string
152
+ /** Present when the run failed: what kind of failure its exit and output describe. */
153
+ kind?: PluginInstallFailureKind
154
+ /**
155
+ * The run outlived its bound: the manager terminated it after it printed nothing for its silence bound, or the GitHub
156
+ * connection check hit its deadline. Such a run reports no exit status of its own, so `exitCode` records the status
157
+ * its failure is read as rather than a status the process returned.
158
+ */
159
+ timedOut?: boolean
160
+ /** Present when a compatibility check refused the run: the packages the running DSH version rejects. */
161
+ incompatible?: IncompatiblePlugin[]
162
+ /**
163
+ * Present when an `expected` check refused the run: `unexpected-package` when the run left the expected package
164
+ * missing or at another version, or added or changed another direct dependency; otherwise `not-bundle` when the
165
+ * expected package declares no bundle. The output names what the run installed.
166
+ */
167
+ unmet?: 'unexpected-package' | 'not-bundle'
168
+ }
169
+
170
+ /** Persisted change and independently observed application outcome. */
171
+ export interface ChangeResult {
172
+ changed: boolean
173
+ /** `cancelled` is an installation the caller stopped, its files restored. */
174
+ application: 'applied' | 'restart-required' | 'overridden' | 'failed' | 'cancelled'
175
+ /** Present with `restart-required`: why the change takes effect only at the next start. */
176
+ restartReason?: RestartReason
177
+ /** Last attempted step; successful installation can proceed to enablement. */
178
+ stage: 'install' | 'enable' | 'remove'
179
+ target: string
180
+ enabled?: boolean
181
+ error?: ManagementError
182
+ /** Pre-existing inactive entries the operation left as they were. */
183
+ warnings?: string[]
184
+ packageResult?: PackageResult
185
+ /** The bundle an installation added, once pnpm and the bundle check accepted it. */
186
+ bundle?: string
187
+ /** The installed bundle's manifest version, when declared; pnpm's `minimumReleaseAge` can make it older than the newest release. */
188
+ version?: string
189
+ /** Exact `allowBuilds` keys awaiting explicit script approval in the profile's pnpm settings, read after a failed run. */
190
+ pendingBuilds?: string[]
191
+ /** Package script permissions saved before this installation attempt. */
192
+ approvedBuilds?: string[]
193
+ /** The registries the installation asked, in order; `packageResult` is the last one's run. */
194
+ registries?: Registry[]
195
+ /**
196
+ * What the last failed run could not reach or get an answer from: the registry it asked, or the host a git or
197
+ * tarball spec is fetched from, which no registry stands in for; absent for a failure neither explains.
198
+ */
199
+ failedAt?: 'registry' | 'spec-host'
200
+ }
201
+
202
+ /** Identifies one installation from its start to its settlement, including its log chunks and cancellation. */
203
+ export type PluginInstallRequestId = Branded<'PluginInstallRequestId'>
204
+
205
+ /** Bundle installation defaults to activation; callers that offer cancellation supply their request id. */
206
+ export interface InstallBundleOptions {
207
+ enabled?: boolean
208
+ /** Save the resolved dependency version without a range; applies to any bundle installation. */
209
+ saveExact?: boolean
210
+ requestId?: PluginInstallRequestId
211
+ /** Explicitly allow these pending packages' scripts for this profile, then install; a name no longer pending refuses the call. */
212
+ approvedBuilds?: string[]
213
+ /** The registry asked first; absent, the configured one. The configured fallbacks follow while a registry is unreachable or stale. */
214
+ registry?: Registry
215
+ /**
216
+ * The package and manifest version the spec must install. An installation that leaves this package missing or at
217
+ * another version, or that adds or changes another direct dependency, is undone with its profile files and modules
218
+ * before its bundle loads, and fails with `unexpected-package`; one whose package declares no bundle is undone the
219
+ * same way and fails with `not-bundle`, and one whose bundle patches cannot load fails as an operation error.
220
+ */
221
+ expected?: { readonly name: string; readonly version: string }
222
+ }
223
+
224
+ /** Where an inspection asks. */
225
+ export interface InspectOptions {
226
+ /** The registry asked first; absent, the configured one. */
227
+ readonly registry?: Registry
228
+ }
229
+
230
+ /** The form one install spec takes, in pnpm's vocabulary. */
231
+ export type InstallSpecKind = 'registry' | 'path' | 'git' | 'tarball'
232
+
233
+ /** Why a spec was refused before anything installed. */
234
+ export type PluginInspectProblem =
235
+ | 'invalid-spec'
236
+ | 'already-installed'
237
+ | 'not-found'
238
+ | 'not-a-package'
239
+ | 'not-a-bundle'
240
+ | 'network'
241
+ | 'unknown'
242
+
243
+ /**
244
+ * What a spec names, read before installing it: the registry's answer for a
245
+ * name, a directory's manifest for a path, and only the form for a git or
246
+ * tarball spec, whose package is known once pnpm has fetched it.
247
+ */
248
+ export type PluginSpecInspection =
249
+ | {
250
+ readonly status: 'accepted'
251
+ readonly kind: InstallSpecKind
252
+ readonly name?: string
253
+ readonly version?: string
254
+ /** `description` of the package manifest. */
255
+ readonly description?: string
256
+ /** Whether the package declares a bundle patch; null when the spec's form does not say. */
257
+ readonly bundle: boolean | null
258
+ /** The registry that answered for a name, and for the other forms the one an install of the spec asks first. */
259
+ readonly registry: Registry
260
+ /** The host a git spec or a tarball URL is fetched from, which no registry stands in for. */
261
+ readonly host?: string
262
+ }
263
+ | {
264
+ readonly status: 'refused'
265
+ readonly problem: PluginInspectProblem
266
+ /** What pnpm, the registry, or the file system said. */
267
+ readonly reason: string
268
+ /** The registries asked, in order, when the refusal came from asking them; `reason` is the last one's. */
269
+ readonly registries?: Registry[]
270
+ }
271
+
272
+ /** One registry a lookup asked, in order; the registry that answered carries no problem. */
273
+ export interface RegistryAttempt {
274
+ readonly registry: Registry
275
+ /** Why this registry gave no usable answer; absent for the registry that answered. */
276
+ readonly problem?: 'not-found' | 'network' | 'unknown'
277
+ /** What pnpm or the registry said, verbatim. */
278
+ readonly reason?: string
279
+ }
280
+
281
+ /** One published version newer than the installed one. */
282
+ export interface PluginVersion {
283
+ readonly version: string
284
+ /** The registry's publication time, as an ISO 8601 string. */
285
+ readonly publishedAt?: string
286
+ /** The dist-tags pointing at this version, such as `latest`. */
287
+ readonly tags: readonly string[]
288
+ /** Whether the version carries a semver prerelease suffix. */
289
+ readonly prerelease: boolean
290
+ /** The registry's deprecation message, when the version is deprecated. */
291
+ readonly deprecated?: string
292
+ /** Whether the version declares a `dsh.bundle`; a version that does not cannot replace a bundle. */
293
+ readonly bundle: boolean
294
+ /** Present when the version's `engines.dsh` or DSH peers reject the running DSH version without an exemption for the exact pair. */
295
+ readonly incompatible?: IncompatiblePlugin
296
+ }
297
+
298
+ /** The versions a registry offers for an installed registry package, read without changing the profile. */
299
+ export type PluginVersionList =
300
+ | {
301
+ readonly status: 'listed'
302
+ /** The installed version the list is newer than. */
303
+ readonly installed: string
304
+ /** The registry that answered; an update installs from it. */
305
+ readonly registry: Registry
306
+ readonly attempts: readonly RegistryAttempt[]
307
+ /** Published versions newer than `installed`, newest first, at most `versionListLimit` of them. */
308
+ readonly versions: readonly PluginVersion[]
309
+ /** Newer versions beyond `versionListLimit` that the list leaves out. */
310
+ readonly omitted: number
311
+ }
312
+ | {
313
+ readonly status: 'refused'
314
+ /** `not-updatable`: the package is not an installed profile dependency resolved from a registry. */
315
+ readonly problem: 'not-updatable' | 'not-found' | 'network' | 'unknown'
316
+ readonly reason: string
317
+ /** The registries asked, in order; empty for `not-updatable`. */
318
+ readonly attempts: readonly RegistryAttempt[]
319
+ }
320
+
321
+ /** Where a version listing asks. */
322
+ export interface ListVersionsOptions {
323
+ /** The registry asked first; absent, the one this process last installed the package from, else the configured one. */
324
+ readonly registry?: Registry
325
+ }
326
+
327
+ /** Where an update asks for its target, and the request id its progress names. */
328
+ export interface UpdateBundleOptions {
329
+ /** The registry asked first, normally the one that answered `listVersions`; absent, as for `listVersions`. */
330
+ readonly registry?: Registry
331
+ /**
332
+ * The Git spec of the target version: required for a bundle listed with `update: 'git'`, where it must pin a full
333
+ * commit of the installed copy's repository directory, and refused for any other.
334
+ */
335
+ readonly spec?: string
336
+ /** Names the update's progress and the target installation's logs; `cancelInstall` stops only that installation. */
337
+ readonly requestId?: PluginInstallRequestId
338
+ }
339
+
340
+ /** The step of an update its Host progress names. */
341
+ export type PluginUpdateStep = 'checking' | 'removing' | 'installing' | 'restoring'
342
+
343
+ /** Progress of one update request. */
344
+ export interface PluginUpdateProgress {
345
+ readonly requestId: PluginInstallRequestId
346
+ readonly step: PluginUpdateStep
347
+ }
348
+
349
+ /**
350
+ * How an update ended. `result` belongs to the last step that ran: the target check, the removal of the installed
351
+ * version, or the target's installation. `restore` is present when the target's installation failed or was cancelled
352
+ * after the installed version was removed, and reports the reinstallation of that version.
353
+ */
354
+ export interface PluginUpdateResult {
355
+ readonly from: string
356
+ readonly to: string
357
+ readonly step: 'check' | 'remove' | 'install'
358
+ readonly result: ChangeResult
359
+ readonly restore?: ChangeResult
360
+ }
361
+
362
+ /** The Host phase of one installation, before its install call settles; `installing` is announced once per registry asked. */
363
+ export interface PluginInstallProgress {
364
+ readonly requestId: PluginInstallRequestId
365
+ readonly phase: 'installing' | 'cancelling' | 'applying'
366
+ /** With `installing`: the registry this attempt asks, its one-based position, and how many the installation may ask. */
367
+ readonly attempt?: { readonly registry: Registry; readonly index: number; readonly total: number }
368
+ }
369
+
370
+ /** Cancellation is confirmed only after process exit and file restoration. */
371
+ export interface PluginInstallCancellation {
372
+ readonly status: 'cancelled' | 'too-late' | 'not-running'
373
+ }
374
+
375
+ /** One chunk of an installation run's output: a pnpm run, or the GitHub connection check that stopped it. */
376
+ export interface PluginInstallLogChunk {
377
+ /** The installation the run belongs to, when its caller supplied a request id. */
378
+ readonly requestId?: PluginInstallRequestId
379
+ /** The run the chunk belongs to. */
380
+ readonly jobId: string
381
+ /** The command line the run executes: its command name, then its arguments. */
382
+ readonly argv: readonly string[]
383
+ /** The directory the run executes in: the profile directory. */
384
+ readonly cwd: string
385
+ readonly stream: 'stdout' | 'stderr'
386
+ readonly text: string
387
+ /** Present on the chunk that ends a run: its exit code, null when the run ended without one. */
388
+ readonly exitCode?: number | null
389
+ }
390
+
391
+ /**
392
+ * A bundle's long description, or `none` when it has neither a `meta.detail` file nor a README. Images resolve beside
393
+ * `path` through `GET /api/plugin-manager/detail-file?bundle=<name>&document=<path>&path=<destination>`.
394
+ */
395
+ export type BundleDetail =
396
+ | {
397
+ readonly status: 'found'
398
+ /** `locale` for the file locale `meta.detail` names, `readme` for the package's README. */
399
+ readonly origin: 'locale' | 'readme'
400
+ /** `/`-separated path of the document inside the package. */
401
+ readonly path: string
402
+ /** Markdown text without a byte order mark or a leading YAML front matter block. */
403
+ readonly markdown: string
404
+ }
405
+ | { readonly status: 'none' }
406
+
407
+ /** What changed in the profile, for consumers that show it. */
408
+ export interface PluginChange {
409
+ /** The operation that changed it. */
410
+ readonly reason: 'plugin' | 'bundle' | 'install' | 'remove'
411
+ }
412
+
413
+ /** Identifies one manager invocation, including time spent waiting for its profile lock. */
414
+ export type PluginOperationId = Branded<'PluginOperationId'>
415
+
416
+ /** Management facts for diagnostic consumers; recent operations do not establish a crash's cause. */
417
+ export type PluginOperation = {
418
+ readonly id: PluginOperationId
419
+ readonly time: string
420
+ readonly reason: PluginChange['reason']
421
+ /** Known entry id or parsed registry package name; unrecognized targets and raw specs are omitted. */
422
+ readonly target: string | null
423
+ readonly stage: ChangeResult['stage']
424
+ readonly enabled?: boolean | undefined
425
+ /** Request-time or resolved package version; absence means unusable or unavailable, never the latest registry version. */
426
+ readonly version?: string | undefined
427
+ } & (
428
+ | { readonly phase: 'started' }
429
+ | {
430
+ readonly phase: 'settled'
431
+ readonly application: ChangeResult['application']
432
+ readonly changed: boolean
433
+ readonly errorCode?: ManagementError['code'] | undefined
434
+ readonly restartReason?: RestartReason | undefined
435
+ }
436
+ /** An exception escaped the operation result; persisted or applied changes cannot be inferred. */
437
+ | { readonly phase: 'unknown' }
438
+ )
439
+
440
+ declare module '@deepseek-ai/cordis' {
441
+ interface Events {
442
+ /**
443
+ * One manager invocation started or ended; subscribers run independently without delaying management.
444
+ * @mode parallel
445
+ * @param operation - Correlated operation facts; a start without an end has an unknown outcome.
446
+ */
447
+ 'plugin-manager/operation'(operation: PluginOperation): void | Promise<void>
448
+ /**
449
+ * The profile's plugins, bundles, or composition changed: a manager
450
+ * operation completed. A patch generation applied outside the manager,
451
+ * by HMR's watcher after a CLI or hand edit, announces nothing here.
452
+ * @mode emit
453
+ * @param change - what changed.
454
+ */
455
+ 'plugin-manager/changed'(change: PluginChange): void
456
+ /**
457
+ * One chunk of an installation run's output, streamed as the run produces it.
458
+ * @mode emit
459
+ * @param chunk - the chunk and the run it belongs to.
460
+ */
461
+ 'plugin-manager/install-log'(chunk: PluginInstallLogChunk): void
462
+ /**
463
+ * An installation moved between its Host phases. `installing` is announced once per registry the
464
+ * installation asks, with the attempt's registry and position; `cancelling` and `applying` once.
465
+ * @mode emit
466
+ * @param progress - the installation's request id and phase, with the attempt while installing.
467
+ */
468
+ 'plugin-manager/install-state'(progress: PluginInstallProgress): void
469
+ /**
470
+ * An update moved to its next step: checking the target, removing the installed version, installing the target,
471
+ * or reinstalling the removed version after the target failed. Announced once per step.
472
+ * @mode emit
473
+ * @param progress - the update's request id and step.
474
+ */
475
+ 'plugin-manager/update-state'(progress: PluginUpdateProgress): void
476
+ }
477
+ }
@@ -0,0 +1,80 @@
1
+ /** Read `pnpm view` answers about a package's published versions. */
2
+ import semver from 'semver'
3
+
4
+ /** The fields a version listing prints for the package: every version, its publication times, and its dist-tags. */
5
+ export const VERSION_LIST_FIELDS = ['versions', 'time', 'dist-tags'] as const
6
+
7
+ /** The fields read for one version: what decides whether it can replace an installed bundle. */
8
+ export const VERSION_FIELDS = ['name', 'version', 'engines', 'peerDependencies', 'deprecated', 'dsh'] as const
9
+
10
+ /** One published version newer than the installed one, before its own manifest is read. */
11
+ export interface PublishedVersion {
12
+ readonly version: string
13
+ readonly publishedAt?: string
14
+ readonly tags: readonly string[]
15
+ readonly prerelease: boolean
16
+ }
17
+
18
+ /** What one version's manifest says about replacing an installed bundle. */
19
+ export interface VersionFacts {
20
+ /** The fields `evaluatePluginCompatibility` reads. */
21
+ readonly manifest: { name: string; version: string; engines?: unknown; peerDependencies?: unknown }
22
+ readonly bundle: boolean
23
+ readonly deprecated?: string
24
+ }
25
+
26
+ /** A JSON object, or undefined for anything else. */
27
+ function recordOf(value: unknown): Record<string, unknown> | undefined {
28
+ return typeof value === 'object' && value !== null && !Array.isArray(value) ? value as Record<string, unknown> : undefined
29
+ }
30
+
31
+ /**
32
+ * The published versions newer than the installed one, newest first.
33
+ * @param answer - parsed `pnpm view <name> versions time dist-tags --json` output.
34
+ * @param installed - the installed version.
35
+ * @returns the newer versions with their publication times and dist-tags.
36
+ * @throws when the answer names no versions.
37
+ */
38
+ export function newerVersions(answer: unknown, installed: string): PublishedVersion[] {
39
+ const fields = recordOf(answer)
40
+ // pnpm prints a package with one version as a string rather than a one-element array.
41
+ const listed: unknown = typeof fields?.versions === 'string' ? [fields.versions] : fields?.versions
42
+ if (!Array.isArray(listed)) throw new Error('pnpm view answered no versions')
43
+ const time = recordOf(fields?.time) ?? {}
44
+ const tags = Object.entries(recordOf(fields?.['dist-tags']) ?? {})
45
+ return listed
46
+ .filter((version): version is string => typeof version === 'string' && semver.valid(version) !== null && semver.gt(version, installed))
47
+ .sort(semver.rcompare)
48
+ .map((version) => {
49
+ const published = time[version]
50
+ return {
51
+ version,
52
+ ...typeof published === 'string' ? { publishedAt: published } : {},
53
+ tags: tags.filter(([, tagged]) => tagged === version).map(([tag]) => tag),
54
+ prerelease: semver.prerelease(version) !== null,
55
+ }
56
+ })
57
+ }
58
+
59
+ /**
60
+ * What one exact version's manifest says, from `pnpm view <name>@<version> name version engines peerDependencies deprecated dsh --json`.
61
+ * @param answer - the parsed output.
62
+ * @param name - the package name, used when the answer omits it.
63
+ * @param version - the version asked for, used when the answer omits it.
64
+ * @returns the manifest fields compatibility reads, whether the version declares a bundle, and its deprecation message.
65
+ */
66
+ export function versionFacts(answer: unknown, name: string, version: string): VersionFacts {
67
+ const fields = recordOf(answer) ?? {}
68
+ const dsh = recordOf(fields.dsh)
69
+ const deprecated = fields.deprecated
70
+ return {
71
+ manifest: {
72
+ name: typeof fields.name === 'string' ? fields.name : name,
73
+ version: typeof fields.version === 'string' ? fields.version : version,
74
+ ...Object.hasOwn(fields, 'engines') ? { engines: fields.engines } : {},
75
+ ...Object.hasOwn(fields, 'peerDependencies') ? { peerDependencies: fields.peerDependencies } : {},
76
+ },
77
+ bundle: recordOf(dsh?.bundle) !== undefined,
78
+ ...typeof deprecated === 'string' && deprecated !== '' ? { deprecated } : {},
79
+ }
80
+ }