feat(plugin-inventory): live plugin activation, mirror install, and toggle lists

Installing a plugin now activates it without a restart: the CLI boot provides a
dshReloadProfile handle that re-runs the profile composition and applies it to
the running root Include, and the install/uninstall Remotes recompose live when
the handle is present (restartRequired: false). Registry installs try the
ordered INSTALL_REGISTRIES mirrors with the official npm registry as the final
fallback, erroring only when every source is unreachable. The enable/disable
guard splits into a REQUIRED_PLUGINS blacklist and a USER_TOGGLEABLE_PLUGINS
whitelist (default toggleable) generated from the running plugin list, and the
offline optional-bundle catalog is emptied (default bundles are not
installable/uninstallable). The plugin-list tab becomes a registry install form
and shows immediate-activation instead of a restart notice.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Pine
2026-08-14 20:45:00 +08:00
parent a0efe02c04
commit e18cfbfb93
16 changed files with 486 additions and 196 deletions
@@ -278,26 +278,15 @@
font-weight: 600;
}
.installList {
display: flex;
flex-direction: column;
gap: 0.375rem;
margin: 0;
padding: 0;
list-style: none;
}
.installRow {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.75rem;
gap: 0.5rem;
}
.installName {
overflow-wrap: anywhere;
font-family: var(--ds-font-family-code);
font-size: 12px;
.installInput {
flex: 1;
min-width: 0;
}
.installAction {
@@ -1,10 +1,5 @@
import { useEffect, useId, useMemo, useState, type ReactNode } from 'react'
import type {
AvailableBundlesSnapshot,
InstallResult,
InstallSpec,
PluginInventorySnapshot,
} from '@deepseek-ai/dsh-api-remotes/client'
import type { InstallResult, InstallSpec, PluginInventorySnapshot } from '@deepseek-ai/dsh-api-remotes/client'
import {
IconChevronDownOutline14,
IconSearchOutline16,
@@ -19,12 +14,8 @@ export interface PluginInventorySettingsTabInjected {
list: () => Promise<PluginInventorySnapshot>
/** Toggle one plugin entry on or off; persists across a restart. */
setEnabled: (entryId: PluginInventoryEntry['entryId'], enabled: boolean) => Promise<void>
/** List the offline-installable optional bundles. */
availableBundles: () => Promise<AvailableBundlesSnapshot>
/** Install a bundle or registry plugin; the host persists the change. */
/** Install a registry plugin by package name; the host persists the change. */
installPlugin: (spec: InstallSpec) => Promise<InstallResult>
/** Un-compose an offline optional bundle. */
uninstall: (name: string) => Promise<InstallResult>
}
type PluginInventoryEntry = PluginInventorySnapshot['entries'][number]
@@ -73,14 +64,9 @@ function matches(entry: PluginInventoryEntry, normalizedQuery: string): boolean
.some(value => value.toLocaleLowerCase().includes(normalizedQuery))
}
type BundleState =
| { readonly status: 'loading' }
| { readonly status: 'ready'; readonly snapshot: AvailableBundlesSnapshot }
| { readonly status: 'error' }
/** Render the current Loader inventory with per-plugin enable/disable and install. */
export function PluginInventorySettingsTab({
list, setEnabled, availableBundles, installPlugin, uninstall, t,
list, setEnabled, installPlugin, t,
}: PluginInventorySettingsTabProps): ReactNode {
const catalogId = useId()
const [request, setRequest] = useState(0)
@@ -88,8 +74,8 @@ export function PluginInventorySettingsTab({
const [expanded, setExpanded] = useState<PluginInventoryEntry['entryId'] | null>(null)
const [state, setState] = useState<ViewState>({ status: 'loading' })
const [busy, setBusy] = useState<PluginInventoryEntry['entryId'] | null>(null)
const [bundles, setBundles] = useState<BundleState>({ status: 'loading' })
const [installBusy, setInstallBusy] = useState<string | null>(null)
const [spec, setSpec] = useState('')
const [installBusy, setInstallBusy] = useState(false)
const [installNote, setInstallNote] = useState<{ kind: 'restart' | 'error'; text: string } | null>(null)
useEffect(() => {
@@ -101,15 +87,6 @@ export function PluginInventorySettingsTab({
return () => { current = false }
}, [list, request])
useEffect(() => {
let current = true
void Promise.resolve().then(() => availableBundles()).then(
(snapshot) => { if (current) setBundles({ status: 'ready', snapshot }) },
() => { if (current) setBundles({ status: 'error' }) },
)
return () => { current = false }
}, [availableBundles, request])
/** Toggle one entry then re-read the inventory. */
const toggle = (entryId: PluginInventoryEntry['entryId'], enabled: boolean): void => {
if (busy !== null) return
@@ -120,21 +97,25 @@ export function PluginInventorySettingsTab({
).finally(() => { setBusy(null) })
}
/** Install or uninstall an optional bundle, then re-read the catalog. */
const mutateBundle = (name: string, mode: 'install' | 'uninstall'): void => {
if (installBusy !== null) return
setInstallBusy(name)
/** Install a plugin by package name via the registry, then re-read. */
const installRegistry = (): void => {
const trimmed = spec.trim()
if (trimmed.length === 0 || installBusy) return
setInstallBusy(true)
setInstallNote(null)
const action = mode === 'install'
? installPlugin({ type: 'bundle', name })
: uninstall(name)
void action.then(
() => {
setInstallNote({ kind: 'restart', text: t('restartRequired') })
void installPlugin({ type: 'registry', spec: trimmed }).then(
(result) => {
// A live recompose activates the plugin immediately; only fall back to a
// restart notice when no reload handle exists.
setInstallNote({ kind: 'restart', text: t(result.restartRequired ? 'restartRequired' : 'installed') })
setSpec('')
setRequest(value => value + 1)
},
() => { setInstallNote({ kind: 'error', text: t('installFailed') }) },
).finally(() => { setInstallBusy(null) })
(error: unknown) => {
const detail = error instanceof Error ? error.message : String(error)
setInstallNote({ kind: 'error', text: `${t('installFailed')}: ${detail}` })
},
).finally(() => { setInstallBusy(false) })
}
const normalizedQuery = query.trim().toLocaleLowerCase()
@@ -255,31 +236,31 @@ export function PluginInventorySettingsTab({
) : null}
{state.status === 'ready' ? (
<>
{bundles.status === 'ready' && bundles.snapshot.available.length > 0 ? (
<section className={css.install} aria-label={t('available')}>
<h3>{t('available')}</h3>
{installNote !== null
? <p className={installNote.kind === 'error' ? css.installError : css.installRestart} role="status">{installNote.text}</p>
: null}
<ul className={css.installList}>
{bundles.snapshot.available.map(bundle => (
<li key={bundle.name} className={css.installRow}>
<span className={css.installName}>{bundle.name}</span>
<button
type="button"
className={css.installAction}
disabled={installBusy !== null}
onClick={() => { mutateBundle(bundle.name, bundle.installed ? 'uninstall' : 'install') }}
>
{installBusy === bundle.name
? t('installing')
: bundle.installed ? t('uninstall') : t('install')}
</button>
</li>
))}
</ul>
</section>
) : null}
<section className={css.install} aria-label={t('installPlugin')}>
<h3>{t('installPlugin')}</h3>
<div className={css.installRow}>
<input
type="text"
className={css.installInput}
value={spec}
placeholder={t('installSpec')}
aria-label={t('installSpec')}
onChange={(event) => { setSpec(event.currentTarget.value) }}
onKeyDown={(event) => { if (event.key === 'Enter') installRegistry() }}
/>
<button
type="button"
className={css.installAction}
disabled={installBusy || spec.trim().length === 0}
onClick={installRegistry}
>
{installBusy ? t('installing') : t('install')}
</button>
</div>
{installNote !== null
? <p className={installNote.kind === 'error' ? css.installError : css.installRestart} role="status">{installNote.text}</p>
: null}
</section>
<div className={css.catalog}>
<label className={css.search}>
<IconSearchOutline16 aria-hidden="true" />
@@ -40,13 +40,6 @@ export function apply(ctx: ClientContext): void {
throw new Error(`pluginInventory.setEnabled failed: ${result.error.code}: ${result.error.message}`)
}
}
const availableBundles: PluginInventorySettingsTabInjected['availableBundles'] = async () => {
const result = await ctx.remote.pluginInventory.availableBundles()
if (!result.ok) {
throw new Error(`pluginInventory.availableBundles failed: ${result.error.code}: ${result.error.message}`)
}
return result.value
}
const installPlugin: PluginInventorySettingsTabInjected['installPlugin'] = async (spec) => {
const result = await ctx.remote.pluginInventory.installPlugin(spec)
if (!result.ok) {
@@ -54,15 +47,8 @@ export function apply(ctx: ClientContext): void {
}
return result.value
}
const uninstall: PluginInventorySettingsTabInjected['uninstall'] = async (name) => {
const result = await ctx.remote.pluginInventory.uninstall(name)
if (!result.ok) {
throw new Error(`pluginInventory.uninstall failed: ${result.error.code}: ${result.error.message}`)
}
return result.value
}
const injected = (): PluginInventorySettingsTabInjected => ({
list, setEnabled, availableBundles, installPlugin, uninstall,
list, setEnabled, installPlugin,
})
ctx.slots.inject('settings.plugins.tab', () => ctx.slots.register({
@@ -24,11 +24,12 @@ export const zh = {
disable: '停用',
toggling: '切换中…',
required: '应用必需插件,不可切换',
available: '安装插件',
installPlugin: '安装插件',
installSpec: '输入插件包名,如 @scope/plugin',
install: '安装',
uninstall: '卸载',
installing: '处理中…',
restartRequired: '已应用,重启后生效',
installing: '安装中…',
restartRequired: '已安装,重启后生效',
installed: '已安装并生效',
installFailed: '安装失败',
} satisfies Record<string, string>
@@ -59,10 +60,11 @@ export const en = {
disable: 'Disable',
toggling: 'Toggling…',
required: 'Required by the app; cannot be toggled',
available: 'Installable plugins',
installPlugin: 'Install plugin',
installSpec: 'Package name, e.g. @scope/plugin',
install: 'Install',
uninstall: 'Uninstall',
installing: 'Working…',
restartRequired: 'Applied; restart to activate',
installing: 'Installing…',
restartRequired: 'Installed; restart to activate',
installed: 'Installed and active',
installFailed: 'Install failed',
} satisfies Record<PluginInventoryLocaleKey, string>
@@ -15,16 +15,13 @@ const t = ((key: PluginInventoryLocaleKey): string => en[key]) as PluginInventor
function props(
list: PluginInventorySettingsTabInjected['list'],
bundles: PluginInventorySettingsTabInjected['availableBundles'] = async () => ({ available: [] }),
installPlugin: PluginInventorySettingsTabInjected['installPlugin'] = async () => ({ ok: true as const, restartRequired: true }),
uninstall: PluginInventorySettingsTabInjected['uninstall'] = async () => ({ ok: true as const, restartRequired: true }),
): PluginInventorySettingsTabProps {
return {
t,
list,
availableBundles: bundles,
setEnabled: vi.fn(async () => {}),
installPlugin,
uninstall,
} as PluginInventorySettingsTabProps
}
@@ -162,28 +159,25 @@ describe('PluginInventorySettingsTab', () => {
await act(async () => { deferredFailure.reject(new Error('late failure')) })
})
it('renders the installable bundles with install and uninstall actions', async () => {
it('installs a registry plugin by package name', async () => {
const installPlugin = vi.fn<PluginInventorySettingsTabInjected['installPlugin']>(async () => ({ ok: true, restartRequired: true }))
const uninstall = vi.fn<PluginInventorySettingsTabInjected['uninstall']>(async () => ({ ok: true, restartRequired: true }))
const bundles: PluginInventorySettingsTabInjected['availableBundles'] = async () => ({
available: [
{ name: '@deepseek-ai/dsh-new-bundle', installed: false },
{ name: '@deepseek-ai/dsh-installed-bundle', installed: true },
],
})
render(<PluginInventorySettingsTab {...props(async () => SNAPSHOT, bundles, installPlugin, uninstall)} />)
render(<PluginInventorySettingsTab {...props(async () => SNAPSHOT, installPlugin)} />)
expect(await screen.findByText(en.available)).toBeTruthy()
expect(screen.getByText('@deepseek-ai/dsh-new-bundle')).toBeTruthy()
expect(screen.getByText('@deepseek-ai/dsh-installed-bundle')).toBeTruthy()
// Install a not-installed bundle.
const input = await screen.findByRole('textbox', { name: en.installSpec })
fireEvent.change(input, { target: { value: '@scope/plugin' } })
fireEvent.click(screen.getByRole('button', { name: en.install }))
expect(installPlugin).toHaveBeenCalledWith({ type: 'bundle', name: '@deepseek-ai/dsh-new-bundle' })
expect(installPlugin).toHaveBeenCalledWith({ type: 'registry', spec: '@scope/plugin' })
expect(await screen.findByText(en.restartRequired)).toBeTruthy()
})
// Uninstall an installed bundle.
fireEvent.click(screen.getByRole('button', { name: en.uninstall }))
expect(uninstall).toHaveBeenCalledWith('@deepseek-ai/dsh-installed-bundle')
it('shows an immediate-activation note when a live reload activates the plugin', async () => {
const installPlugin = vi.fn<PluginInventorySettingsTabInjected['installPlugin']>(async () => ({ ok: true, restartRequired: false }))
render(<PluginInventorySettingsTab {...props(async () => SNAPSHOT, installPlugin)} />)
const input = await screen.findByRole('textbox', { name: en.installSpec })
fireEvent.change(input, { target: { value: '@scope/plugin' } })
fireEvent.click(screen.getByRole('button', { name: en.install }))
expect(await screen.findByText(en.installed)).toBeTruthy()
expect(screen.queryByText(en.restartRequired)).toBeNull()
})
})
@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write packages/host/plugin-inventory/README.md
README.md: 3d899ac7404acd16047efce09e4c6d0dd0508db2
README.zh.md: ceb69499e3b2209c58d37e9c6d4b18cc599d7dc5
README.md: 54b5be19ba3a7c4925d59b1be1132dbd03ffbde8
README.zh.md: 6c3870b368686e2451f94cc397fcd07726bb1eae
+1 -1
View File
@@ -8,7 +8,7 @@ The phase is `pending`, `loading`, `active`, `failed`, or `unloading`; it is `nu
Every entry carries a `protected` flag. The guard in `src/required.ts` is default-open with two code-editable lists: `REQUIRED_PLUGINS` (the blacklist of load-bearing core that must never be disabled — the entry tree, the Remote RPC spine, the session and agent spines) and `USER_TOGGLEABLE_PLUGINS` (the whitelist, which overrides the blacklist for an explicitly toggleable plugin); a plugin on neither list is toggleable by default. The full dependency-derived taxonomy of the shipped base bundle is in [`docs/plugin-system.md`](../../../docs/plugin-system.md). `setEnabled` refuses to disable a required plugin and, after enabling, verifies the fiber becomes active (reverting a dependency-missing enable). The Web plugin-list tab renders one flat list of every entry: each shows its real enabled state, a toggleable plugin carries an enable or disable button (so a bundle-default-disabled plugin can be re-enabled), and a required plugin shows only a read-only note.
The gateway also manages installation through `availableBundles`/`install`/`uninstall`. `availableBundles` lists the curated offline-installable optional bundles in `src/bundles.ts` (`AVAILABLE_BUNDLES`), each marked installed when present in the profile's `dsh.profile.bundles`. `install` composes an offline bundle into that list (no network), or for a registry spec runs pnpm against the writable profile directory via the bundled Node and vendored pnpm — a registry install is gated behind the `dshAllowPluginInstall` context flag, which only the desktop boot sets. These writes persist the profile manifest and require a restart to take effect. Its public payload types live under `./types`, and Typert generates the Host and Client Remote artifacts exposed by `./typert` and `./remote`.
The gateway also manages installation through `availableBundles`/`installPlugin`/`uninstall`. `availableBundles` lists the curated offline-installable optional bundles in `src/bundles.ts` (`AVAILABLE_BUNDLES`); that catalog is empty until an optional bundle ships — the profile's default bundles (`dsh-base`, `dsh-web-app`, `dsh-image-recognition-bundle`) are part of the deployment, not optional add-ons, and `uninstall` refuses to remove them. `installPlugin` runs pnpm against the writable profile directory via the bundled Node and vendored pnpm for a registry package spec (the settings plugin-list tab offers this as the "install plugin" form); a registry install is gated behind the `dshAllowPluginInstall` context flag, which only the desktop boot sets. It tries the ordered `INSTALL_REGISTRIES` list (`src/install.ts`) until one succeeds, with the official npm registry last as the fallback, and errors only when every registry is unreachable. When the boot provides a `dshReloadProfile` handle, the gateway recomposes the running tree after the write so the plugin activates immediately (`restartRequired: false`); without it, the install persists the manifest and requires a restart (`restartRequired: true`). Its public payload types live under `./types`, and Typert generates the Host and Client Remote artifacts exposed by `./typert` and `./remote`.
The service is Remote-only and deliberately declares no same-process Cordis `Context` merge. Client packages consume it through the explicit [`api-remotes`](../../api/remotes/README.md) assembly rather than importing the Host implementation.
+1 -1
View File
@@ -8,7 +8,7 @@
每条条目带 `protected` 标记。`src/required.ts` 中的守卫默认开放,含两个可由代码编辑的名单:`REQUIRED_PLUGINS`(黑名单,即不可停用的承重核心——入口树、Remote RPC 主干、session 与 agent 主干)与 `USER_TOGGLEABLE_PLUGINS`(白名单,覆盖黑名单、对显式可开关的插件生效);未列入任何名单的插件默认可切换。随包 base bundle 的完整依赖图分类见 [`docs/plugin-system.md`](../../../docs/plugin-system.md)。`setEnabled` 拒绝停用必需插件;启用后会校验 fiber 变为 active(依赖缺失的启用会回滚)。Web 插件列表 tab 渲染单一扁平列表,包含所有条目:每项按真实启用状态显示,可切换插件带"启用"或"停用"按钮(这样 bundle 默认禁用的插件也能重新启用),必需插件只显示只读说明。
网关还通过 `availableBundles`/`install`/`uninstall` 管理安装。`availableBundles` 列出 `src/bundles.ts``AVAILABLE_BUNDLES`)中策展的离线可安装可选 bundle,每项在存在于 profile 的 `dsh.profile.bundles` 时标记为已安装。`install` 把离线 bundle 组合进该列表(无需网络);对 registry spec 用内置 Node 与 vendored pnpm 在可写的 profile 目录运行 pnpm——registry 安装受 `dshAllowPluginInstall` 上下文标志门禁,仅桌面启动会开启。这些写入持久化 profile 清单,需重启生效。公开 payload 类型位于 `./types`Typert 生成由 `./typert``./remote` 导出的 Host 和 Client Remote 产物。
网关还通过 `availableBundles`/`installPlugin`/`uninstall` 管理安装。`availableBundles` 列出 `src/bundles.ts``AVAILABLE_BUNDLES`)中策展的离线可安装可选 bundle;该目录目前为空,直到有可选 bundle 随包——profile 的默认 bundle`dsh-base``dsh-web-app``dsh-image-recognition-bundle`)是部署的一部分,非可选插件,`uninstall` 拒绝移除它们。`installPlugin` 对 registry spec 用内置 Node 与 vendored pnpm 在可写的 profile 目录运行 pnpm(设置页插件列表 tab 以"安装插件"表单提供此入口);registry 安装受 `dshAllowPluginInstall` 上下文标志门禁,仅桌面启动会开启。它会依次尝试 `src/install.ts` 中排序的 `INSTALL_REGISTRIES` 镜像源列表,直到其中一个成功——官方 npm 源排在最后作为保底,只有所有镜像源都不可达才报错。当 boot 提供了 `dshReloadProfile` 句柄时,网关在写入后重组合运行中的树,使插件立即生效(`restartRequired: false`);否则安装持久化 profile 清单,需重启生效(`restartRequired: true`。公开 payload 类型位于 `./types`Typert 生成由 `./typert``./remote` 导出的 Host 和 Client Remote 产物。
该服务仅供 Remote 使用,刻意不声明同进程 Cordis `Context` merge。Client 包通过显式的 [`api-remotes`](../../api/remotes/README.md) 组合消费它,而不导入 Host 实现。
@@ -7,13 +7,18 @@
* `dsh.profile.bundles` — no network or package manager required. Add a new
* shipped optional bundle to {@link AVAILABLE_BUNDLES} to make it installable
* from the plugin list.
*
* The profile's default bundles (`dsh-base`, `dsh-web-app`, and the
* `dsh-image-recognition-bundle` that ships in the web template) are composed by
* default and are NOT offered here as installable or uninstallable — they are
* part of the deployment, not optional add-ons.
* @module @deepseek-ai/dsh-plugin-inventory/bundles
*/
/**
* Bundle package names a deployment may compose offline. Keep this to bundles
* that are guaranteed resolvable from the installation anchor.
* that are guaranteed resolvable from the installation anchor and are genuinely
* optional (not default template bundles). Currently empty — no optional
* bundles ship yet; new ones should be added here to become installable.
*/
export const AVAILABLE_BUNDLES: readonly string[] = [
'@deepseek-ai/dsh-image-recognition-bundle',
]
export const AVAILABLE_BUNDLES: readonly string[] = []
+37 -7
View File
@@ -8,7 +8,7 @@ import { TypertRemoteService, Remote } from '@deepseek-ai/dsh-typert-protocol'
// Typert-generated ./typert and ./remote artifacts import Zod at runtime.
import type {} from 'zod'
import { AVAILABLE_BUNDLES } from './bundles.ts'
import { composeOfflineBundle, resolvePnpm, runPnpmInstall, uninstallBundle } from './install.ts'
import { composeOfflineBundle, resolvePnpm, runPnpmInstallWithRegistries, uninstallBundle } from './install.ts'
import { persistPluginDisabled } from './persist.ts'
import { isRequiredPlugin } from './required.ts'
import type {
@@ -23,8 +23,20 @@ import type {
export type * from './types.ts'
export { AVAILABLE_BUNDLES } from './bundles.ts'
export { INSTALL_REGISTRIES } from './install.ts'
export type { AvailableBundle, AvailableBundlesSnapshot, InstallResult, InstallSpec } from './types.ts'
/**
* The profile's default bundle layers, composed by the shipped template and not
* offered as offline-installable or uninstallable (they are part of the
* deployment). See `packages/boot/app-boot/src/profile.ts` `PROFILE_TEMPLATES`.
*/
const DEFAULT_BUNDLES = new Set([
'@deepseek-ai/dsh-base',
'@deepseek-ai/dsh-web-app',
'@deepseek-ai/dsh-image-recognition-bundle',
])
/** Brand an existing Loader-tree entry id at the owning boundary. */
function pluginEntryId(value: string): PluginEntryId {
return value as PluginEntryId
@@ -123,6 +135,9 @@ export class PluginInventoryGateway extends TypertRemoteService {
availableBundles(): AvailableBundlesSnapshot {
const profileDir = this.profileDir()
const installed = new Set(this.profileManifest(profileDir)?.dsh?.profile?.bundles ?? [])
// The catalog is empty until a new optional bundle ships, so the projection
// callback is unreachable in the current configuration.
/* v8 ignore next */
return {
available: AVAILABLE_BUNDLES.map(name => ({ name, installed: installed.has(name) })),
}
@@ -139,15 +154,18 @@ export class PluginInventoryGateway extends TypertRemoteService {
* @returns a confirmation; `restartRequired` tells the caller to restart.
*/
@Remote('installPlugin')
installPlugin(spec: InstallSpec): InstallResult {
async installPlugin(spec: InstallSpec): Promise<InstallResult> {
const profileDir = this.profileDir()
const anchor = this.ctx.get('dshInstallAnchor') as string | undefined
if (anchor === undefined) {
throw new Error('dsh: install anchor is unavailable in this runtime')
}
if (spec.type === 'bundle') {
if (DEFAULT_BUNDLES.has(spec.name)) {
throw new Error(`dsh: bundle ${spec.name} is composed by default and is not installable`)
}
composeOfflineBundle('dsh', profileDir, anchor, spec.name)
return { ok: true, restartRequired: true }
return { ok: true, restartRequired: !(await this.reload()) }
}
if (this.ctx.get('dshAllowPluginInstall') !== true) {
throw new Error('dsh: plugin install is not permitted in this runtime')
@@ -160,7 +178,8 @@ export class PluginInventoryGateway extends TypertRemoteService {
// this snapshot fallback is only reached in that same unreachable-to-succeed case.
/* v8 ignore next */
const before = this.profileManifest(profileDir) ?? { dependencies: {} }
runPnpmInstall({
// Try each registry until one succeeds; the official npm registry is last.
runPnpmInstallWithRegistries({
binName: 'dsh',
profileDir,
installAnchor: anchor,
@@ -169,7 +188,7 @@ export class PluginInventoryGateway extends TypertRemoteService {
spec: spec.spec,
before,
})
return { ok: true, restartRequired: true }
return { ok: true, restartRequired: !(await this.reload()) }
}
/**
@@ -178,9 +197,20 @@ export class PluginInventoryGateway extends TypertRemoteService {
* @returns a confirmation; `restartRequired` tells the caller to restart.
*/
@Remote('uninstall')
uninstall(name: string): InstallResult {
async uninstall(name: string): Promise<InstallResult> {
if (DEFAULT_BUNDLES.has(name)) {
throw new Error(`dsh: bundle ${name} is composed by default and cannot be uninstalled`)
}
uninstallBundle('dsh', this.profileDir(), name)
return { ok: true, restartRequired: true }
return { ok: true, restartRequired: !(await this.reload()) }
}
/** Trigger a live tree recomposition; false when no reload handle is provided. */
private async reload(): Promise<boolean> {
const reload = this.ctx.get('dshReloadProfile') as (() => Promise<void>) | undefined
if (reload === undefined) return false
await reload()
return true
}
/** The profile directory the Loader anchors on (its `baseUrl`). */
+47 -2
View File
@@ -21,6 +21,17 @@ import {
type ProfileManifest,
} from '@deepseek-ai/dsh-app-boot'
/**
* Registries to try, in order, for a registry plugin install. The install
* attempts each until one succeeds; the official npm registry is the final
* fallback, so a deployment reaches the package even when every mirror is
* down. Add mirrors here (code-editable) to route installs through them.
*/
export const INSTALL_REGISTRIES: readonly string[] = [
'https://registry.npmmirror.com',
'https://registry.npmjs.org',
]
/**
* Compose an offline optional bundle into the profile's bundle layer list.
* Validates that the bundle resolves from the installation anchor (so a bad
@@ -71,6 +82,8 @@ export interface PnpmInstallOptions {
readonly spec: string
/** The profile manifest read before the install, for reconciliation. */
readonly before: ProfileManifest
/** An npm registry to install from (`pnpm add --registry`); defaults to pnpm's configured one. */
readonly registry?: string
}
/**
@@ -80,14 +93,46 @@ export interface PnpmInstallOptions {
* @param options - the run options.
*/
export function runPnpmInstall(options: PnpmInstallOptions): void {
const { binName, profileDir, installAnchor, nodeBin, pnpmCjs, spec, before } = options
const result = spawn(nodeBin, [pnpmCjs, 'add', spec], profileDir)
const { binName, profileDir, installAnchor, nodeBin, pnpmCjs, spec, before, registry } = options
const args = registry === undefined
? [pnpmCjs, 'add', spec]
: [pnpmCjs, 'add', spec, '--registry', registry]
const result = spawn(nodeBin, args, profileDir)
if (result.exitCode !== 0) {
throw new Error(`${binName}: pnpm install failed with exit code ${result.exitCode}`)
}
reconcileProfileBundles(binName, before, profileDir, installAnchor)
}
/**
* Run `pnpm add` trying each registry in {@link INSTALL_REGISTRIES} until one
* succeeds (the first success wins). The official registry is last, so a
* deployment falls back to it when every mirror is down; throws with the last
* error only when every registry fails.
* @param options - the run options (without a fixed `registry`).
* @param registries - the ordered registries to try (defaults to
* {@link INSTALL_REGISTRIES}).
*/
export function runPnpmInstallWithRegistries(
options: Omit<PnpmInstallOptions, 'registry'>,
registries: readonly string[] = INSTALL_REGISTRIES,
): void {
let lastError: unknown
for (const registry of registries) {
try {
runPnpmInstall({ ...options, registry })
return
} catch (error) {
lastError = error
}
}
// The install path only throws Errors, so the non-Error formatting is defensive.
/* v8 ignore next */
throw new Error(
`${options.binName}: plugin install failed across all registries; last error: ${lastError instanceof Error ? lastError.message : String(lastError)}`,
)
}
/** Spawn one synchronous child and return its exit code (0 on success). */
function spawn(command: string, args: readonly string[], cwd: string): { exitCode: number } {
const result = spawnSync(command, args, {
+142 -18
View File
@@ -2,16 +2,12 @@
* Which Loader plugins the running application requires and must not be toggled,
* and which plugins a deployment explicitly allows the user to toggle.
*
* The guard is default-open with two code-editable lists:
* - {@link REQUIRED_PLUGINS} is the blacklist of load-bearing core plugins that
* must never be disabled (disabling one tears the process or the management
* surface down).
* - {@link USER_TOGGLEABLE_PLUGINS} is the whitelist of plugins a deployment
* explicitly permits the user to toggle; a whitelisted name overrides the
* blacklist for that plugin.
* A plugin on neither list is toggleable by default. Edit these lists (they are
* plain constants) to change what the plugin-inventory `protected` flag reports
* and what `setEnabled` refuses to disable.
* The guard is default-open with two code-editable lists, generated from the
* running plugin list (chjianlist.json): plugins currently enabled land in
* {@link REQUIRED_PLUGINS} (the blacklist — they keep running and cannot be
* disabled); plugins currently disabled land in {@link USER_TOGGLEABLE_PLUGINS}
* (the whitelist — they can be enabled). A whitelisted name overrides the
* blacklist for that plugin.
* @module @deepseek-ai/dsh-plugin-inventory/required
*/
@@ -22,11 +18,138 @@
* test seam for the unit tests.
*/
const REQUIRED_PLUGINS = new Set([
'@deepseek-ai/cordis-plugin-hmr',
'@deepseek-ai/cordis-plugin-loader',
'@deepseek-ai/dsh-typert-registry',
'@deepseek-ai/dsh-typert-loader',
'@deepseek-ai/dsh-session',
'@deepseek-ai/cordis-plugin-timer',
'@deepseek-ai/dsh-agent',
'@deepseek-ai/dsh-agent-default-model',
'@deepseek-ai/dsh-agent-instructions',
'@deepseek-ai/dsh-agent-loop',
'@deepseek-ai/dsh-agent-presets',
'@deepseek-ai/dsh-api-gateway',
'@deepseek-ai/dsh-api-remotes',
'@deepseek-ai/dsh-attachment-local',
'@deepseek-ai/dsh-bash-sandbox',
'@deepseek-ai/dsh-client-connection',
'@deepseek-ai/dsh-client-hmr',
'@deepseek-ai/dsh-client-locale',
'@deepseek-ai/dsh-client-modules',
'@deepseek-ai/dsh-client-runtime',
'@deepseek-ai/dsh-client-ui-agent-preset',
'@deepseek-ai/dsh-client-ui-commands',
'@deepseek-ai/dsh-client-ui-conversation',
'@deepseek-ai/dsh-client-ui-cordis',
'@deepseek-ai/dsh-client-ui-deliverables',
'@deepseek-ai/dsh-client-ui-directory-picker-native',
'@deepseek-ai/dsh-client-ui-goal',
'@deepseek-ai/dsh-client-ui-input-trigger',
'@deepseek-ai/dsh-client-ui-jobs',
'@deepseek-ai/dsh-client-ui-layout',
'@deepseek-ai/dsh-client-ui-message-feedback',
'@deepseek-ai/dsh-client-ui-model-selection',
'@deepseek-ai/dsh-client-ui-permission-presets',
'@deepseek-ai/dsh-client-ui-plan',
'@deepseek-ai/dsh-client-ui-settings',
'@deepseek-ai/dsh-client-ui-settings-general',
'@deepseek-ai/dsh-client-ui-settings-models',
'@deepseek-ai/dsh-client-ui-settings-plugin-inventory',
'@deepseek-ai/dsh-client-ui-settings-plugins',
'@deepseek-ai/dsh-client-ui-sidebar',
'@deepseek-ai/dsh-client-ui-skill',
'@deepseek-ai/dsh-client-ui-subagent',
'@deepseek-ai/dsh-client-ui-theme',
'@deepseek-ai/dsh-client-ui-tool',
'@deepseek-ai/dsh-client-ui-trajectory',
'@deepseek-ai/dsh-client-ui-user-questions',
'@deepseek-ai/dsh-client-ui-workflow-run',
'@deepseek-ai/dsh-client-ui-workspace',
'@deepseek-ai/dsh-code-runtime-worker-thread',
'@deepseek-ai/dsh-command-compact',
'@deepseek-ai/dsh-command-feedback',
'@deepseek-ai/dsh-command-goal',
'@deepseek-ai/dsh-commands',
'@deepseek-ai/dsh-compaction-basic',
'@deepseek-ai/dsh-compaction-tool-result-pruner',
'@deepseek-ai/dsh-cordis-client-runner',
'@deepseek-ai/dsh-cordis-host-runner',
'@deepseek-ai/dsh-credentials-local',
'@deepseek-ai/dsh-fs-observation-policy',
'@deepseek-ai/dsh-fs-sandbox',
'@deepseek-ai/dsh-goal',
'@deepseek-ai/dsh-goal-round-driver',
'@deepseek-ai/dsh-host-apiproxy',
'@deepseek-ai/dsh-host-directory-picker-auto',
'@deepseek-ai/dsh-host-directory-picker-native',
'@deepseek-ai/dsh-host-plugin-inventory',
'@deepseek-ai/dsh-host-webserver',
'@deepseek-ai/dsh-image-recognition',
'@deepseek-ai/dsh-image-recognition-http',
'@deepseek-ai/dsh-jobs-local',
'@deepseek-ai/dsh-llm',
'@deepseek-ai/dsh-llm-deepseek',
'@deepseek-ai/dsh-llm-pi-ai',
'@deepseek-ai/dsh-llm-retry',
'@deepseek-ai/dsh-message-feedback',
'@deepseek-ai/dsh-permission-presets',
'@deepseek-ai/dsh-persona',
'@deepseek-ai/dsh-plan-mode',
'@deepseek-ai/dsh-repeat-tool-reminder',
'@deepseek-ai/dsh-sandbox-local',
'@deepseek-ai/dsh-sandbox-policy',
'@deepseek-ai/dsh-session',
'@deepseek-ai/dsh-session-checkpoint-policy',
'@deepseek-ai/dsh-session-log-export',
'@deepseek-ai/dsh-session-persistence-jsonl',
'@deepseek-ai/dsh-session-projection',
'@deepseek-ai/dsh-session-projection-cache',
'@deepseek-ai/dsh-session-query-sqlite',
'@deepseek-ai/dsh-session-stats',
'@deepseek-ai/dsh-session-title',
'@deepseek-ai/dsh-session-title-first-prompt-llm',
'@deepseek-ai/dsh-settings-file',
'@deepseek-ai/dsh-shell-env',
'@deepseek-ai/dsh-skill',
'@deepseek-ai/dsh-skill-filesystem',
'@deepseek-ai/dsh-spill-local',
'@deepseek-ai/dsh-spill-policy',
'@deepseek-ai/dsh-storage',
'@deepseek-ai/dsh-storage-domain',
'@deepseek-ai/dsh-storage-json',
'@deepseek-ai/dsh-subagent',
'@deepseek-ai/dsh-subagent-fork-in-process',
'@deepseek-ai/dsh-subagent-spawn-in-process',
'@deepseek-ai/dsh-subprocess-local',
'@deepseek-ai/dsh-system-prompt',
'@deepseek-ai/dsh-token-meter',
'@deepseek-ai/dsh-tool-ask-user',
'@deepseek-ai/dsh-tool-bash',
'@deepseek-ai/dsh-tool-call-timeout-policy',
'@deepseek-ai/dsh-tool-fs',
'@deepseek-ai/dsh-tool-fs-search',
'@deepseek-ai/dsh-tool-goal',
'@deepseek-ai/dsh-tool-image-recognition',
'@deepseek-ai/dsh-tool-jobs',
'@deepseek-ai/dsh-tool-ralph',
'@deepseek-ai/dsh-tool-skill',
'@deepseek-ai/dsh-tool-subagent',
'@deepseek-ai/dsh-tool-subagent-control',
'@deepseek-ai/dsh-tool-subagent-control/list-agents',
'@deepseek-ai/dsh-tool-subagent-report',
'@deepseek-ai/dsh-tool-todo',
'@deepseek-ai/dsh-tool-web',
'@deepseek-ai/dsh-tool-workflow',
'@deepseek-ai/dsh-tools',
'@deepseek-ai/dsh-typert-loader',
'@deepseek-ai/dsh-typert-registry',
'@deepseek-ai/dsh-user-approval',
'@deepseek-ai/dsh-user-questions',
'@deepseek-ai/dsh-web',
'@deepseek-ai/dsh-web-app',
'@deepseek-ai/dsh-web-app/startup',
'@deepseek-ai/dsh-web-search-deepseek',
'@deepseek-ai/dsh-workflow-worker-thread',
'@deepseek-ai/dsh-workspace',
'cordis:include',
// Test seam: a `cordis:` builtin the unit tests use as a required entry.
'cordis:required',
])
@@ -34,13 +157,14 @@ const REQUIRED_PLUGINS = new Set([
/**
* Whitelist: plugin module names a deployment explicitly permits the user to
* toggle. A name here overrides the blacklist, so a whitelisted plugin is never
* reported `protected` even if it is also required. Everything else is
* toggleable by default, so this is the place to force a specific plugin open.
* reported `protected` even if it is also required.
*/
const USER_TOGGLEABLE_PLUGINS = new Set([
'@deepseek-ai/dsh-image-recognition',
'@deepseek-ai/dsh-image-recognition-http',
'@deepseek-ai/dsh-tool-image-recognition',
'@deepseek-ai/dsh-pwsh-sandbox',
'@deepseek-ai/dsh-session-telemetry-otel',
'@deepseek-ai/dsh-skill-badge',
'@deepseek-ai/dsh-tool-pwsh',
'@deepseek-ai/dsh-tool-str-replace-editor',
])
/**
@@ -1,9 +1,12 @@
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
import { readProfileManifest } from '@deepseek-ai/dsh-app-boot'
import { composeOfflineBundle, resolvePnpm, runPnpmInstall, uninstallBundle } from '../src/install.ts'
import {
composeOfflineBundle, INSTALL_REGISTRIES, resolvePnpm, runPnpmInstall,
runPnpmInstallWithRegistries, uninstallBundle,
} from '../src/install.ts'
const dirs: string[] = []
@@ -35,6 +38,22 @@ function makeFakePnpm(dir: string, exitCode: number): string {
return file
}
/**
* A fake pnpm that records its argv to `process.env.RECORD` and exits 1 when the
* `--registry` value matches `process.env.FAIL_REG`, else `process.env.EXIT`.
*/
function makeRecordingPnpm(dir: string): string {
const file = join(dir, 'recording.cjs')
writeFileSync(file, [
"const fs = require('fs')",
'const args = process.argv.slice(2)',
'fs.writeFileSync(process.env.RECORD, JSON.stringify(args))',
"const reg = args[args.indexOf('--registry') + 1]",
'process.exit(reg === process.env.FAIL_REG ? 1 : Number(process.env.EXIT ?? 0))',
].join('\n'))
return file
}
afterEach(() => {
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true })
})
@@ -83,6 +102,67 @@ describe('runPnpmInstall', () => {
nodeBin: process.execPath, pnpmCjs: pnpm, spec: 'example', before,
}) }).toThrow(/pnpm install failed/)
})
it('passes --registry when a registry is given', () => {
const dir = makeProfile()
const record = join(dir, 'record.json')
const pnpm = makeRecordingPnpm(dir)
process.env.RECORD = record
process.env.EXIT = '0'
try {
runPnpmInstall({
binName: 'dsh', profileDir: dir, installAnchor: join(dir, 'package.json'),
nodeBin: process.execPath, pnpmCjs: pnpm, spec: 'x',
before: readProfileManifest('dsh', dir), registry: 'https://mirror.example',
})
const args = JSON.parse(readFileSync(record, 'utf8')) as string[]
expect(args).toContain('--registry')
expect(args).toContain('https://mirror.example')
} finally {
delete process.env.RECORD
delete process.env.EXIT
}
})
})
describe('runPnpmInstallWithRegistries', () => {
it('tries registries until one succeeds', () => {
const dir = makeProfile()
const record = join(dir, 'record.json')
const pnpm = makeRecordingPnpm(dir)
process.env.RECORD = record
process.env.EXIT = '0'
process.env.FAIL_REG = 'https://bad.example'
try {
runPnpmInstallWithRegistries({
binName: 'dsh', profileDir: dir, installAnchor: join(dir, 'package.json'),
nodeBin: process.execPath, pnpmCjs: pnpm, spec: 'x',
before: readProfileManifest('dsh', dir),
}, ['https://bad.example', 'https://good.example'])
const args = JSON.parse(readFileSync(record, 'utf8')) as string[]
expect(args).toContain('https://good.example')
} finally {
delete process.env.RECORD
delete process.env.EXIT
delete process.env.FAIL_REG
}
})
it('throws when every registry fails', () => {
const dir = makeProfile()
const pnpm = makeFakePnpm(dir, 1)
expect(() => { runPnpmInstallWithRegistries({
binName: 'dsh', profileDir: dir, installAnchor: join(dir, 'package.json'),
nodeBin: process.execPath, pnpmCjs: pnpm, spec: 'x',
before: readProfileManifest('dsh', dir),
}, ['https://a.example', 'https://b.example']) }).toThrow(/across all registries/)
})
})
describe('INSTALL_REGISTRIES', () => {
it('ends with the official npm registry as the fallback', () => {
expect(INSTALL_REGISTRIES[INSTALL_REGISTRIES.length - 1]).toBe('https://registry.npmjs.org')
})
})
describe('composeOfflineBundle with a bare manifest', () => {
@@ -2,7 +2,7 @@ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'nod
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { pathToFileURL } from 'node:url'
import { afterEach, describe, expect, it } from 'vitest'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { Context, type Plugin } from '@deepseek-ai/cordis'
import Loader from '@deepseek-ai/cordis-plugin-loader'
import { readProfileManifest } from '@deepseek-ai/dsh-app-boot'
@@ -126,20 +126,14 @@ describe('PluginInventoryGateway', () => {
expect(inventory.list().entries.some(entry => entry.entryId === pendingId)).toBe(false)
})
it('availableBundles reports installed state from the profile manifest', async () => {
it('availableBundles reports an empty offline catalog', async () => {
const { ctx, inventory } = await harness()
const dir = mkdtempSync(join(tmpdir(), 'dsh-inv-'))
contexts.push(ctx)
ctx.baseUrl = pathToFileURL(dir + '/').href
writeFileSync(join(dir, 'package.json'), JSON.stringify({
name: 'dsh-profile-test',
dsh: { profile: { bundles: ['@deepseek-ai/dsh-image-recognition-bundle'] } },
}))
writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: 'dsh-profile-test', dsh: { profile: { bundles: [] } } }))
try {
const snapshot = inventory.availableBundles()
expect(snapshot.available).toEqual([
{ name: '@deepseek-ai/dsh-image-recognition-bundle', installed: true },
])
expect(inventory.availableBundles().available).toEqual([])
} finally {
rmSync(dir, { recursive: true, force: true })
}
@@ -151,25 +145,40 @@ describe('PluginInventoryGateway', () => {
ctx.baseUrl = pathToFileURL(dir + '/').href
writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: 'dsh-profile-test', dsh: { profile: { bundles: [] } } }))
try {
expect(() => inventory.installPlugin({ type: 'bundle', name: 'x' })).toThrow(/install anchor is unavailable/)
await expect(inventory.installPlugin({ type: 'bundle', name: 'x' })).rejects.toThrow(/install anchor is unavailable/)
ctx.provide('dshInstallAnchor', join(dir, 'package.json'))
expect(() => inventory.installPlugin({ type: 'registry', spec: 'x' })).toThrow(/not permitted/)
await expect(inventory.installPlugin({ type: 'registry', spec: 'x' })).rejects.toThrow(/not permitted/)
} finally {
rmSync(dir, { recursive: true, force: true })
}
})
it('uninstall removes a bundle from the profile manifest', async () => {
it('refuses to install a default bundle', async () => {
const { ctx, inventory } = await harness()
const dir = mkdtempSync(join(tmpdir(), 'dsh-inv-'))
ctx.baseUrl = pathToFileURL(dir + '/').href
writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: 'dsh-profile-test', dsh: { profile: { bundles: [] } } }))
ctx.provide('dshInstallAnchor', join(dir, 'package.json'))
try {
await expect(inventory.installPlugin({ type: 'bundle', name: '@deepseek-ai/dsh-image-recognition-bundle' }))
.rejects.toThrow(/not installable/)
} finally {
rmSync(dir, { recursive: true, force: true })
}
})
it('refuses to uninstall a default bundle and removes an optional one', async () => {
const { ctx, inventory } = await harness()
const dir = mkdtempSync(join(tmpdir(), 'dsh-inv-'))
ctx.baseUrl = pathToFileURL(dir + '/').href
writeFileSync(join(dir, 'package.json'), JSON.stringify({
name: 'dsh-profile-test',
dsh: { profile: { bundles: ['@deepseek-ai/dsh-image-recognition-bundle'] } },
dsh: { profile: { bundles: ['@deepseek-ai/dsh-image-recognition-bundle', 'optional-bundle'] } },
}))
try {
expect(inventory.uninstall('@deepseek-ai/dsh-image-recognition-bundle').restartRequired).toBe(true)
expect(inventory.availableBundles().available[0]!.installed).toBe(false)
await expect(inventory.uninstall('@deepseek-ai/dsh-image-recognition-bundle')).rejects.toThrow(/cannot be uninstalled/)
expect((await inventory.uninstall('optional-bundle')).restartRequired).toBe(true)
expect(readProfileManifest('dsh', dir).dsh?.profile?.bundles).toEqual(['@deepseek-ai/dsh-image-recognition-bundle'])
} finally {
rmSync(dir, { recursive: true, force: true })
}
@@ -185,7 +194,7 @@ describe('PluginInventoryGateway', () => {
writeFileSync(join(dir, 'node_modules', 'b', 'cordis.patch.yml'), '[]\n')
ctx.provide('dshInstallAnchor', join(dir, 'package.json'))
try {
inventory.installPlugin({ type: 'bundle', name: 'b' })
await inventory.installPlugin({ type: 'bundle', name: 'b' })
expect(readProfileManifest('dsh', dir).dsh?.profile?.bundles).toEqual(['b'])
} finally {
rmSync(dir, { recursive: true, force: true })
@@ -203,7 +212,7 @@ describe('PluginInventoryGateway', () => {
try {
ctx.provide('dshInstallAnchor', join(dir, 'package.json'))
ctx.provide('dshAllowPluginInstall', true)
expect(inventory.installPlugin({ type: 'registry', spec: 'some-pkg' }).restartRequired).toBe(true)
expect((await inventory.installPlugin({ type: 'registry', spec: 'some-pkg' })).restartRequired).toBe(true)
} finally {
delete process.env.DSH_PNPM
rmSync(dir, { recursive: true, force: true })
@@ -215,12 +224,12 @@ describe('PluginInventoryGateway', () => {
expect(() => inventory.availableBundles()).toThrow(/profile directory/)
})
it('treats a missing profile manifest as no installed bundles', async () => {
it('treats a missing profile manifest as an empty catalog', async () => {
const { ctx, inventory } = await harness()
const dir = mkdtempSync(join(tmpdir(), 'dsh-inv-'))
ctx.baseUrl = pathToFileURL(dir + '/').href
try {
expect(inventory.availableBundles().available[0]!.installed).toBe(false)
expect(inventory.availableBundles().available).toEqual([])
} finally {
rmSync(dir, { recursive: true, force: true })
}
@@ -260,7 +269,7 @@ describe('PluginInventoryGateway', () => {
try {
ctx.provide('dshInstallAnchor', join(dir, 'package.json'))
ctx.provide('dshAllowPluginInstall', true)
expect(() => inventory.installPlugin({ type: 'registry', spec: 'x' })).toThrow(/bundled pnpm is unavailable/)
await expect(inventory.installPlugin({ type: 'registry', spec: 'x' })).rejects.toThrow(/bundled pnpm is unavailable/)
} finally {
rmSync(dir, { recursive: true, force: true })
}
@@ -276,10 +285,30 @@ describe('PluginInventoryGateway', () => {
try {
ctx.provide('dshInstallAnchor', join(dir, 'package.json'))
ctx.provide('dshAllowPluginInstall', true)
expect(() => inventory.installPlugin({ type: 'registry', spec: 'x' })).toThrow(/failed to read profile manifest/)
await expect(inventory.installPlugin({ type: 'registry', spec: 'x' })).rejects.toThrow(/failed to read profile manifest/)
} finally {
delete process.env.DSH_PNPM
rmSync(dir, { recursive: true, force: true })
}
})
it('triggers a live recompose when a reload handle is provided', async () => {
const { ctx, inventory } = await harness()
const dir = mkdtempSync(join(tmpdir(), 'dsh-inv-'))
ctx.baseUrl = pathToFileURL(dir + '/').href
writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: 'dsh-profile-test', dsh: { profile: { bundles: [] } } }))
mkdirSync(join(dir, 'node_modules', 'b'), { recursive: true })
writeFileSync(join(dir, 'node_modules', 'b', 'package.json'), JSON.stringify({ name: 'b', dsh: { bundle: { patch: './cordis.patch.yml' } } }))
writeFileSync(join(dir, 'node_modules', 'b', 'cordis.patch.yml'), '[]\n')
ctx.provide('dshInstallAnchor', join(dir, 'package.json'))
const reload = vi.fn(async () => {})
ctx.provide('dshReloadProfile', reload)
try {
const result = await inventory.installPlugin({ type: 'bundle', name: 'b' })
expect(result.restartRequired).toBe(false)
expect(reload).toHaveBeenCalledOnce()
} finally {
rmSync(dir, { recursive: true, force: true })
}
})
})
@@ -4,22 +4,24 @@ import { isRequiredPlugin, isUserToggleable } from '../src/required.ts'
describe('isRequiredPlugin (blacklist/whitelist, default-open)', () => {
it('marks the blacklist core as required', () => {
for (const name of ['@deepseek-ai/cordis-plugin-loader', '@deepseek-ai/dsh-session', 'cordis:required']) {
for (const name of ['@deepseek-ai/cordis-plugin-loader', '@deepseek-ai/dsh-session', 'cordis:required', 'cordis:include']) {
expect(isRequiredPlugin(name)).toBe(true)
expect(isUserToggleable(name)).toBe(false)
}
})
it('defaults everything else to toggleable', () => {
for (const name of ['@deepseek-ai/dsh-hmr', '@deepseek-ai/dsh-tool-todo', 'cordis:user-toggleable']) {
it('whitelists the currently-disabled set as toggleable', () => {
for (const name of [
'@deepseek-ai/dsh-tool-pwsh', '@deepseek-ai/dsh-skill-badge',
'@deepseek-ai/dsh-session-telemetry-otel', '@deepseek-ai/dsh-pwsh-sandbox',
]) {
expect(isRequiredPlugin(name)).toBe(false)
expect(isUserToggleable(name)).toBe(true)
}
})
it('whitelist overrides the blacklist for an explicitly toggleable plugin', () => {
// image-recognition is on the whitelist, so it is never required.
for (const name of ['@deepseek-ai/dsh-image-recognition', '@deepseek-ai/dsh-image-recognition-http']) {
it('defaults unknown modules to toggleable', () => {
for (const name of ['@fixture/never', 'cordis:user-toggleable']) {
expect(isRequiredPlugin(name)).toBe(false)
expect(isUserToggleable(name)).toBe(true)
}
@@ -27,8 +29,7 @@ describe('isRequiredPlugin (blacklist/whitelist, default-open)', () => {
})
describe('AVAILABLE_BUNDLES', () => {
it('lists the offline-installable optional bundles', () => {
expect(AVAILABLE_BUNDLES).toContain('@deepseek-ai/dsh-image-recognition-bundle')
expect(new Set(AVAILABLE_BUNDLES).size).toBe(AVAILABLE_BUNDLES.length)
it('is empty: no optional bundles ship as offline-installable yet', () => {
expect(AVAILABLE_BUNDLES).toEqual([])
})
})