@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
@@ -0,0 +1,44 @@
1
+ /**
2
+ * What a failed pnpm run was, read off how it ended and what it printed:
3
+ * pnpm names its failures with stable `ERR_PNPM_*` codes and Node's errno
4
+ * names, which the run's captured tail carries whatever the locale.
5
+ * @module @deepseek-ai/dsh-plugin-manager/install-failure
6
+ */
7
+
8
+ import type { PluginInstallFailureKind } from './types.ts'
9
+
10
+ /** How a run ended, beyond its exit code. */
11
+ export interface InstallFailureFacts {
12
+ /** The output tail the failure reports. */
13
+ readonly log: string
14
+ /** The spawn error, when the child never ran. */
15
+ readonly cause?: unknown
16
+ /** Whether the run outlived its bound. */
17
+ readonly timedOut?: boolean
18
+ }
19
+
20
+ /** Patterns in the order they decide: a specific code before the generic network family. */
21
+ const LOG_KINDS: readonly [PluginInstallFailureKind, RegExp][] = [
22
+ ['build-blocked', /ERR_PNPM_IGNORED_BUILDS|Ignored build scripts|ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED/],
23
+ ['not-found', /ERR_PNPM_FETCH_404|\bE404\b|404 Not Found|Not Found - GET/],
24
+ ['no-matching-version', /ERR_PNPM_NO_MATCHING_VERSION|\bETARGET\b|No matching version/],
25
+ ['disk-full', /\bENOSPC\b|no space left on device/i],
26
+ ['permission', /\bEACCES\b|\bEPERM\b|permission denied/i],
27
+ ['integrity', /ERR_PNPM_TARBALL_INTEGRITY|ERR_PNPM_BAD_TARBALL_SIZE|\bEINTEGRITY\b/],
28
+ ['unknown', /The requested URL returned error: 40[134]\b/],
29
+ ['network', /\bENOTFOUND\b|\bECONNRESET\b|\bETIMEDOUT\b|\bECONNREFUSED\b|\bEAI_AGAIN\b|ERR_PNPM_META_FETCH_FAIL|ERR_PNPM_FETCH_5\d\d|ERR_PNPM_FETCH_TIMEOUT|\bFETCH_ERROR\b|socket hang up|Could not resolve host|unable to access/],
30
+ ]
31
+
32
+ /**
33
+ * Classify a failed run.
34
+ * @param facts - how the run ended and what it printed.
35
+ * @returns the kind, `unknown` when nothing in the facts names one.
36
+ */
37
+ export function classifyInstallFailure(facts: InstallFailureFacts): PluginInstallFailureKind {
38
+ if (facts.timedOut === true) return 'timeout'
39
+ if ((facts.cause as NodeJS.ErrnoException | undefined)?.code === 'ENOENT') return 'pnpm-missing'
40
+ for (const [kind, pattern] of LOG_KINDS) {
41
+ if (pattern.test(facts.log)) return kind
42
+ }
43
+ return 'unknown'
44
+ }
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Reading an install spec before pnpm sees it: which of pnpm's spec forms it
3
+ * takes, for a registry name whether it is one the registry can accept, and
4
+ * for a Git spec pinned to a commit the repository directory it installs from.
5
+ * @module @deepseek-ai/dsh-plugin-manager/install-spec
6
+ */
7
+
8
+ import { homedir } from 'node:os'
9
+ import { isAbsolute, resolve } from 'node:path'
10
+
11
+ /**
12
+ * One spec read into its form and the parts an inspection needs. A git spec
13
+ * and a tarball URL carry the `host` pnpm fetches them from, which no registry
14
+ * stands in for; only their dependencies come from the registry.
15
+ */
16
+ export type ParsedInstallSpec =
17
+ | { readonly kind: 'registry'; readonly spec: string; readonly name: string; readonly range?: string }
18
+ | { readonly kind: 'path'; readonly spec: string; readonly path: string }
19
+ | { readonly kind: 'tarball'; readonly spec: string; readonly path?: string; readonly host?: string }
20
+ | { readonly kind: 'git'; readonly spec: string; readonly host: string }
21
+
22
+ /** The forms pnpm resolves through a git host: a host shorthand, a git URL, or a hosted repository URL. */
23
+ const GIT_SHORTHAND = /^(?:github|gitlab|bitbucket|gist):/i
24
+ const GIT_URL = /^git(?:\+[a-z]+)?:\/\/|^git@[^:]+:/i
25
+ const HOSTED_REPOSITORY_URL = /^https?:\/\/[^/]+\/[^/]+\/[^/#]+(?:\.git)?(?:#.*)?$/i
26
+ /** The hosts pnpm's shorthands stand for. */
27
+ const GIT_SHORTHAND_HOSTS: Readonly<Record<string, string>> = {
28
+ github: 'github.com', gitlab: 'gitlab.com', bitbucket: 'bitbucket.org', gist: 'gist.github.com',
29
+ }
30
+ /** A tarball, on disk or over HTTP. */
31
+ const TARBALL_SPEC = /\.(?:tgz|tar\.gz)(?:#.*)?$/i
32
+ /** An npm package name: lowercase URL-safe segments, an optional scope, no leading dot or underscore. */
33
+ const PACKAGE_NAME = /^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/
34
+ const PACKAGE_NAME_MAX_LENGTH = 214
35
+
36
+ /** A spec neither pnpm nor the registry would take; `reason` is what the person reads. */
37
+ export class InvalidInstallSpecError extends Error {
38
+ /**
39
+ * @param spec - the spec as typed, trimmed.
40
+ * @param reason - why it is refused, as one sentence.
41
+ */
42
+ constructor(readonly spec: string, readonly reason: string) {
43
+ super(`plugin-manager: ${reason}: ${spec}`)
44
+ this.name = 'InvalidInstallSpecError'
45
+ }
46
+ }
47
+
48
+ function invalid(spec: string, reason: string): InvalidInstallSpecError {
49
+ return new InvalidInstallSpecError(spec, reason)
50
+ }
51
+
52
+ /** The host a git spec is cloned from: the shorthand's host, the scp-like user@host, or the URL's host with its port. */
53
+ function gitHost(spec: string): string {
54
+ const shorthand = /^([a-z]+):/i.exec(spec)?.[1]?.toLowerCase()
55
+ if (shorthand !== undefined && Object.hasOwn(GIT_SHORTHAND_HOSTS, shorthand)) return GIT_SHORTHAND_HOSTS[shorthand] as string
56
+ const scp = /^git@([^:]+):/i.exec(spec)?.[1]
57
+ if (scp !== undefined) return scp.toLowerCase()
58
+ return new URL(spec.replace(/^git\+/i, '')).host
59
+ }
60
+
61
+ /**
62
+ * Read a spec into its form. A path must be absolute: the Host's working
63
+ * directory means nothing to the person typing into a browser, and a
64
+ * relative path resolved against the profile would point inside it.
65
+ * @param raw - the spec as typed.
66
+ * @returns the parsed spec.
67
+ * @throws {InvalidInstallSpecError} for an empty spec, a relative path, a name the
68
+ * registry would refuse, or a URL that is neither a git host nor a tarball.
69
+ */
70
+ export function parseInstallSpec(raw: string): ParsedInstallSpec {
71
+ const spec = raw.trim()
72
+ if (spec === '') throw invalid(spec, 'the package spec must not be empty')
73
+ const path = spec.replace(/^(?:file|link):/, '')
74
+ if (path !== spec || isAbsolute(path)) {
75
+ if (!isAbsolute(path)) throw invalid(spec, 'a local path must be absolute')
76
+ return TARBALL_SPEC.test(path) ? { kind: 'tarball', spec, path } : { kind: 'path', spec, path }
77
+ }
78
+ if (/^\.{1,2}(?:[\\/]|$)/.test(spec)) throw invalid(spec, 'a local path must be absolute')
79
+ const git = GIT_SHORTHAND.test(spec) || GIT_URL.test(spec) || HOSTED_REPOSITORY_URL.test(spec)
80
+ if (git && !TARBALL_SPEC.test(spec)) return { kind: 'git', spec, host: gitHost(spec) }
81
+ if (/^https?:\/\//i.test(spec)) {
82
+ if (TARBALL_SPEC.test(spec)) return { kind: 'tarball', spec, host: new URL(spec).host }
83
+ throw invalid(spec, 'a URL must point at a git repository or a tarball')
84
+ }
85
+ const at = spec.indexOf('@', 1)
86
+ const name = at === -1 ? spec : spec.slice(0, at)
87
+ const range = at === -1 ? undefined : spec.slice(at + 1)
88
+ if (name.length > PACKAGE_NAME_MAX_LENGTH || !PACKAGE_NAME.test(name)) {
89
+ throw invalid(spec, 'not a package name the registry accepts')
90
+ }
91
+ if (range === '') throw invalid(spec, 'a version after @ must not be empty')
92
+ return range === undefined ? { kind: 'registry', spec, name } : { kind: 'registry', spec, name, range }
93
+ }
94
+
95
+ /** A full SHA-1 commit name, as a fragment parameter of a Git spec. */
96
+ const FULL_COMMIT = /^[0-9a-f]{40}$/i
97
+
98
+ /**
99
+ * Where a Git spec pinned to a full commit installs from: the lower-case host and the repository path, without
100
+ * transport, user, or `.git`, then `#` and the `path:` directory. The origin ignores the form pnpm saves, so the SSH
101
+ * form saved for an HTTPS repository it cannot read, and the host shortcut saved for a known host, have the HTTPS
102
+ * form's origin. Equal origins name one repository on a host that serves it at the same path over every transport,
103
+ * as Git forges do; on a plain SSH server, an scp-like path is relative to the login's home directory.
104
+ * @param spec - an install spec, such as a saved dependency or an update's target.
105
+ * @returns the origin, or undefined for a spec that is not Git, or whose fragment is not one full commit and at most
106
+ * one `path:` directory.
107
+ */
108
+ export function pinnedGitOrigin(spec: string): string | undefined {
109
+ let parsed: ParsedInstallSpec
110
+ try { parsed = parseInstallSpec(spec) } catch (error) {
111
+ /* v8 ignore next -- parseInstallSpec throws nothing but its own refusal */
112
+ if (!(error instanceof InvalidInstallSpecError)) throw error
113
+ return undefined
114
+ }
115
+ const hash = parsed.spec.indexOf('#')
116
+ if (parsed.kind !== 'git' || hash === -1) return undefined
117
+ const parameters = parsed.spec.slice(hash + 1).split('&')
118
+ const paths = parameters.filter(part => part.startsWith('path:'))
119
+ const others = parameters.filter(part => !part.startsWith('path:'))
120
+ // pnpm reads the last of repeated parameters, so a spec that repeats one names no single origin.
121
+ if (paths.length > 1 || others.length !== 1 || !FULL_COMMIT.test(others.join(''))) return undefined
122
+ const path = (paths[0]?.slice('path:'.length) ?? '').replace(/^\/+|\/+$/g, '')
123
+ const location = parsed.spec.slice(0, hash)
124
+ .replace(/^(github|gitlab|bitbucket|gist):/i, (_prefix, shorthand: string) => `${GIT_SHORTHAND_HOSTS[shorthand.toLowerCase()] as string}/`)
125
+ .replace(/^git\+/i, '').replace(/^[a-z][a-z0-9+.-]*:\/\//i, '').replace(/^[^@/]+@/, '').replace(/^([^/:]+):(?!\d)/, '$1/')
126
+ .replace(/\/+$/, '').replace(/\.git$/i, '').replace(/^[^/]+/, host => host.toLowerCase())
127
+ return `${location}#${path}`
128
+ }
129
+
130
+ /** A recorded dependency value pnpm resolves outside a registry: a protocol other than a registry alias, or an scp-like git address. */
131
+ const NON_REGISTRY_VALUE = /^(?!(?:npm|jsr|workspace|catalog):)[a-z][a-z0-9+.-]*:|^[^@/:\s]+@[^:/\s]+:/i
132
+ /** The user information of an http(s) URL, up to the last `@` before the path, which holds a password or access token when present. */
133
+ export const HTTP_USER_INFO = /^((?:git\+)?https?:\/\/)[^/]*@/i
134
+
135
+ /**
136
+ * The spec `pnpm add` accepts for a dependency the profile manifest records. A git address, URL, or other
137
+ * non-registry protocol is the recorded value without the user information of an http(s) URL, whose query string
138
+ * is kept; a `file:` or `link:` path, which pnpm records relative to the profile or with `~` for the home
139
+ * directory, becomes absolute. A registry range, tag, or alias follows the dependency name after `@`, as does a
140
+ * non-registry value installed under a name other than the package's own.
141
+ * @param name - the dependency name.
142
+ * @param recorded - the value the profile manifest records for it.
143
+ * @param profileDir - the profile directory a relative local path is resolved against.
144
+ * @param packageName - the name the installed package's manifest declares, when it could be read.
145
+ * @returns the installable spec.
146
+ */
147
+ export function dependencySpec(name: string, recorded: string, profileDir: string, packageName = name): string {
148
+ const local = /^(file|link):(.*)$/s.exec(recorded)
149
+ let spec: string
150
+ if (local !== null) {
151
+ const path = (local[2] as string).replace(/^~(?=$|[\\/])/, () => homedir())
152
+ spec = `${local[1]}:${resolve(profileDir, path)}`
153
+ } else if (NON_REGISTRY_VALUE.test(recorded)) {
154
+ spec = recorded.replace(HTTP_USER_INFO, '$1')
155
+ } else {
156
+ return `${name}@${recorded}`
157
+ }
158
+ return packageName === name ? spec : `${name}@${spec}`
159
+ }
@@ -0,0 +1,58 @@
1
+ /** Select Official bundle packages from the running installation without importing provider code. */
2
+ import { existsSync, globSync, readFileSync, realpathSync, statSync } from 'node:fs'
3
+ import { dirname, join, resolve } from 'node:path'
4
+ import { bundlePatchPaths, type ProfileManifest } from '@deepseek-ai/dsh-app-boot'
5
+
6
+ interface WorkspaceManifest extends ProfileManifest {
7
+ main?: string
8
+ }
9
+
10
+ function manifestAt(file: string): WorkspaceManifest {
11
+ return JSON.parse(readFileSync(file, 'utf8')) as WorkspaceManifest
12
+ }
13
+
14
+ /**
15
+ * Offer a source checkout link or an exact published package version. Source installations are
16
+ * identified by the real CLI manifest and its unpacked workspace dependencies, including Desktop's
17
+ * development symlink. An incomplete checkout is an error, never a registry fallback.
18
+ * @param name - Official catalog package name.
19
+ * @param installAnchor - Running application's DSH package.json, possibly reached through a symlink.
20
+ * @param version - Running DSH version used by its release family.
21
+ * @returns An ordinary package-manager spec and its package version.
22
+ * @throws when a source installation lacks its workspace package, bundle patch, or built runtime.
23
+ */
24
+ export function officialBundleInstallTarget(name: string, installAnchor: string, version: string): { spec: string; version: string } {
25
+ const anchor = realpathSync(installAnchor)
26
+ const installation = manifestAt(anchor)
27
+ const source = installation.name === '@deepseek-ai/dsh'
28
+ && Object.values(installation.dependencies ?? {}).some(value => value.startsWith('workspace:'))
29
+ if (!source) return { spec: `${name}@${version}`, version }
30
+ const root = resolve(dirname(anchor), '../..')
31
+ if (anchor !== join(root, 'apps', 'cli', 'package.json')
32
+ || !existsSync(join(root, 'package.json'))
33
+ || manifestAt(join(root, 'package.json')).name !== '@deepseek-ai/dsh-root') {
34
+ throw new Error(`Official bundle ${name}: source DSH installation ${anchor} requires its complete workspace checkout`)
35
+ }
36
+ const matches = globSync('packages/*/*/package.json', { cwd: root })
37
+ .map(file => ({ file: join(root, file), manifest: manifestAt(join(root, file)) }))
38
+ .filter(entry => entry.manifest.name === name)
39
+ const selected = matches[0]
40
+ if (matches.length !== 1 || selected === undefined) {
41
+ throw new Error(`Official bundle ${name}: expected one workspace package in ${root}, found ${matches.length}; restore the checkout and run pnpm install`)
42
+ }
43
+ const { file, manifest } = selected
44
+ const directory = realpathSync(dirname(file))
45
+ if (manifest.version !== version || manifest.private === true || manifest.dsh?.bundle === undefined) {
46
+ throw new Error(`Official bundle ${name}: ${file} must declare a public bundle at DSH version ${version}`)
47
+ }
48
+ const main = typeof manifest.main === 'string' ? resolve(directory, manifest.main) : undefined
49
+ if (main === undefined || !existsSync(main) || !statSync(main).isFile()) {
50
+ throw new Error(`Official bundle ${name}: built runtime is missing in ${directory}; run pnpm install and pnpm run build in ${root}`)
51
+ }
52
+ for (const patch of bundlePatchPaths(directory, manifest.dsh.bundle)) {
53
+ if (!existsSync(patch) || !statSync(patch).isFile()) {
54
+ throw new Error(`Official bundle ${name}: bundle patch ${patch} is missing; restore the checkout`)
55
+ }
56
+ }
57
+ return { spec: `link:${directory}`, version }
58
+ }