diff --git a/.agents/notes/implemented/architecture/2026-09-09-plugin-management-in-the-web-sidebar.i18n.yaml b/.agents/notes/implemented/architecture/2026-09-09-plugin-management-in-the-web-sidebar.i18n.yaml index 8317ed54be..3651cceda4 100644 --- a/.agents/notes/implemented/architecture/2026-09-09-plugin-management-in-the-web-sidebar.i18n.yaml +++ b/.agents/notes/implemented/architecture/2026-09-09-plugin-management-in-the-web-sidebar.i18n.yaml @@ -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 .agents/notes/implemented/architecture/2026-09-09-plugin-management-in-the-web-sidebar.md -2026-09-09-plugin-management-in-the-web-sidebar.md: 229cde95a133d7ae96fa57eb3b071fa9eb887d59 -2026-09-09-plugin-management-in-the-web-sidebar.zh.md: 1238179a15d64806c50eb5a634a8c85e1d9902d4 +2026-09-09-plugin-management-in-the-web-sidebar.md: 562fafcb9307f1ff61b361c94fdde79cbf5175dc +2026-09-09-plugin-management-in-the-web-sidebar.zh.md: 58515c1f0d25a0ffb7d902abcccc8da46d3b281d diff --git a/.agents/notes/implemented/architecture/2026-09-09-plugin-management-in-the-web-sidebar.md b/.agents/notes/implemented/architecture/2026-09-09-plugin-management-in-the-web-sidebar.md index 229cde95a1..562fafcb93 100644 --- a/.agents/notes/implemented/architecture/2026-09-09-plugin-management-in-the-web-sidebar.md +++ b/.agents/notes/implemented/architecture/2026-09-09-plugin-management-in-the-web-sidebar.md @@ -14,6 +14,8 @@ Installed packages belong to the running profile, while Settings is a modal over **One store follows Host state.** The manager controller reads package views, refreshes after management operations and reconnects, and keeps installation progress under the owning job. Configuration cards use the existing global settings bindings. +**Installation results belong to a request.** The dialog generates a fresh request id for every install or retry and filters Host progress, logs, and responses by that id. A cancellation acknowledgement can arrive before the original add response, so that response cannot settle a subsequent retry. Cancellation uses the manager's explicit cleanup acknowledgement; local RPC cancellation and connection loss never imply that pnpm has stopped. The application phase closes the cancellation window. + ## Alternatives considered **A settings section that opens the management page.** Rejected: the dialog covers the main column, so such an entry would have to close Settings to show the page. diff --git a/.agents/notes/implemented/architecture/2026-09-09-plugin-management-in-the-web-sidebar.zh.md b/.agents/notes/implemented/architecture/2026-09-09-plugin-management-in-the-web-sidebar.zh.md index 1238179a15..58515c1f0d 100644 --- a/.agents/notes/implemented/architecture/2026-09-09-plugin-management-in-the-web-sidebar.zh.md +++ b/.agents/notes/implemented/architecture/2026-09-09-plugin-management-in-the-web-sidebar.zh.md @@ -14,6 +14,8 @@ Status: implemented **一个 store 跟随 Host 状态。** 管理器控制器读取包视图,在管理操作和重连后刷新,并按所属 job 保存安装进度。配置卡片使用原有全局 settings 绑定。 +**安装结果属于一次请求。** 每次安装或重试都生成新的请求 ID,对话框按该 ID 筛选 Host 进度、日志和返回结果。取消确认可能先于原 add 响应到达,因此旧响应不能结束随后的重试。取消采用管理器的明确清理确认;本地 RPC 取消和断线均不表示 pnpm 已停止。进入配置应用阶段后关闭取消窗口。 + ## 考虑过的替代方案 **用一个设置分区打开管理页。** 否决:对话框盖住主列,这样的入口必须先关掉设置才能显示页面。 diff --git a/apps/web/tests/expected/plugin-install-cancel/cancelled.expected.md b/apps/web/tests/expected/plugin-install-cancel/cancelled.expected.md new file mode 100644 index 0000000000..bed55e75b9 --- /dev/null +++ b/apps/web/tests/expected/plugin-install-cancel/cancelled.expected.md @@ -0,0 +1,19 @@ +- dialog "添加插件": + - heading "添加插件" [level=2] + - button "关闭": + - img + - paragraph: 输入插件的包名、本地路径或 Git 地址。 + - text: 包名或地址 + - textbox "包名或地址": + - /placeholder: dsh-better-sidebar 或 /path/to/plugin + - text: slow-package + - text: 例如 dsh-better-sidebar、github:someone/dsh-plugin、/path/to/plugin + - checkbox "安装完成后直接启用" [checked] + - text: 安装完成后直接启用 + - status: 已取消安装,本次未继续启用插件。下载缓存或已解包文件可能保留,需要时可重新安装。 + - paragraph: 安装位置:{{cwd}}/.dsh-home/profiles/scaffold + - text: 已取消 $ {{node}} add slow-package 未正常退出 + - button "复制" + - text: "Waiting for package download plugin-manager: installation cancelled" + - button "完成" + - button "重试" diff --git a/apps/web/tests/plugin-install-cancel.e2e.ts b/apps/web/tests/plugin-install-cancel.e2e.ts new file mode 100644 index 0000000000..25964f1c65 --- /dev/null +++ b/apps/web/tests/plugin-install-cancel.e2e.ts @@ -0,0 +1,66 @@ +// A real Host/Remote/browser composition with a controllable package-manager process. +// No model call is needed: installation state and profile files are the observable result. +import { mkdtemp, readFile, writeFile, rm } from 'node:fs/promises' +import { tmpdir } from 'node:os' +import { join } from 'node:path' +import { fileURLToPath } from 'node:url' +import { chromium } from 'playwright' +import { expect, it } from 'vitest' +import { launchWebScaffold, captureStableAria, compareOrRefreshGolden, webSnapshotMode, watchConsole, type WebScaffold } from './scaffold.ts' +import { ZH_BROWSER_LOCALE } from './support.ts' + +it('cancels installation through the UI, restores files, and accepts a retry', async () => { + const scratch = await mkdtemp(join(tmpdir(), 'dsh-install-cancel-')) + const overlay = join(scratch, 'cordis.patch.yml') + await writeFile(overlay, `- id: plugin-manager\n config: ${JSON.stringify({ pnpmCommand: process.execPath, installTimeoutMs: 60_000, installKillGraceMs: 50 })}\n`) + let scaffold: WebScaffold | undefined + try { + scaffold = await launchWebScaffold({ profileRuntime: { packages: [] }, extraOverlayPath: overlay }) + const browser = await chromium.launch() + try { + const profile = join(scaffold.harnessHome, 'profiles', 'scaffold') + const manifestPath = join(profile, 'package.json') + const manifest = await readFile(manifestPath, 'utf8') + const lockPath = join(profile, 'pnpm-lock.yaml') + await writeFile(lockPath, 'original lockfile\n') + // Node stands in for the pnpm executable; the same installer owns and stops this real child. + await writeFile(join(profile, 'add'), ` + import('node:fs').then(fs => { + fs.writeFileSync('package.json', JSON.stringify({ ...JSON.parse(fs.readFileSync('package.json', 'utf8')), dependencies: { partial: '1.0.0' } })); + fs.writeFileSync('pnpm-lock.yaml', 'partial lockfile'); + console.log('Waiting for package download'); + setInterval(() => {}, 1000); + }); + `) + const page = await browser.newPage({ viewport: { width: 1440, height: 1000 }, locale: ZH_BROWSER_LOCALE }) + const tripwire = watchConsole(page) + await page.goto(scaffold.authenticatedUrl) + await page.waitForSelector('[class*="frame"]') + if (await page.getByRole('dialog', { name: '设置' }).count() > 0) await page.keyboard.press('Escape') + await page.getByRole('navigation', { name: '全局面板' }).getByRole('button', { name: '插件', exact: true }).click() + const panel = page.locator('[data-plugin-panel]') + await panel.getByRole('button', { name: '添加插件', exact: true }).click() + const dialog = page.getByRole('dialog', { name: '添加插件' }) + await dialog.getByRole('textbox').fill('slow-package') + await dialog.getByRole('button', { name: '安装', exact: true }).click() + await dialog.getByText('Waiting for package download', { exact: true }).waitFor() + await dialog.getByRole('button', { name: '取消安装', exact: true }).click() + await dialog.getByText('已取消安装,本次未继续启用插件。下载缓存或已解包文件可能保留,需要时可重新安装。', { exact: true }).waitFor() + expect(await readFile(manifestPath, 'utf8')).toBe(manifest) + expect(await readFile(lockPath, 'utf8')).toBe('original lockfile\n') + expect(await dialog.getByRole('textbox').inputValue()).toBe('slow-package') + const snapshot = (await captureStableAria(page, '[role="dialog"]', scaffold.workspaceCwd)) + .split(process.execPath).join('{{node}}') + .split(scaffold.harnessHome).join('{{harnessHome}}') + await compareOrRefreshGolden(fileURLToPath(new URL('./expected/plugin-install-cancel/cancelled.expected.md', import.meta.url)), snapshot, webSnapshotMode()) + await writeFile(join(profile, 'add'), 'console.log("Retry completed")\n') + await dialog.getByRole('button', { name: '重试', exact: true }).click() + await dialog.getByText('Retry completed', { exact: true }).waitFor() + await expect.poll(() => dialog.getByRole('button', { name: '完成', exact: true }).count()).toBeGreaterThan(0) + expect(tripwire.pageErrors).toEqual([]) + } finally { await browser.close() } + } finally { + await scaffold?.close() + await rm(scratch, { recursive: true, force: true }) + } +}) diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index 580ea48443..2ef7735684 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -47,6 +47,7 @@ "tests/document-preview.e2e.ts", "tests/plugin-config.e2e.ts", "tests/plugin-manager.e2e.ts", + "tests/plugin-install-cancel.e2e.ts", "tests/settings-chrome.e2e.ts", "tests/models-settings.e2e.ts", "tests/deepseek-messages-settings.e2e.ts", diff --git a/packages/client/ui-plugin-manager/README.i18n.yaml b/packages/client/ui-plugin-manager/README.i18n.yaml index 52bcb61426..9a86c75c4d 100644 --- a/packages/client/ui-plugin-manager/README.i18n.yaml +++ b/packages/client/ui-plugin-manager/README.i18n.yaml @@ -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/client/ui-plugin-manager/README.md -README.md: 206b014932c72674891f21a0336beda7f5c00b34 -README.zh.md: 584beace4ab880c480415bfe111eb57e5afd37da +README.md: bebcef310371aff791960c9cf2415d140655294f +README.zh.md: 315eca1bbf5e0924ff9a7510cc48405124d08456 diff --git a/packages/client/ui-plugin-manager/README.md b/packages/client/ui-plugin-manager/README.md index 206b014932..bebcef3103 100644 --- a/packages/client/ui-plugin-manager/README.md +++ b/packages/client/ui-plugin-manager/README.md @@ -45,6 +45,8 @@ Non-bundle dependencies remain installed and appear under **Other installed pack ----- +During installation, **Cancel installation** requests Host cleanup and shows **Stopping installation** until it is confirmed. Configuration application cannot be cancelled. A cancelled dialog keeps the package spec and logs and offers retry; downloaded or unpacked files can remain. Closing the dialog is blocked while the Host owns the operation. A connection error does not confirm cancellation. + ## Understand the implementation diff --git a/packages/client/ui-plugin-manager/README.zh.md b/packages/client/ui-plugin-manager/README.zh.md index 584beace4a..315eca1bbf 100644 --- a/packages/client/ui-plugin-manager/README.zh.md +++ b/packages/client/ui-plugin-manager/README.zh.md @@ -45,6 +45,8 @@ kind: "package-reference" ----- +安装期间可点击**取消安装**,页面显示**正在停止安装**,直到 Host 确认清理完成。配置应用阶段不可取消。取消后的对话框保留包名和日志,并提供重试;下载或解包文件可能保留。Host 仍在处理操作时不能关闭对话框。连接错误不代表取消成功。 + ## 理解实现 diff --git a/packages/client/ui-plugin-manager/package.json b/packages/client/ui-plugin-manager/package.json index d388b01adb..fd40d071bd 100644 --- a/packages/client/ui-plugin-manager/package.json +++ b/packages/client/ui-plugin-manager/package.json @@ -60,7 +60,8 @@ "@types/react": "~18.3.1", "clsx": "^2.1.1", "react": "^18.2.0", - "react-dom": "^18.2.0" + "react-dom": "^18.2.0", + "@deepseek-ai/dsh-util-crypto": "workspace:^" }, "files": [ "lib/index.js", diff --git a/packages/client/ui-plugin-manager/src/client/PluginManagerPage.tsx b/packages/client/ui-plugin-manager/src/client/PluginManagerPage.tsx index 334f717a64..4925686b75 100644 --- a/packages/client/ui-plugin-manager/src/client/PluginManagerPage.tsx +++ b/packages/client/ui-plugin-manager/src/client/PluginManagerPage.tsx @@ -5,6 +5,7 @@ * retain package information and uninstall without automatic composition actions. */ +import { isInstallPending } from './manager-store.ts' import { useEffect, useId, useState, type ReactNode } from 'react' import type { PluginInstallRejection, PluginPackageView } from '@deepseek-ai/dsh-api-remotes/client' import { @@ -433,15 +434,16 @@ function failureText(install: InstallState, t: Translate): string { } /** The install dialog: the spec, the enable choice, the run's progress, and a terminal per pnpm run. */ -function InstallDialog({ install, t, onClose, onEditSpec, onToggleEnable, onRun }: { +function InstallDialog({ install, t, onClose, onEditSpec, onToggleEnable, onRun, onCancel }: { readonly install: InstallState readonly t: Translate readonly onClose: () => void readonly onEditSpec: (text: string) => void readonly onToggleEnable: () => void readonly onRun: () => void + readonly onCancel: () => void }): ReactNode { - const running = install.phase === 'running' + const running = isInstallPending(install.phase) const exampleId = useId() const firstRun = install.runs[0] const outcomes: string[] = install.phase !== 'done' @@ -464,14 +466,16 @@ function InstallDialog({ install, t, onClose, onEditSpec, onToggleEnable, onRun className={css.installDialog as string} footer={install.phase === 'done' ? - : ( - <> - - - > - )} + : running + ? + : ( + <> + + + > + )} >
{t('installRunning', { spec: install.spec.trim() })}
+ ?{install.phase === 'starting' ? t('installStarting') : install.phase === 'cancelling' ? t('installCancelling') : install.phase === 'applying' ? t('installApplying') : t('installRunning', { spec: install.spec.trim() })}
: null} {outcomes.map(line =>{line}
)} {install.phase === 'done' ? install.removed.map(entry =>{removedText(entry, t)}
) : null} + {install.phase === 'cancelled' ?{t('installCancelled')}
: null} + {install.failure?.code === 'client/cancel-unconfirmed' ?{t('installCancelUnconfirmed', { reason: install.failure.reason })}
: null} {install.phase === 'failed' ?{failureText(install, t)}
: null} @@ -511,7 +517,7 @@ function InstallDialog({ install, t, onClose, onEditSpec, onToggleEnable, onRun running={run.exitCode === undefined} exitCode={run.exitCode} maxLines={INSTALL_TERMINAL_LINES} - labels={terminalLabels(t)} + labels={{ ...terminalLabels(t), ...(install.phase === 'cancelled' || install.phase === 'cancelling' ? { failed: t('installCancelledShort') } : {}) }} className={css.terminal} /> ))} @@ -680,6 +686,7 @@ export function PluginManagerPage(props: PluginManagerPageProps): ReactNode { onEditSpec={props.editInstallSpec} onToggleEnable={props.toggleInstallEnable} onRun={props.runInstall} + onCancel={props.cancelInstall} /> {state.confirm === null ? null diff --git a/packages/client/ui-plugin-manager/src/client/index.ts b/packages/client/ui-plugin-manager/src/client/index.ts index c01033cee0..8f3423f6e0 100644 --- a/packages/client/ui-plugin-manager/src/client/index.ts +++ b/packages/client/ui-plugin-manager/src/client/index.ts @@ -66,6 +66,7 @@ export function apply(ctx: ClientContext): void { const disposers = [ ctx.remote.$on('plugins/changed', refresh), ctx.remote.$on('plugins/install-log', (chunk) => { controller.appendLog(chunk) }), + ctx.remote.$on('plugins/install-state', (progress) => { controller.installProgress(progress) }), ctx.on('connection/reset', refresh), ] return () => { for (const dispose of disposers) dispose() } diff --git a/packages/client/ui-plugin-manager/src/client/locales.ts b/packages/client/ui-plugin-manager/src/client/locales.ts index 16a5bb8064..4170205937 100644 --- a/packages/client/ui-plugin-manager/src/client/locales.ts +++ b/packages/client/ui-plugin-manager/src/client/locales.ts @@ -63,6 +63,13 @@ export const zh = { installExample: '例如 dsh-better-sidebar、github:someone/dsh-plugin、/path/to/plugin', installEnable: '安装完成后直接启用', installRun: '安装', + installCancel: '取消安装', + installStarting: '正在准备安装…', + installCancelling: '正在停止安装…', + installApplying: '正在应用配置,请稍候…', + installCancelledShort: '已取消', + installCancelled: '已取消安装,本次未继续启用插件。下载缓存或已解包文件可能保留,需要时可重新安装。', + installCancelUnconfirmed: '尚未确认安装已停止,请重试取消或等待安装结果。{reason}', installRunning: '正在安装 {spec}…', installFailedTail: '安装失败:{reason}', installLocation: '安装位置:{dir}', @@ -214,6 +221,13 @@ export const en = { installExample: 'For example dsh-better-sidebar, github:someone/dsh-plugin, /path/to/plugin', installEnable: 'Enable right after installing', installRun: 'Install', + installCancel: 'Cancel installation', + installStarting: 'Preparing installation…', + installCancelling: 'Stopping installation…', + installApplying: 'Applying configuration, please wait…', + installCancelledShort: 'Cancelled', + installCancelled: 'Installation cancelled without proceeding to enable plugins. Downloaded or unpacked files may remain; reinstall if needed.', + installCancelUnconfirmed: 'Installation has not been confirmed stopped. Retry cancellation or wait for the installation result. {reason}', installRunning: 'Installing {spec}…', installFailedTail: 'The install failed: {reason}', installLocation: 'Installs into {dir}', diff --git a/packages/client/ui-plugin-manager/src/client/manager-store.ts b/packages/client/ui-plugin-manager/src/client/manager-store.ts index eb3605c07a..f49f1f71b1 100644 --- a/packages/client/ui-plugin-manager/src/client/manager-store.ts +++ b/packages/client/ui-plugin-manager/src/client/manager-store.ts @@ -6,6 +6,7 @@ * change made on another surface shows here without a manual refresh. */ +import { randomUUID } from '@deepseek-ai/dsh-util-crypto' import type { Context as ClientContext } from '@deepseek-ai/cordis' import type { PluginDependents, @@ -13,6 +14,8 @@ import type { PluginInstallLogChunk, PluginInstallRejection, PluginInstallResult, + PluginInstallRequestId, + PluginInstallProgress, PluginPackageView, } from '@deepseek-ai/dsh-api-remotes/client' import { createSnapshotStore, type SnapshotStore } from '@deepseek-ai/dsh-client-store' @@ -50,7 +53,9 @@ export interface InstallState { readonly spec: string /** Whether a newly installed bundle is enabled right away. */ readonly enable: boolean - readonly phase: 'idle' | 'running' | 'done' | 'failed' + readonly phase: 'idle' | 'starting' | 'running' | 'cancelling' | 'applying' | 'cancelled' | 'done' | 'failed' + /** Identifies this dialog's installation, including log and cancellation messages. */ + readonly requestId?: PluginInstallRequestId /** The pnpm runs of the open install, in the order they started. */ readonly runs: readonly InstallRun[] /** Dependencies the last run added and kept, once it finished. */ @@ -67,6 +72,15 @@ export interface InstallState { readonly failure: { readonly code: string; readonly reason: string } | null } +/** + * Whether an installation is still owned by the Host. + * @param phase - the dialog's current installation phase. + * @returns true until an authoritative result settles the installation. + */ +export function isInstallPending(phase: InstallState['phase']): boolean { + return phase === 'starting' || phase === 'running' || phase === 'cancelling' || phase === 'applying' +} + /** A destructive action waiting for the user's confirmation: a package's uninstall or disable, or one row's switch-off. */ export type ConfirmState = | { @@ -111,6 +125,8 @@ export interface PluginManagerFace { editInstallSpec: (text: string) => void toggleInstallEnable: () => void runInstall: () => void + /** Request cancellation and wait for Host cleanup. */ + cancelInstall: () => void /** Put a bundle into, or take it out of, the profile's layer list. */ setEnabled: (packageName: string, enabled: boolean) => void /** Compose an enabled bundle again from scratch. */ @@ -217,20 +233,23 @@ export class PluginManagerController { hooks: { pluginManager: this.store }, ensure: () => { if (this.getSnapshot().status === 'idle') void this.load() }, refresh: () => { void this.load() }, - openInstall: () => { this.patch({ install: { ...IDLE_INSTALL, open: true } }) }, + openInstall: () => { + if (!isInstallPending(this.getSnapshot().install.phase)) this.patch({ install: { ...IDLE_INSTALL, open: true } }) + }, closeInstall: () => { - if (this.getSnapshot().install.phase === 'running') return + if (isInstallPending(this.getSnapshot().install.phase)) return this.patch({ install: IDLE_INSTALL }) }, editInstallSpec: (text) => { const install = this.getSnapshot().install // A new spec after a settled run starts over: the outcome on screen belongs to the old spec. - this.patchInstall(install.phase === 'done' || install.phase === 'failed' + this.patchInstall(install.phase === 'done' || install.phase === 'failed' || install.phase === 'cancelled' ? { ...IDLE_INSTALL, open: true, enable: install.enable, spec: text } : { spec: text }) }, toggleInstallEnable: () => { this.patchInstall({ enable: !this.getSnapshot().install.enable }) }, runInstall: () => { void this.runInstall() }, + cancelInstall: () => { void this.cancelInstall() }, setEnabled: (packageName, enabled) => { void this.setEnabled(packageName, enabled) }, retry: (packageName) => { void this.run(packageName, { packageName }, async () => { @@ -251,18 +270,27 @@ export class PluginManagerController { } /** - * Fold one install-log chunk into its pnpm run. The Host runs one mutation - * at a time, so while this dialog's install is in flight every chunk is its - * own: the `add` run, then the removals that follow it under the removed - * packages' names. A run's last chunk may trail the answer that settled the - * dialog and still lands on its run; a chunk for a run the dialog has not - * seen counts only while the install is in flight. + * Follow the Host's cancellation window for this dialog's installation. + * @param progress - a request id and phase received from the Host. + */ + installProgress(progress: PluginInstallProgress): void { + const install = this.getSnapshot().install + if (install.requestId !== progress.requestId || !isInstallPending(install.phase)) return + // A queued start notification cannot undo the local user's cancellation request. + if (install.phase === 'cancelling' && progress.phase === 'installing') return + this.patchInstall({ phase: progress.phase === 'installing' ? 'running' : progress.phase }) + } + + /** + * Fold a chunk belonging to this installation into its pnpm command. + * A final chunk may arrive after the add response and still updates an existing run. * @param chunk - the chunk the Host forwarded. */ appendLog(chunk: PluginInstallLogChunk): void { const install = this.getSnapshot().install + if (chunk.requestId !== install.requestId) return const index = install.runs.findIndex(run => run.jobId === chunk.jobId) - if (index === -1 && install.phase !== 'running') return + if (index === -1 && !isInstallPending(install.phase)) return const settled = chunk.exitCode === undefined ? {} : { exitCode: chunk.exitCode } const runs = index === -1 ? [...install.runs, { jobId: chunk.jobId, command: chunk.argv.join(' '), cwd: chunk.cwd, output: chunk.text, ...settled }] @@ -410,20 +438,23 @@ export class PluginManagerController { private async runInstall(): Promise