diff --git a/packages/boot/app-boot/src/profile.ts b/packages/boot/app-boot/src/profile.ts index bc1fd14804..d0f78356ae 100644 --- a/packages/boot/app-boot/src/profile.ts +++ b/packages/boot/app-boot/src/profile.ts @@ -201,7 +201,7 @@ const INSTALLATION_OWNED_PROFILE_TUPLES: Record = { /** * Bundles an earlier release shipped and the installation no longer carries; - * loading a profile removes them from its bundle list. + * {@link loadProfileDirectory} removes them from the profile's bundle list. */ const RETIRED_BUNDLES: ReadonlySet = new Set([ // The Web composition mounts Schedule itself @@ -581,30 +581,47 @@ function sameBundles(left: readonly string[], right: readonly string[]): boolean return left.length === right.length && left.every((value, index) => value === right[index]) } -/** - * Normalize an exact installation-owned bundle tuple to its shipped template, - * and drop {@link RETIRED_BUNDLES} from any other bundle list, preserving all - * other manifest fields. The manifest is written only when its bundles change. - */ -function normalizeProfileManifest(name: string, dir: string, manifest: ProfileManifest): void { - const bundles = manifest.dsh?.profile?.bundles - if (bundles === undefined) return - const installationOwned = INSTALLATION_OWNED_PROFILE_TUPLES[name] - const template = PROFILE_TEMPLATES[name] - const normalized = template !== undefined && installationOwned !== undefined && sameBundles(bundles, installationOwned) - ? template.bundles - : bundles.filter(bundle => !RETIRED_BUNDLES.has(bundle)) - if (sameBundles(normalized, bundles)) return - writeProfileManifest(dir, { +/** Return `manifest` with `dsh.profile.bundles` replaced, preserving all other fields. */ +function withBundles(manifest: ProfileManifest, bundles: readonly string[]): ProfileManifest { + return { ...manifest, dsh: { ...manifest.dsh, profile: { ...manifest.dsh?.profile, - bundles: [...normalized], + bundles: [...bundles], }, }, - }) + } +} + +/** + * Normalize an exact installation-owned bundle tuple to its shipped template, + * preserving all other manifest fields. Other bundle lists remain untouched. + */ +function normalizeShippedProfile(name: string, dir: string, manifest: ProfileManifest): ProfileManifest { + const installationOwned = INSTALLATION_OWNED_PROFILE_TUPLES[name] + const template = PROFILE_TEMPLATES[name] + const bundles = manifest.dsh?.profile?.bundles + if (template === undefined || bundles === undefined) return manifest + const isRetiredTuple = installationOwned !== undefined && sameBundles(bundles, installationOwned) + if (!isRetiredTuple) return manifest + const normalized = withBundles(manifest, template.bundles) + writeProfileManifest(dir, normalized) + return normalized +} + +/** + * Remove {@link RETIRED_BUNDLES} from a profile's bundle list, writing the + * manifest back only when it listed one. + */ +function dropRetiredBundles(dir: string, manifest: ProfileManifest): ProfileManifest { + const bundles = manifest.dsh?.profile?.bundles ?? [] + const kept = bundles.filter(bundle => !RETIRED_BUNDLES.has(bundle)) + if (kept.length === bundles.length) return manifest + const normalized = withBundles(manifest, kept) + writeProfileManifest(dir, normalized) + return normalized } /** @@ -654,7 +671,8 @@ export function resolveBundleDir( * Load an already initialized profile directory without resolving it through * the shared Harness home. This is used by application-owned profiles whose * package project and lifecycle belong to that application. - * Unreadable bundles, and bundles whose own dsh peers the profile does not exempt, are skipped + * Retired bundles are removed from the stored bundle list first, rewriting the + * manifest when it listed one. Unreadable bundles, and bundles whose own dsh peers the profile does not exempt, are skipped * without changing the manifest and listed in `skippedBundles`; nothing is printed. * @param binName - the diagnostic prefix on thrown errors. * @param dir - absolute profile package directory. @@ -668,7 +686,7 @@ export function loadProfileDirectory( installAnchor: string, options: { userLayer?: boolean } = {}, ): Profile { - const manifest = readProfileManifest(binName, dir) + const manifest = dropRetiredBundles(dir, readProfileManifest(binName, dir)) const bundles = manifest.dsh?.profile?.bundles ?? [] const layers: ProfileLayer[] = [] const skippedBundles: SkippedBundle[] = [] @@ -700,8 +718,7 @@ export function loadProfileDirectory( /** * Load a profile: resolve every `dsh.profile.bundles` entry to its patch - * layer and parse the profile's own patch file. The stored bundle list first - * drops retired bundles and a retired installation-owned tuple. Unreadable or incompatible bundles + * layer and parse the profile's own patch file. Unreadable or incompatible bundles * are skipped and listed in `skippedBundles`; profile manifest and user patch errors still throw. * @param binName - the diagnostic prefix on thrown errors. * @param name - the profile name. @@ -727,7 +744,7 @@ export function loadProfile( initProfile(dir, template.bundles) } removeLinkProjections(dir) - normalizeProfileManifest(name, dir, readProfileManifest(binName, dir)) + normalizeShippedProfile(name, dir, readProfileManifest(binName, dir)) return loadProfileDirectory(binName, dir, installAnchor, options) } diff --git a/packages/boot/app-boot/tests/profile.spec.ts b/packages/boot/app-boot/tests/profile.spec.ts index 834dc950f0..297b198401 100644 --- a/packages/boot/app-boot/tests/profile.spec.ts +++ b/packages/boot/app-boot/tests/profile.spec.ts @@ -386,17 +386,17 @@ describe('loadProfile', () => { ]) }) - it('removes a retired bundle from any profile and keeps the rest of the manifest', () => { + it('removes a retired bundle from an application-owned profile and keeps the rest of the manifest', () => { const anchor = stageInstallation({ '@deepseek-ai/dsh-base': { patch: '[]\n' }, 'custom-bundle': { patch: '[]\n' }, }) - const home = tmp() - const dir = resolveProfileDir('custom', home) + const dir = join(tmp(), 'app-profile') initProfile(dir, ['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-experimental-schedule-bundle', 'custom-bundle']) writeProfileManifest(dir, { ...readProfileManifest('t', dir), dependencies: { 'custom-bundle': '^1.0.0' } }) - const profile = loadProfile('t', 'custom', anchor, home) + const profile = loadProfileDirectory('t', dir, anchor) expect(profile.skippedBundles).toEqual([]) + expect(profile.layers.map(layer => layer.packageName)).toEqual(['@deepseek-ai/dsh-base', 'custom-bundle']) expect(readProfileManifest('t', dir)).toMatchObject({ dependencies: { 'custom-bundle': '^1.0.0' }, dsh: { profile: { bundles: ['@deepseek-ai/dsh-base', 'custom-bundle'] } }, diff --git a/packages/boot/plugin-manager/README.i18n.yaml b/packages/boot/plugin-manager/README.i18n.yaml index 7b503ceb6a..5d9059f39c 100644 --- a/packages/boot/plugin-manager/README.i18n.yaml +++ b/packages/boot/plugin-manager/README.i18n.yaml @@ -48,8 +48,8 @@ en: fde2d9491fe5dd4f zh: ef6e6db15c4f19d2 /deepseek-ai-dsh-plugin-manager/known-limitations-and-deferred-work/failure-behavior: - en: 61450cf6e03c2819 - zh: 4d52f5306825787b + en: 4b31f3638e4a6628 + zh: 23f6599a963bcf89 /deepseek-ai-dsh-plugin-manager/known-limitations-and-deferred-work/dev-note: en: e67f633dc6fe7773 zh: 3bb0c20c93f16f98 diff --git a/packages/boot/plugin-manager/README.md b/packages/boot/plugin-manager/README.md index eabc124c92..7afa06c478 100644 --- a/packages/boot/plugin-manager/README.md +++ b/packages/boot/plugin-manager/README.md @@ -145,7 +145,7 @@ Failures preserve completed steps and report the actual remaining state. Profile | Enable: saving selection or loading fails | Keep the installed dependency and any saved selection. Report enablement failure; allow repair, disablement or removal. | | Remove: any step fails | Stop at the failed step. Preserve completed changes, retain remaining dependencies for retry, and report removal failure. Do not re-enable the bundle. | -Installation finishes after pnpm and bundle validation succeed; subsequent enablement failure does not undo installation. Removal proceeds in order: remove the bundle from `dsh.profile.bundles`, unload its runtime contributions, then run `pnpm remove`. A failed step prevents subsequent steps. +Installation finishes after pnpm and bundle validation succeed; subsequent enablement failure does not undo installation. Removal proceeds in order: remove the bundle from `dsh.profile.bundles`, unload its runtime contributions, then run `pnpm remove`. A failed step prevents subsequent steps. A selected name that neither the profile's dependencies nor the installation holds, such as a retired bundle, is also removable; its removal stops after deselection and runs no pnpm. Restoration rewrites only the two snapshotted files; user-authored patch configuration, application data, diagnostic logs and files pnpm downloaded remain untouched, and the next package operation prunes packages no manifest references. diff --git a/packages/boot/plugin-manager/README.zh.md b/packages/boot/plugin-manager/README.zh.md index c715052d8f..4ebb4cd1f2 100644 --- a/packages/boot/plugin-manager/README.zh.md +++ b/packages/boot/plugin-manager/README.zh.md @@ -145,7 +145,7 @@ CLI 提供 `dsh plugin --profile version-exemptions`、`allow-version | 启用:保存选择项或加载失败 | 保留已安装的依赖和已保存的选择项。报告启用失败,允许修正、停用或卸载。 | | 卸载:任一步失败 | 停在失败步骤,保留已完成的改动和待重试删除的依赖,报告卸载失败。不重新启用组合包。 | -pnpm 执行和组合包校验成功即完成安装,后续启用失败不撤销安装。卸载依次执行:从 `dsh.profile.bundles` 移除组合包、卸载运行时贡献、执行 `pnpm remove`。任一步失败都不继续执行后续步骤。 +pnpm 执行和组合包校验成功即完成安装,后续启用失败不撤销安装。卸载依次执行:从 `dsh.profile.bundles` 移除组合包、卸载运行时贡献、执行 `pnpm remove`。任一步失败都不继续执行后续步骤。profile 依赖和安装都不持有的已选名称(例如已下线的组合包)同样可卸载;其卸载在取消选择后结束,不运行 pnpm。 恢复只重写这两份快照文件;用户编写的 patch 配置、应用数据、诊断日志以及 pnpm 已下载的文件保持原样,没有 manifest 引用的包由下一次包操作清理。 diff --git a/packages/boot/plugin-manager/src/index.ts b/packages/boot/plugin-manager/src/index.ts index 10ca06c160..7994031ed3 100644 --- a/packages/boot/plugin-manager/src/index.ts +++ b/packages/boot/plugin-manager/src/index.ts @@ -289,12 +289,15 @@ export class PluginManager extends TypertRemoteService { for (const name of names) { const installed = dependencies.includes(name) const optional = OPTIONAL_BUNDLES.includes(name) - const removable = installed && !Object.hasOwn(installation.dependencies ?? {}, name) + const enabled = selected.includes(name) + const shipped = Object.hasOwn(installation.dependencies ?? {}, name) // Bundle resolution reads the installation first, so a profile dependency the installation manifest also names, // like one it forbids removing, is not the loaded copy. + const owned = installed && !shipped + // A selection neither the profile nor the installation holds, such as a retired bundle, is removed by deselecting it. + const removable = owned || (enabled && !installed && !shipped) const sourceOf = (packageName?: string): { source?: string } => - removable ? { source: dependencySpec(name, recorded[name] as string, this.profile.dir, packageName) } : {} - const enabled = selected.includes(name) + owned ? { source: dependencySpec(name, recorded[name] as string, this.profile.dir, packageName) } : {} const readOnlyReason = this.protectsManager(name) ? 'management-required' as const : undefined try { const info = bundleManifest(name, this.profile.dir, this.profile.installAnchor) @@ -599,14 +602,15 @@ export class PluginManager extends TypertRemoteService { return { status: 'cancelled' } } - /** Unload and remove a profile-owned bundle dependency through dsh plugin's pnpm path. - * @param name Installed dependency name. + /** Unload and remove a profile-owned bundle dependency through dsh plugin's pnpm path; a selected name no + * dependency holds is only deselected. + * @param name Installed dependency or selected bundle name. * @returns Removal diagnostics and the remaining profile state. */ @Remote removeBundle(name: string): Promise { return this.change(async (result) => { - await this.configure(async () => { + const installed = await this.configure(async () => { const bundle = (await this.listBundles()).find(item => item.name === name) if (bundle === undefined || !bundle.removable) throw new ManagementFailure('not-removable') if (this.ownerContext.get('hmr') === undefined && (this.profile.startedBundles.includes(name) @@ -623,7 +627,9 @@ export class PluginManager extends TypertRemoteService { && contributions.some(row => row.id === entry.options.id && row.name === entry.options.name))) { throw new ManagementFailure('bundle-in-use') } + return bundle.installed }) + if (!installed) return result.packageResult = await this.runPnpm(['remove', name]) if (result.packageResult.exitCode !== 0 || result.packageResult.timedOut === true) { throw new Error(result.packageResult.output) diff --git a/packages/boot/plugin-manager/tests/manager.spec.ts b/packages/boot/plugin-manager/tests/manager.spec.ts index fa8b926bae..1efa18f0e3 100644 --- a/packages/boot/plugin-manager/tests/manager.spec.ts +++ b/packages/boot/plugin-manager/tests/manager.spec.ts @@ -1088,6 +1088,23 @@ it('offers the launcher\'s optional bundles switched off and never removable', a expect(await manager.removeBundle(offered)).toMatchObject({ changed: false, application: 'failed' }) }) +it('removes a selected bundle no dependency holds by deselecting it without pnpm', async () => { + const { manager, dir } = await fixture() + const manifest = readProfileManifest('test', dir) + writeFileSync(join(dir, 'package.json'), JSON.stringify({ + ...manifest, dsh: { profile: { bundles: [...manifest.dsh?.profile?.bundles ?? [], 'retired'] } }, + })) + expect((await manager.listBundles()).find(row => row.name === 'retired')).toMatchObject({ + enabled: true, installed: false, optional: false, removable: true, error: { code: 'operation-error' }, + }) + const pnpm = vi.spyOn(operations, 'runProfilePnpm') + onTestFinished(() => { pnpm.mockRestore() }) + expect(await manager.removeBundle('retired')).toMatchObject({ changed: true, application: 'applied' }) + expect(pnpm).not.toHaveBeenCalled() + expect(readProfileManifest('test', dir).dsh?.profile?.bundles).not.toContain('retired') + expect((await manager.listBundles()).some(row => row.name === 'retired')).toBe(false) +}) + it('omits installation-owned plain packages from the bundle inventory', async () => { const { manager, dir, profile, bundle } = await fixture() bundle('installation-plain', []) diff --git a/packages/client/ui-plugin-manager/README.i18n.yaml b/packages/client/ui-plugin-manager/README.i18n.yaml index 42c48c46ed..f0015f23b4 100644 --- a/packages/client/ui-plugin-manager/README.i18n.yaml +++ b/packages/client/ui-plugin-manager/README.i18n.yaml @@ -33,8 +33,8 @@ en: 87f6d96467dc2383 zh: e0fb91aa4c4d5a12 /deepseek-ai-dsh-client-ui-plugin-manager/understand-the-implementation: - en: 8ca48e1365f18adf - zh: 91eadd683d2d8b5b + en: 203168fc87e939bd + zh: 72d0ccd2c54f3f44 /deepseek-ai-dsh-client-ui-plugin-manager/understand-the-implementation/registration: en: 3d70281f082988a5 zh: 17c6f595e3b57260 diff --git a/packages/client/ui-plugin-manager/README.md b/packages/client/ui-plugin-manager/README.md index 8e70c66e45..afe82f4444 100644 --- a/packages/client/ui-plugin-manager/README.md +++ b/packages/client/ui-plugin-manager/README.md @@ -97,7 +97,7 @@ A row's page exists only while a `plugins.row.config` entry names the row, so a ## Understand the implementation -Package management uses the profile's dependency records: installed bundles can be toggled and removed; installation-owned bundles remain locked. This distinction does not select startup failure policy. +Package management uses the profile's dependency records: installed bundles can be toggled and removed; installation-owned bundles remain locked. A selected bundle that neither the profile nor the installation holds also offers uninstall, which only removes it from the profile's bundle list. This distinction does not select startup failure policy.
Implementation internals — click to expand diff --git a/packages/client/ui-plugin-manager/README.zh.md b/packages/client/ui-plugin-manager/README.zh.md index 75288b869d..94f635bf11 100644 --- a/packages/client/ui-plugin-manager/README.zh.md +++ b/packages/client/ui-plugin-manager/README.zh.md @@ -97,7 +97,7 @@ ctx.slots.inject('plugins.detail.section', () => ctx.slots.register({ ## 理解实现 -插件管理依据 profile 的依赖记录:已安装组合包可启停、可移除,随安装提供的组合包保持锁定。这一区分不决定启动失败策略。 +插件管理依据 profile 的依赖记录:已安装组合包可启停、可移除,随安装提供的组合包保持锁定。profile 与安装都不持有的已选组合包同样提供卸载,卸载只把它从 profile 的组合包列表中移除。这一区分不决定启动失败策略。
实现细节——点击展开 diff --git a/packages/client/ui-plugin-manager/src/client/PluginManagerPage.tsx b/packages/client/ui-plugin-manager/src/client/PluginManagerPage.tsx index 72a6e7bb3e..63a614928a 100644 --- a/packages/client/ui-plugin-manager/src/client/PluginManagerPage.tsx +++ b/packages/client/ui-plugin-manager/src/client/PluginManagerPage.tsx @@ -602,7 +602,7 @@ function RowDetail({ pkg, row, t, resolveText, onBack, renderSlot, form }: { /** * One package's page: the crumb back to the list; its icon with its switch - * and, for a package the profile installed, uninstall; its title beside its + * and, for a package the profile installed or a selection the Host can remove, uninstall; its title beside its * version tag, its beta tag, and its problem tag; the package name the title * stands for; its one-liner; the Host's problem when it reports one; the * configuration the bundle registered for itself; its rows with their switches @@ -640,7 +640,7 @@ function PackageDetail({ actions={(
{renderSlot('plugins.detail.actions', { subject })} - {pkg.installed + {pkg.installed || pkg.removable ? (