@deepseek-ai/dsh-plugin-manager 0.2.2-rc.5 → 0.2.3-alpha.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.
- package/README.i18n.yaml +8 -8
- package/README.md +5 -4
- package/README.zh.md +5 -4
- package/lib/index.js +39 -7
- package/lib/typert.host.js +28 -28
- package/lib/typert.remote-client.d.ts.map +1 -1
- package/lib/typert.remote-client.js +26 -26
- package/lib/types/catalog.d.ts +14 -0
- package/lib/types/catalog.d.ts.map +1 -0
- package/lib/types/catalog.js +16 -0
- package/lib/types/catalog.js.map +1 -0
- package/lib/types/error.d.ts +25 -0
- package/lib/types/error.d.ts.map +1 -0
- package/lib/types/error.js +38 -0
- package/lib/types/error.js.map +1 -0
- package/lib/types/index.d.ts +5 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +15 -5
- package/lib/types/index.js.map +1 -1
- package/lib/types/registry.js +1 -1
- package/lib/types/registry.js.map +1 -1
- package/lib/types/tools.js +8 -8
- package/lib/types/tools.js.map +1 -1
- package/package.json +44 -39
- package/src/catalog.ts +18 -0
- package/src/error.ts +47 -0
- package/src/index.ts +15 -5
- package/src/registry.ts +1 -1
- package/src/tools.ts +8 -8
package/src/error.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Typed failures thrown by plugin management calls rather than reported in a change result. */
|
|
2
|
+
|
|
3
|
+
import { HarnessError } from '@deepseek-ai/dsh-error'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Every {@link PluginManagerError} code:
|
|
7
|
+
* - `PLUGIN_MANAGER_PROFILE_READ_FAILED`: the profile manifest, patches, version exemptions, or
|
|
8
|
+
* installation manifest could not be read or parsed; `cause` is the original error. Repair the
|
|
9
|
+
* profile files before retrying.
|
|
10
|
+
* - `PLUGIN_MANAGER_UNAVAILABLE`: the manager was disposed before the change started.
|
|
11
|
+
*/
|
|
12
|
+
export const PLUGIN_MANAGER_ERROR_CODES = [
|
|
13
|
+
'PLUGIN_MANAGER_PROFILE_READ_FAILED',
|
|
14
|
+
'PLUGIN_MANAGER_UNAVAILABLE',
|
|
15
|
+
] as const
|
|
16
|
+
|
|
17
|
+
/** One {@link PluginManagerError} code. */
|
|
18
|
+
export type PluginManagerErrorCode = typeof PLUGIN_MANAGER_ERROR_CODES[number]
|
|
19
|
+
|
|
20
|
+
/** Typed plugin management failure; `code` is one of {@link PLUGIN_MANAGER_ERROR_CODES}. */
|
|
21
|
+
export class PluginManagerError extends HarnessError {
|
|
22
|
+
override readonly code: PluginManagerErrorCode
|
|
23
|
+
|
|
24
|
+
constructor(message: string, code: PluginManagerErrorCode, options?: ErrorOptions) {
|
|
25
|
+
super(message, code, options)
|
|
26
|
+
this.name = 'PluginManagerError'
|
|
27
|
+
this.code = code
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Run one synchronous profile read, converting its failure.
|
|
33
|
+
* @param read - reads and parses profile files.
|
|
34
|
+
* @returns the read value.
|
|
35
|
+
* @throws {PluginManagerError} `PLUGIN_MANAGER_PROFILE_READ_FAILED` with the original error as `cause`.
|
|
36
|
+
*/
|
|
37
|
+
export function readProfileState<T>(read: () => T): T {
|
|
38
|
+
try {
|
|
39
|
+
return read()
|
|
40
|
+
} catch (error) {
|
|
41
|
+
// Profile readers fail with filesystem, JSON, YAML, or validation Error instances.
|
|
42
|
+
throw new PluginManagerError(
|
|
43
|
+
`plugin-manager: failed to read the profile: ${(error as Error).message}`,
|
|
44
|
+
'PLUGIN_MANAGER_PROFILE_READ_FAILED', { cause: error },
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -35,6 +35,7 @@ import { dependencySpec, InvalidInstallSpecError, parseInstallSpec, pinnedGitOri
|
|
|
35
35
|
import { attributeFailure, normalizeRegistry, NPMMIRROR_REGISTRY, registryPlan } from './registry.ts'
|
|
36
36
|
import { flatten, writePluginEnabled } from './patch.ts'
|
|
37
37
|
import { incompatiblePlugin, ManagementFailure } from './failure.ts'
|
|
38
|
+
import { PluginManagerError, readProfileState } from './error.ts'
|
|
38
39
|
import { approveBuilds, recordPendingBuilds } from './build-approval.ts'
|
|
39
40
|
import { checkGitConnection, checkGithubConnection, type GithubConnectionFailure } from './github-connection.ts'
|
|
40
41
|
import { chooseGitTransport, sshGitSpec } from './git-transport.ts'
|
|
@@ -48,6 +49,7 @@ import type {
|
|
|
48
49
|
} from './types.ts'
|
|
49
50
|
export type * from './types.ts'
|
|
50
51
|
export { classifyInstallFailure, type InstallFailureFacts } from './install-failure.ts'
|
|
52
|
+
export { PluginManagerError, type PluginManagerErrorCode } from './error.ts'
|
|
51
53
|
export { InvalidInstallSpecError, parseInstallSpec, pinnedGitOrigin, type ParsedInstallSpec } from './install-spec.ts'
|
|
52
54
|
|
|
53
55
|
/** The pnpm executable, registries, and limits for diagnostics, lookups and connection checks. */
|
|
@@ -471,10 +473,12 @@ export class PluginManager extends TypertRemoteService {
|
|
|
471
473
|
|
|
472
474
|
/** Read current plugins, including why a row cannot be changed through the profile patch.
|
|
473
475
|
* @returns Current runtime entries with persistent patch targets.
|
|
476
|
+
* @throws {PluginManagerError} `PLUGIN_MANAGER_PROFILE_READ_FAILED` to in-process callers when the profile patches
|
|
477
|
+
* cannot be read; Remote callers receive `gateway/internal`.
|
|
474
478
|
*/
|
|
475
479
|
@Remote
|
|
476
480
|
async listPlugins(): Promise<PluginInfo[]> {
|
|
477
|
-
const rows = flatten(composeEntries([readProfilePatches('dsh', this.profile)]))
|
|
481
|
+
const rows = readProfileState(() => flatten(composeEntries([readProfilePatches('dsh', this.profile)])))
|
|
478
482
|
const snapshot = await readPluginInventory(this.ctx)
|
|
479
483
|
return snapshot.entries.map((entry) => {
|
|
480
484
|
const actual = [...this.ctx.loader.entries()].find(row => row.id === entry.entryId)
|
|
@@ -495,6 +499,8 @@ export class PluginManager extends TypertRemoteService {
|
|
|
495
499
|
* A dependency without a bundle patch is listed, as a `not-bundle` problem, only while it is selected.
|
|
496
500
|
* @returns Package versions, manifest descriptions, the installable spec of profile dependencies, rows, optional
|
|
497
501
|
* display metadata, activation selections, whether the installation offers the bundle, and removal availability.
|
|
502
|
+
* @throws {PluginManagerError} `PLUGIN_MANAGER_PROFILE_READ_FAILED` to in-process callers when a profile or
|
|
503
|
+
* installation manifest cannot be read; Remote callers receive `gateway/internal`.
|
|
498
504
|
*/
|
|
499
505
|
@Remote
|
|
500
506
|
listBundles(): Promise<BundleInfo[]> {
|
|
@@ -506,12 +512,14 @@ export class PluginManager extends TypertRemoteService {
|
|
|
506
512
|
|
|
507
513
|
/** The bundle inventory before update eligibility, which is derived from each listed bundle. */
|
|
508
514
|
private readBundles(): Omit<BundleInfo, 'update'>[] {
|
|
509
|
-
const manifest =
|
|
510
|
-
|
|
515
|
+
const { manifest, exemptions, installation } = readProfileState(() => ({
|
|
516
|
+
manifest: readProfileManifest('dsh', this.profile.dir),
|
|
517
|
+
exemptions: readProfileVersionExemptions(this.profile.dir),
|
|
518
|
+
installation: JSON.parse(readFileSync(this.profile.installAnchor, 'utf8')) as InstallationManifest,
|
|
519
|
+
}))
|
|
511
520
|
const selected = bundleSelection(manifest)
|
|
512
521
|
const recorded = manifest.dependencies ?? {}
|
|
513
522
|
const dependencies = Object.keys(recorded)
|
|
514
|
-
const installation = JSON.parse(readFileSync(this.profile.installAnchor, 'utf8')) as InstallationManifest
|
|
515
523
|
const catalog = new Map(OFFICIAL_ON_DEMAND_CATALOG.map(entry => [entry.packageName, entry]))
|
|
516
524
|
const names = [...new Set([...selected, ...dependencies, ...Object.keys(installation.dependencies ?? {}), ...catalog.keys()])]
|
|
517
525
|
const bundles: Omit<BundleInfo, 'update'>[] = []
|
|
@@ -1375,7 +1383,9 @@ export class PluginManager extends TypertRemoteService {
|
|
|
1375
1383
|
let settled: ChangeResult
|
|
1376
1384
|
try {
|
|
1377
1385
|
settled = await withFileLock(join(this.profile.dir, 'package.json'), async () => {
|
|
1378
|
-
this.abort.signal.
|
|
1386
|
+
if (this.abort.signal.aborted) {
|
|
1387
|
+
throw new PluginManagerError('plugin-manager: the manager is disposed; retry after the Host reloads it', 'PLUGIN_MANAGER_UNAVAILABLE')
|
|
1388
|
+
}
|
|
1379
1389
|
const before = this.diskState()
|
|
1380
1390
|
const result: ChangeResult = { ...request, changed: false,
|
|
1381
1391
|
...this.ownerContext.get('hmr') !== undefined ? { application: 'applied' } : { application: 'restart-required', restartReason: 'no-hmr' } }
|
package/src/registry.ts
CHANGED
|
@@ -28,7 +28,7 @@ export const REGISTRY_URL = /^https?:\/\/\S+$/
|
|
|
28
28
|
export function normalizeRegistry(url: string): string {
|
|
29
29
|
let parsed: URL | undefined
|
|
30
30
|
try { parsed = new URL(url) }
|
|
31
|
-
catch { /*
|
|
31
|
+
catch (_invalidUrl) { /* `parsed` stays undefined and the check below throws the registry error */ }
|
|
32
32
|
if (parsed === undefined || (parsed.protocol !== 'http:' && parsed.protocol !== 'https:')) {
|
|
33
33
|
throw new Error(`a registry must be an http(s) URL: ${url}`)
|
|
34
34
|
}
|
package/src/tools.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type {} from '@deepseek-ai/dsh-sandbox-policy'
|
|
|
6
6
|
import type {} from '@deepseek-ai/dsh-user-approval'
|
|
7
7
|
import { approveEscalation } from '@deepseek-ai/dsh-sandbox'
|
|
8
8
|
import type { ChangeResult, ManagementError, PluginEntryId, PluginInstallFailureKind, RestartReason } from './types.ts'
|
|
9
|
-
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
9
|
+
import { defineTool, ToolArgsError } from '@deepseek-ai/dsh-tools'
|
|
10
10
|
import { getDshRuntimeVersion } from '@deepseek-ai/dsh-app-boot'
|
|
11
11
|
|
|
12
12
|
/** What the model does next for each refusal the manager reports. */
|
|
@@ -15,7 +15,7 @@ const ERROR_STEPS: Record<ManagementError['code'], string> = {
|
|
|
15
15
|
'unaddressable': 'This entry has no unique profile patch target; tell the user to edit the profile patch file directly.',
|
|
16
16
|
'unknown-plugin': 'Call list_plugins and retry with an exact entryId.',
|
|
17
17
|
'invalid-spec': 'Retry with an npm package name, a git URL, a tarball URL, or an absolute local directory.',
|
|
18
|
-
'already-installed': 'The package is already installed; to install another version, call remove_bundle first, then install_bundle again.',
|
|
18
|
+
'already-installed': 'The package is already installed. To reload its files after an in-place change, call set_plugin with enabled true on its entry from list_plugins; to install another version, call remove_bundle first, then install_bundle again.',
|
|
19
19
|
'ambiguous-install': 'The dependency change named no single package; call list_bundles to see what was installed.',
|
|
20
20
|
'not-bundle': 'The package declares no dsh.bundle and cannot be managed as a plugin; install a DSH plugin bundle instead.',
|
|
21
21
|
'not-removable': 'Call list_bundles; only bundles marked removable can be removed.',
|
|
@@ -86,7 +86,7 @@ export const inject = ['tools', 'pluginManager', 'sandboxPolicy']
|
|
|
86
86
|
export function apply(ctx: Context): void {
|
|
87
87
|
ctx.tools.register(defineTool({
|
|
88
88
|
name: 'plugin_manager',
|
|
89
|
-
description: 'List plugins or bundles in the current profile, enable or disable them, install a bundle, or remove an installed bundle. Every action requires danger-full-access permission or approval for this call. Approval does not change the session permission mode. Changes affect every session in this profile. List first to obtain exact identifiers. Package installation can execute allowed build scripts.
|
|
89
|
+
description: 'List plugins or bundles in the current profile, enable or disable them, install a bundle, or remove an installed bundle. Every action requires danger-full-access permission or approval for this call. Approval does not change the session permission mode. Changes affect every session in this profile. List first to obtain exact identifiers. Package installation can execute allowed build scripts. The application field of a change result is authoritative: applied means the change is in effect and needs no restart; any other value carries nextStep, which says what to do or tell the user. Unmet DSH version requirements (engines.dsh, else DSH peer dependencies) block installation and activation. Version exemptions risk crashes and data loss: warn the user and obtain explicit permission for the exact plugin and runtime versions before granting one.',
|
|
90
90
|
parameters: {
|
|
91
91
|
action: { type: 'string', required: true, enum: ['list_plugins', 'list_bundles', 'set_plugin', 'set_bundle', 'install_bundle', 'remove_bundle', 'list_version_exemptions', 'set_version_exemption'], description: 'Management operation.' },
|
|
92
92
|
target: { type: 'string', description: 'Plugin entry id, bundle package name, or installation spec, according to action. For an Official catalog entry, pass list_bundles installTarget.spec to install_bundle.' },
|
|
@@ -116,7 +116,7 @@ export function apply(ctx: Context): void {
|
|
|
116
116
|
return JSON.stringify({ runtimeVersion: getDshRuntimeVersion(), ...manager.listVersionExemptions() })
|
|
117
117
|
case 'set_version_exemption':
|
|
118
118
|
if (args.target === undefined || args.runtimeVersion === undefined || args.enabled === undefined) {
|
|
119
|
-
throw new
|
|
119
|
+
throw new ToolArgsError(['target package-name@version, runtimeVersion, and enabled are required'])
|
|
120
120
|
}
|
|
121
121
|
return JSON.stringify(withNextStep(
|
|
122
122
|
await manager.setVersionExemption(args.target, args.runtimeVersion, args.enabled, args.acceptRisk)))
|
|
@@ -125,7 +125,7 @@ export function apply(ctx: Context): void {
|
|
|
125
125
|
const offset = args.offset ?? 0
|
|
126
126
|
const limit = args.limit ?? 25
|
|
127
127
|
if (!Number.isInteger(offset) || offset < 0 || !Number.isInteger(limit) || limit < 1 || limit > 100) {
|
|
128
|
-
throw new
|
|
128
|
+
throw new ToolArgsError(['offset must be a non-negative integer and limit must be an integer from 1 to 100'])
|
|
129
129
|
}
|
|
130
130
|
const rows = args.action === 'list_plugins' ? await manager.listPlugins() : await manager.listBundles()
|
|
131
131
|
const entries = rows.slice(offset, offset + limit).map(({ meta: _meta, ...row }) =>
|
|
@@ -140,20 +140,20 @@ export function apply(ctx: Context): void {
|
|
|
140
140
|
}
|
|
141
141
|
case 'set_plugin':
|
|
142
142
|
case 'set_bundle': {
|
|
143
|
-
if (args.target === undefined || args.enabled === undefined) throw new
|
|
143
|
+
if (args.target === undefined || args.enabled === undefined) throw new ToolArgsError(['target and enabled are required'])
|
|
144
144
|
return JSON.stringify(withNextStep(await (args.action === 'set_plugin'
|
|
145
145
|
? manager.setPluginEnabled(args.target as PluginEntryId, args.enabled)
|
|
146
146
|
: manager.setBundleEnabled(args.target, args.enabled))))
|
|
147
147
|
}
|
|
148
148
|
case 'install_bundle':
|
|
149
|
-
if (args.target === undefined) throw new
|
|
149
|
+
if (args.target === undefined) throw new ToolArgsError(['target package spec is required'])
|
|
150
150
|
return JSON.stringify(withNextStep(await manager.installBundle(args.target, {
|
|
151
151
|
...args.enabled === undefined ? {} : { enabled: args.enabled },
|
|
152
152
|
...args.approvedBuilds === undefined ? {} : { approvedBuilds: args.approvedBuilds },
|
|
153
153
|
...args.registry === undefined ? {} : { registry: args.registry },
|
|
154
154
|
})))
|
|
155
155
|
case 'remove_bundle':
|
|
156
|
-
if (args.target === undefined) throw new
|
|
156
|
+
if (args.target === undefined) throw new ToolArgsError(['target bundle name is required'])
|
|
157
157
|
return JSON.stringify(withNextStep(await manager.removeBundle(args.target)))
|
|
158
158
|
/* v8 ignore next -- tool JSON validation rejects actions outside the declared enum */
|
|
159
159
|
default: return assertNever(args.action)
|