DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(plugin): 面板里两类拦截都给可操作的 toast,且只在成功时重启
hairyffd43c386a8f2
diff --git a/src-tauri/src/service/plugin/install/single.rs b/src-tauri/src/service/plugin/install/single.rsindex ad47cdcf..f9a3474b 100644--- a/src-tauri/src/service/plugin/install/single.rs+++ b/src-tauri/src/service/plugin/install/single.rs@@ -17,7 +17,7 @@ use crate::service::workflow;use super::artifact::{ensure_plugin_entry_built, installed_package_name};use super::build_plugin_envs;use super::diagnose::{- git_transport_hint, network_error_hint, pick_error_message,+ git_transport_hint, incompatible_versions, network_error_hint, pick_error_message,policy_blocked_versions, policy_verification_network_failure, store_mismatch_hint,};use super::errors;@@ -344,6 +344,20 @@ async fn run_single_plugin_command(if exit_code != 0 {log::error!("dsh plugin {action} failed for {id} with exit code {exit_code}");+ // 版本兼容性拒绝:dsh 在 pnpm 之前核对插件声明的 DSH peer 依赖,未授权精确版本+ // 即拒绝(不下载、不构建),升级同样会撞上(新版本声明了更高的核心 peer 依赖)。+ // 与批量安装路径一致地解析成精确三元组,交前端「授权后重跑」;不记插件错误——+ // 插件没坏,只是待用户授权。+ let incompatible = incompatible_versions(&last_attempt);+ if !incompatible.is_empty() {+ log::warn!(+ "dsh refused the {action} for incompatible plugin versions: {incompatible:?}"+ );+ return Err(format!(+ "PLUGIN_VERSION_INCOMPATIBLE: {}",+ serde_json::to_string(&incompatible).unwrap_or_default()+ ));+ }// 真实的发布时长策略违规优先识别:档案已声明/装了太新的版本,pnpm 的 lockfile// 校验不放行,于是升级/卸载/安装都会在这里失败。不是插件故障、也不是网络问题// (发布时间都拿到了),重试无用——解析成精确 `包名@版本` 交给前端由用户授权,diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.jsonindex a1b98aaa..b8fa04f0 100644--- a/src/i18n/locales/en-US.json+++ b/src/i18n/locales/en-US.json@@ -265,10 +265,11 @@"plugins.remove_confirm_desc": "Uninstall {{name}}? Its features will no longer be available after removal.","plugins.remove_failed": "Failed to uninstall {{name}}","plugins.upgrade_failed": "Failed to upgrade {{name}}",- "plugins.policy_blocked_title": "Release-age policy is blocking plugin operations",- "plugins.policy_blocked_desc": "These versions are younger than 24 hours and pnpm does not resolve them by default, yet the profile already declares them, so every plugin operation fails. Authorising records their exact versions in the profile's exemption list and retries (exact versions only).",- "plugins.policy_blocked_confirm": "Authorise and retry",- "plugins.policy_allow_failed": "Failed to record the release-age exemption",+ "plugins.blocked_incompatible_title": "{{name}} is incompatible with the current core",+ "plugins.blocked_incompatible_desc": "The blocked version {{blocked}} declares DSH dependencies that do not match the running core; running it may cause crashes or data loss. Authorising records the exact-version exemption and retries.",+ "plugins.blocked_policy_title": "{{name}}'s new version is still inside the release-age window",+ "plugins.blocked_policy_desc": "The blocked version {{blocked}} was published less than 24 hours ago and pnpm does not resolve it by default, while the profile already declares it. Authorising records the exact-version exemption and retries.",+ "plugins.authorize_failed": "Authorisation failed","plugins.updated_toast": "Plugin {{name}} updated","plugins.removed_toast": "Plugin {{name}} uninstalled","plugins.disable": "Disable",@@ -352,6 +353,7 @@"config.harness": "Harness","buttons.cancel": "Cancel","buttons.confirm": "Confirm",+ "buttons.authorize": "Authorise","recovery.heading_one": "A plugin is preventing startup","recovery.heading_many": "{{count}} plugins are preventing startup","recovery.remove_one": "Remove this plugin and continue checking",diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.jsonindex 512c1ed2..b0c87fdb 100644--- a/src/i18n/locales/zh-CN.json+++ b/src/i18n/locales/zh-CN.json@@ -265,10 +265,11 @@"plugins.remove_confirm_desc": "确定卸载插件 {{name}} 吗?卸载后其功能将不可用。","plugins.remove_failed": "卸载插件 {{name}} 失败","plugins.upgrade_failed": "升级插件 {{name}} 失败",- "plugins.policy_blocked_title": "发布保护期挡住了插件操作",- "plugins.policy_blocked_desc": "这些版本发布不足 24 小时,pnpm 默认不解析,而档案已经声明了它们,因此每次插件操作都会失败。授权后会把它们的精确版本写进档案豁免清单并重跑(只对这些精确版本生效)。",- "plugins.policy_blocked_confirm": "授权并重试",- "plugins.policy_allow_failed": "记录发布保护豁免失败",+ "plugins.blocked_incompatible_title": "{{name}} 与当前核心不兼容",+ "plugins.blocked_incompatible_desc": "被拦下的版本 {{blocked}} 声明的 DSH 依赖与当前核心不一致,运行它可能导致崩溃或数据丢失。授权后写入精确版本豁免并重试。",+ "plugins.blocked_policy_title": "{{name}} 的新版本还在发布保护期内",+ "plugins.blocked_policy_desc": "被拦下的版本 {{blocked}} 发布不足 24 小时,pnpm 默认不解析,而档案已经声明了它。授权后写入精确版本豁免并重试。",+ "plugins.authorize_failed": "授权失败","plugins.updated_toast": "插件 {{name}} 已更新","plugins.removed_toast": "插件 {{name}} 已卸载","plugins.disable": "禁用",@@ -352,6 +353,7 @@"config.harness": "核心","buttons.cancel": "取消","buttons.confirm": "确定",+ "buttons.authorize": "授权","recovery.heading_one": "发现导致启动失败的插件","recovery.heading_many": "发现 {{count}} 个导致启动失败的插件","recovery.remove_one": "卸除此插件并继续检测",diff --git a/src/store/modules/preinstall/index.ts b/src/store/modules/preinstall/index.tsindex d7eb42d4..558cd9bd 100644--- a/src/store/modules/preinstall/index.ts+++ b/src/store/modules/preinstall/index.ts@@ -1,4 +1,5 @@-export { preinstall } from './store'+export { parseBlockedRefusal, preinstall } from './store'+export type { BlockedRefusal } from './store'export type {IncompatibleVersion,PolicyBlockedVersion,diff --git a/src/store/modules/preinstall/store.ts b/src/store/modules/preinstall/store.tsindex c7b8b470..0f12802c 100644--- a/src/store/modules/preinstall/store.ts+++ b/src/store/modules/preinstall/store.ts@@ -12,49 +12,45 @@ import { harnessUpdater } from '../harness-updater'const LOG_LIMIT = 200/**- * 后端版本兼容性拒绝的前缀:其后是 `IncompatibleVersion[]` 的 JSON。+ * 后端「拦截清单」的两套前缀:其后都是清单 JSON。*- * dsh 在 pnpm 之前核对插件声明的 DSH peer 依赖,未授权精确版本即整批拒绝。后端把- * 拒绝清单挂在错误串上(Tauri 命令的错误通道只有字符串),这里解出来交给界面走- * 「逐项授权 → 重试」;解析失败返回 null,退回普通的安装失败展示,绝不假装可授权。+ * dsh 的版本兼容性与 pnpm 的发布时长策略(`minimumReleaseAge`)是两套互不相干的拦截,+ * 但形状一致:后端把清单挂在错误串上(Tauri 命令的错误通道只有字符串),前端解出来+ * 交给用户逐项授权后重跑。*/const INCOMPATIBLE_PREFIX = 'PLUGIN_VERSION_INCOMPATIBLE:'--/**- * 发布时长策略拦下的载荷前缀(后端 `policy_blocked_versions` 的结果):其后是- * `{ name, version }[]` 的 JSON。- *- * 与 [`INCOMPATIBLE_PREFIX`] 是两套互不相干的拦截(dsh 的版本兼容性 vs pnpm 的- * `minimumReleaseAge`),但处理形状一致:都交给界面列出来让用户勾选授权后重跑。- */const POLICY_BLOCKED_PREFIX = 'PLUGIN_POLICY_BLOCKED:'+/** 被拦下的清单:核心版本兼容性拒绝,或 pnpm 发布时长策略拒绝。 */+export type BlockedRefusal+ = | { kind: 'incompatible', versions: IncompatibleVersion[] }+ | { kind: 'policy', versions: PolicyBlockedVersion[] }+/**- * 解析后端「发布时长策略拦下」的载荷([`POLICY_BLOCKED_PREFIX`] 之后的- * `{ name, version }[]` JSON);识别不出来返回 null,退回普通失败展示。+ * 解析后端拦截清单的错误载荷;识别不出来返回 null。+ *+ * 引导页与插件面板共用这一处解析:两边的错误通道都一样,规则必须一致。解析失败一律+ * 退回普通失败展示——绝不把读不出来的 JSON 当成可授权项(那会变成一次来路不明的授权)。*/-function parsePolicyBlocked(error: string): PolicyBlockedVersion[] | null {- if (!error.startsWith(POLICY_BLOCKED_PREFIX))- return null- try {- const parsed = JSON.parse(error.slice(POLICY_BLOCKED_PREFIX.length)) as PolicyBlockedVersion[]- return parsed.length > 0 ? parsed : null- }- catch (err) {- console.error('[Harness] failed to parse policy-blocked payload:', err)- return null- }+export function parseBlockedRefusal(error: string): BlockedRefusal | null {+ const incompatible = parseVersions<IncompatibleVersion>(error, INCOMPATIBLE_PREFIX)+ if (incompatible)+ return { kind: 'incompatible', versions: incompatible }+ const policy = parseVersions<PolicyBlockedVersion>(error, POLICY_BLOCKED_PREFIX)+ if (policy)+ return { kind: 'policy', versions: policy }+ return null}-function parseIncompatible(error: string): IncompatibleVersion[] | null {- if (!error.startsWith(INCOMPATIBLE_PREFIX))+function parseVersions<T>(error: string, prefix: string): T[] | null {+ if (!error.startsWith(prefix))return nulltry {- const parsed = JSON.parse(error.slice(INCOMPATIBLE_PREFIX.length)) as IncompatibleVersion[]+ const parsed = JSON.parse(error.slice(prefix.length)) as T[]return parsed.length > 0 ? parsed : null}catch (err) {- console.error('[Harness] failed to parse incompatible plugin payload:', err)+ console.error(`[Harness] failed to parse ${prefix} payload:`, err)return null}}@@ -150,15 +146,14 @@ export const preinstall = defineStore({catch (err) {console.error('[Harness] preinstall failed:', err)const error = String(err)- const incompatible = parseIncompatible(error)- const policyBlocked = parsePolicyBlocked(error)- if (incompatible) {+ const refusal = parseBlockedRefusal(error)+ if (refusal?.kind === 'incompatible') {// 不是故障而是待授权清单:交给界面展示风险与勾选,用户授权后重跑安装- this.incompatible = incompatible+ this.incompatible = refusal.versions}- else if (policyBlocked) {+ else if (refusal?.kind === 'policy') {// 同上,但拦下它的是 pnpm 的发布时长策略:清单同样交给界面勾选授权- this.policyBlocked = policyBlocked+ this.policyBlocked = refusal.versions}else {this.error = error.startsWith('NETWORK_ERROR:')diff --git a/src/ui/config/plugin.tsx b/src/ui/config/plugin.tsxindex bfbcdb00..2bdac912 100644--- a/src/ui/config/plugin.tsx+++ b/src/ui/config/plugin.tsx@@ -1,3 +1,4 @@+import type { BlockedRefusal } from '@/store/modules/preinstall'import type { DshPlugin } from '@/types'import { ChevronRight, CircleExclamation } from '@gravity-ui/icons'import { Button, Chip, Label, Spinner, Tooltip } from '@heroui/react'@@ -18,40 +19,10 @@ import { Panel } from '@/components/panel'import { queryKeys } from '@/config/query-keys'import { useListen } from '@/hooks/use-listen'import { store } from '@/store'+import { parseBlockedRefusal } from '@/store/modules/preinstall'import { silence } from '@/utils/silence'import { toast } from '@/utils/toast'-/**- * 被 pnpm 发布时长策略拦下的条目(后端 `PolicyBlockedVersion`)。- *- * 豁免是按精确 `包名@版本` 写进档案的 `minimumReleaseAgeExclude` 的,所以只需要这两个- * 字段;`published_at` 之类的细节由用户自己看时机,不参与授权键。- */-interface PolicyBlockedVersion {- name: string- version: string-}--const POLICY_BLOCKED_PREFIX = 'PLUGIN_POLICY_BLOCKED:'--/**- * 解析后端「发布时长策略拦下」的载荷;识别不出来返回 null,退回普通失败展示。- *- * 解析失败绝不能假装可授权——那会把一条读不出来的 JSON 变成用户勾选的豁免。- */-function parsePolicyBlocked(error: string): PolicyBlockedVersion[] | null {- if (!error.startsWith(POLICY_BLOCKED_PREFIX))- return null- try {- const parsed = JSON.parse(error.slice(POLICY_BLOCKED_PREFIX.length)) as PolicyBlockedVersion[]- return parsed.length > 0 ? parsed : null- }- catch (err) {- console.error('[ConfigPlugin] failed to parse policy-blocked payload:', err)- return null- }-}-/*** 操作 chip 的样式变体:busy 时禁止点击并降低透明度,否则可点击。* 统一各操作 chip 的 busy 样式,避免内联三元重复。@@ -118,53 +89,51 @@ export function ConfigPlugin() {const [dialogHolder, openDialog] = useOverlay(Modal, { type: 'holder' })/**- * 记录发布时长策略豁免:pnpm 的 `minimumReleaseAge`(11 默认 24 小时)不放行档案里- * 已声明的太新版本,于是**每次**插件操作都硬失败(见后端 `PLUGIN_POLICY_BLOCKED`)。- * 用户确认接受这些精确版本后写进档案的 `minimumReleaseAgeExclude`,再重跑原操作。+ * 记录被拦下版本的精确授权:核心版本兼容性走 `allow_plugin_versions`(写档案的+ * `compatibility.json`),发布时长策略走 `allow_plugin_policy_versions`(写+ * `minimumReleaseAgeExclude`)。两套授权互不相干,但都只认精确版本、都由用户在这里确认。*/- const allowPolicy = useMutation({- mutationFn: (versions: PolicyBlockedVersion[]) => invoke<void>('allow_plugin_policy_versions', { versions }),+ const allowBlocked = useMutation({+ mutationFn: (refusal: BlockedRefusal) => invoke<void>(+ refusal.kind === 'incompatible' ? 'allow_plugin_versions' : 'allow_plugin_policy_versions',+ { versions: refusal.versions },+ ),onError: (err) => {- console.error('[ConfigPlugin] allow_plugin_policy_versions failed:', err)- toast(t('plugins.policy_allow_failed'), {})+ console.error('[ConfigPlugin] authorising blocked versions failed:', err)+ toast(t('plugins.authorize_failed'), {})},})/**- * 被发布时长策略拦住时的出路:先让用户看清单并明确确认(与版本兼容性豁免一样,- * 不放宽默认策略、不替用户决定),确认后写入精确豁免并重跑原操作。+ * 插件操作被拦下时的出路:标题 + 说明 + 被拦下的精确版本,动作按钮「授权」点一次补齐+ * 所需豁免并重跑原操作(不想要就关掉气泡,不另设取消按钮)。+ *+ * 常驻(`timeout: 0`):这是需要用户决定的岔口,超时消失等于把人晾在原地。授权后重跑+ * 原操作——豁免写进档案后仍要由 pnpm 真正改一遍依赖,不能假定写入即生效。*/- async function onPolicyBlocked(blocked: PolicyBlockedVersion[], retry: () => Promise<void>) {- try {- await openDialog({- status: 'warning',- title: t('plugins.policy_blocked_title'),- description: (- <div className="flex flex-col gap-2">- <p>{t('plugins.policy_blocked_desc')}</p>- <ul className="flex flex-col gap-1">- {blocked.map(item => (- <li key={`${item.name}@${item.version}`} className="font-mono text-[11px] text-ink">- {item.name}- @- {item.version}- </li>- ))}- </ul>- </div>- ),- confirmText: t('plugins.policy_blocked_confirm'),- })- }- catch (e) {- silence(e, 'plugin policy blocked: dialog cancelled')- return- }+ function onBlocked(refusal: BlockedRefusal, name: string, retry: () => Promise<void>) {+ const core = refusal.kind === 'incompatible'+ const blocked = refusal.versions.map(item => `${item.name}@${item.version}`).join('、')+ const key = toast(t(core ? 'plugins.blocked_incompatible_title' : 'plugins.blocked_policy_title', { name }), {+ variant: core ? 'danger' : 'warning',+ timeout: 0,+ description: t(core ? 'plugins.blocked_incompatible_desc' : 'plugins.blocked_policy_desc', { blocked }),+ actionProps: {+ children: t('buttons.authorize'),+ onPress: () => {+ toast.close(key)+ void authorise(refusal, retry)+ },+ },+ })+ }++ async function authorise(refusal: BlockedRefusal, retry: () => Promise<void>) {try {- await allowPolicy.mutateAsync(blocked)+ await allowBlocked.mutateAsync(refusal)}catch (e) {- silence(e, 'plugin policy blocked: error already shown by mutation onError')+ silence(e, 'plugin blocked: error already shown by mutation onError')return}await retry()@@ -185,11 +154,11 @@ export function ConfigPlugin() {onError: (err, id) => {const name = plugins.find(p => p.id === id)?.name ?? idconsole.error('[ConfigPlugin] upgrade failed:', err)- // 被发布时长策略拦住不是「升级失败」:档案已声明太新的版本,pnpm 不放行,重跑- // 多少次都一样。给出可操作的出路(授权精确版本后重试),而不是一句失败。- const blocked = parsePolicyBlocked(String(err))- if (blocked) {- void onPolicyBlocked(blocked, () => onUpgrade(id))+ // 被拦下不是「升级失败」:要么是核心不兼容、要么是发布保护期,重跑多少次都一样。+ // 给出可操作的出路(授权精确版本后重试),而不是一句没有出路的失败。+ const refusal = parseBlockedRefusal(String(err))+ if (refusal) {+ onBlocked(refusal, name, () => onUpgrade(id))return}toast(t('plugins.upgrade_failed', { name }), {})@@ -206,11 +175,11 @@ export function ConfigPlugin() {onError: (err, id) => {const name = plugins.find(p => p.id === id)?.name ?? idconsole.error('[ConfigPlugin] remove failed:', err)- // 卸载同样会重写 lockfile 并复核整份档案,因此同样可能被发布时长策略拦住- // (档案里另有太新版本时):一样给出授权后重跑的出路,而不是一句失败。- const blocked = parsePolicyBlocked(String(err))- if (blocked) {- void onPolicyBlocked(blocked, () => runRemove(id))+ // 卸载同样要重写 lockfile 并复核整份档案,因此同样可能被核心不兼容或发布保护期+ // 拦下:一样给出授权后重跑的出路,而不是一句失败。+ const refusal = parseBlockedRefusal(String(err))+ if (refusal) {+ onBlocked(refusal, name, () => runRemove(id))return}toast(t('plugins.remove_failed', { name }), {})@@ -288,15 +257,15 @@ export function ConfigPlugin() {setBusy({ id, action: 'update' })try {await upgrade.mutateAsync(id)+ // 只有升级成功才拉起服务:失败时档案/依赖仍是待处理状态(不兼容、发布保护期、+ // 网络…),此时重启只会再失败一次(重启 > 报错),把真正的失败原因淹没掉。+ void store.harness.restart()}catch (e) {silence(e, 'plugin upgrade: error already shown by mutation onError')}finally {setBusy(null)- // 插件操作会停掉运行中的服务(即使失败也已被后端停止),这里统一拉起服务并- // 同步前端运行状态,避免留下「服务已死但界面仍显示运行中」的过期状态。- void store.harness.restart()}}@@ -329,14 +298,14 @@ export function ConfigPlugin() {setBusy({ id, action: 'remove' })try {await remove.mutateAsync(id)+ // 同升级:只有成功才拉起服务(失败时档案仍是待处理状态,重启只会报错一次)+ void store.harness.restart()}catch (e) {silence(e, 'plugin remove: error already shown by mutation onError')}finally {setBusy(null)- // 同上:卸载后统一拉起服务,避免服务被后端停止后前端状态过期。- void store.harness.restart()}}@@ -347,14 +316,14 @@ export function ConfigPlugin() {setBusy({ id, action: 'disable' })try {await disable.mutateAsync(id)+ // 只有成功才拉起服务,使新的 bundles 列表生效(失败时什么都没变,重启没有意义)+ void store.harness.restart()}catch (e) {silence(e, 'plugin disable: error already shown by mutation onError')}finally {setBusy(null)- // 禁用后统一拉起服务,使新的 bundles 列表生效。- void store.harness.restart()}}@@ -385,14 +354,14 @@ export function ConfigPlugin() {setBusy({ id, action: 'enable' })try {await enable.mutateAsync({ id, clearConfigOverride })+ // 同禁用:只有成功才拉起服务,使新的 bundles 列表生效+ void store.harness.restart()}catch (e) {silence(e, 'plugin enable: error already shown by mutation onError')}finally {setBusy(null)- // 启用后统一拉起服务,使新的 bundles 列表生效。- void store.harness.restart()}}