feat(plugin-inventory): offline bundle and pnpm plugin install for the desktop
Adds an install surface to the plugin-inventory gateway: availableBundles lists the curated offline-installable optional bundles (AVAILABLE_BUNDLES); install composes an offline bundle into the profile's dsh.profile.bundles, or for a registry spec runs pnpm against the writable profile via the bundled Node and a vendored pnpm (gated behind the dshAllowPluginInstall context flag, set only by the desktop boot); uninstall removes a bundle layer. The reconcile logic from `dsh plugin add` moves into app-boot as shared helpers. The desktop vendored pnpm into the harness and sets the allow-install env; the plugin-list SPA gains an installable-bundles section. Tests cover the guard, install helpers, and the SPA section at 100% host coverage. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+2
-67
@@ -18,78 +18,13 @@ import {
|
||||
initProfile,
|
||||
PROFILE_TEMPLATES,
|
||||
readProfileManifest,
|
||||
resolveBundleDir,
|
||||
reconcileProfileBundles,
|
||||
resolveProfileDir,
|
||||
writeProfileManifest,
|
||||
type ProfileManifest,
|
||||
} from '@deepseek-ai/dsh-app-boot'
|
||||
import { INSTALL_ANCHOR } from './profile-boot.ts'
|
||||
|
||||
const NAME = 'dsh'
|
||||
|
||||
/**
|
||||
* Whether a resolved dependency exports a profile patch, i.e. is a bundle.
|
||||
* @param packageName - the dependency's package name.
|
||||
* @param profileDir - the profile directory (resolution anchor).
|
||||
* @returns true when the package manifest declares `dsh.bundle`.
|
||||
*/
|
||||
function exportsPatch(packageName: string, profileDir: string): boolean {
|
||||
let dir: string
|
||||
try {
|
||||
dir = resolveBundleDir(NAME, packageName, INSTALL_ANCHOR, profileDir)
|
||||
} catch {
|
||||
return false // pnpm reported success yet the package is unresolvable — treat as plain
|
||||
}
|
||||
const manifest = readProfileManifest(NAME, dir)
|
||||
return manifest.dsh?.bundle?.patch !== undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconcile `dsh.profile.bundles` against the installed state: pnpm has
|
||||
* already written the real installed names (so a git/path/tarball/alias spec
|
||||
* on the command line reconciles by its true package name) and materialized
|
||||
* the packages. A dependency that resolves to a `dsh.bundle`-declaring
|
||||
* package joins the layer stack (appended in dependency order); a
|
||||
* dependency-listed name that no longer does — removed, or the installed
|
||||
* version dropped the declaration — leaves it. In-box bundles from the
|
||||
* profile template are not dependencies and are never touched. Warns once
|
||||
* per newly-added bundle-less dependency (a plain library is fine; the
|
||||
* warning is orientation).
|
||||
*/
|
||||
function reconcilePlugins(before: ProfileManifest, profileDir: string): void {
|
||||
const after = readProfileManifest(NAME, profileDir)
|
||||
const beforeDeps = new Set(Object.keys(before.dependencies ?? {}))
|
||||
const dependencies = Object.keys(after.dependencies ?? {})
|
||||
const plugins = after.dsh?.profile?.bundles ?? []
|
||||
let changed = false
|
||||
for (const packageName of dependencies) {
|
||||
const isBundle = exportsPatch(packageName, profileDir)
|
||||
if (isBundle && !plugins.includes(packageName)) {
|
||||
plugins.push(packageName)
|
||||
changed = true
|
||||
} else if (!isBundle && !beforeDeps.has(packageName)) {
|
||||
process.stderr.write(
|
||||
`${NAME}: warning: ${packageName} declares no dsh.bundle — installed as a plain dependency, not a profile layer `
|
||||
+ '(a later update that gains one activates it automatically)\n',
|
||||
)
|
||||
}
|
||||
}
|
||||
const dependencySet = new Set(dependencies)
|
||||
for (const packageName of [...plugins]) {
|
||||
// Only dependency-managed entries are subject to removal; template
|
||||
// bundles (dsh-base and friends) are not dependencies.
|
||||
const wasDependency = beforeDeps.has(packageName) || dependencySet.has(packageName)
|
||||
const stillBundle = dependencySet.has(packageName) && exportsPatch(packageName, profileDir)
|
||||
if (wasDependency && !stillBundle) {
|
||||
plugins.splice(plugins.indexOf(packageName), 1)
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
if (!changed) return
|
||||
after.dsh = { ...after.dsh, profile: { ...after.dsh?.profile, bundles: plugins } }
|
||||
writeProfileManifest(profileDir, after)
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewrite relative filesystem specs against the user's invoking directory.
|
||||
* pnpm runs with cwd = the profile directory, so a bare `.` or `../plugin`
|
||||
@@ -141,7 +76,7 @@ export function runPlugin(profile: string, args: readonly string[]): number {
|
||||
}
|
||||
const exitCode = result.status ?? 1
|
||||
if (exitCode === 0) {
|
||||
reconcilePlugins(before, dir)
|
||||
reconcileProfileBundles(NAME, before, dir, INSTALL_ANCHOR)
|
||||
} else {
|
||||
// pnpm's own diagnostics name pnpm-workspace.yaml without saying WHICH
|
||||
// one; the profile owns it, and the commonest failure here is pnpm ≥10
|
||||
|
||||
@@ -250,6 +250,11 @@ export async function runProfile(options: RunProfileOptions): Promise<{ ctx: Con
|
||||
// Before any config-tree entry mounts, so plugins resolve all launch-time
|
||||
// environment values from the same immutable provenance snapshot.
|
||||
hostCtx.provide(DSH_LAUNCH_ENVIRONMENT_KEY, options.environment)
|
||||
// Plugin install facts: the installation anchor for resolving bundles, and
|
||||
// whether registry (pnpm) install is permitted. Both default off; the
|
||||
// desktop boot opts into install via DSH_ALLOW_PLUGIN_INSTALL.
|
||||
hostCtx.provide('dshInstallAnchor', INSTALL_ANCHOR)
|
||||
hostCtx.provide('dshAllowPluginInstall', process.env.DSH_ALLOW_PLUGIN_INSTALL === '1')
|
||||
// The command line and bounded exit request are launcher facts available
|
||||
// to every app plugin that injects the argument snapshot.
|
||||
provideCmdline(hostCtx, {
|
||||
|
||||
Reference in New Issue
Block a user