DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(plugin): 「升级以 0 退出但版本没动」也能授权解开
hairyf181abec1ec8d
diff --git a/src-tauri/src/service/plugin/install/single.rs b/src-tauri/src/service/plugin/install/single.rsindex f9a3474b..ae61fdcc 100644--- a/src-tauri/src/service/plugin/install/single.rs+++ b/src-tauri/src/service/plugin/install/single.rs@@ -33,6 +33,8 @@ use super::run_plugin_with_allow_build_retry;use super::uninstall_recovery;use super::PreinstallPluginInfo;use super::{PreinstallLogPayload, PREINSTALL_LOG_EVENT};+use crate::service::plugin::update::known_latest;+use crate::service::profile::profile_release_age_excluded;pub async fn update(app_handle: &AppHandle, id: &str) -> Result<(), String> {run_single_plugin_command(app_handle, id, "update", &update_pnpm_args(id)).await@@ -435,9 +437,30 @@ async fn run_single_plugin_command(if dependency_fingerprint(&profile_dir(app_handle), id).as_deref() == Some(before) {let detail = installed_package_version(&profile_dir(app_handle), id).unwrap_or_else(|| before.to_string());- log::warn!("dsh plugin update made no change for {id}, still at {detail}");+ // 只有「新版本太新」这一种成因有出路(授权那个精确版本即可过闸),因此把+ // 目标版本与「是否已在豁免清单里」一并带出去:已经授权过还是不动,说明成因+ // 是档案把来源钉死,界面就别再给按钮——否则用户只会反复点一个没用的动作。+ // 目标版本取自更新探测缓存(不新发网络请求);git 托管插件的「最新」是提交+ // SHA、不是 registry 版本,不能进发布时长豁免清单,按形状挡掉。+ let latest = known_latest(id).filter(|latest| {+ latest != &detail+ && latest.contains('.')+ && latest.starts_with(|c: char| c.is_ascii_digit())+ });+ let retryable = latest.as_deref().is_some_and(|latest| {+ !profile_release_age_excluded(app_handle, &format!("{id}@{latest}"))+ });+ log::warn!(+ "dsh plugin update made no change for {id}, still at {detail}, newest {latest:?}, actionable {retryable}"+ );return Err(format!(- "PLUGIN_UPDATE_NO_CHANGE: pnpm exited successfully but {id} is still at {detail}; no newer version was installed — either the profile pins this dependency (a `catalog:` entry in pnpm-workspace.yaml, a git spec, or a `link:` directory), or the newest release is still inside pnpm's `minimumReleaseAge` window (releases younger than the configured age are not resolved; bundled pnpm defaults to 24 hours), so the upgrade did not take effect"+ "PLUGIN_UPDATE_NO_CHANGE: {}",+ serde_json::json!({+ "name": id,+ "version": detail,+ "latest": latest,+ "retryable": retryable,+ })));}}diff --git a/src-tauri/src/service/plugin/update.rs b/src-tauri/src/service/plugin/update.rsindex c6fc6bfa..03cebaa6 100644--- a/src-tauri/src/service/plugin/update.rs+++ b/src-tauri/src/service/plugin/update.rs@@ -65,6 +65,21 @@ fn cache_key(id: &str, spec: &str, version: &str, locked: &HashMap<String, Strinformat!("{id}\u{0}{spec}\u{0}{version}\u{0}{locked_commit}")}+/// 探测缓存里该插件的「最新版本」;没探测过或缓存里没有它时返回 `None`。+///+/// 升级「以 0 退出但版本没动」时需要知道本该装到哪个版本:发布时长豁免是按精确+/// `包名@版本` 写的,没有目标版本就给不出可授权的条目。这里只读缓存、不新发请求+/// (探测由 [`refresh`] 统一负责),缓存键以 `id` 开头(见 [`cache_key`])。+pub(crate) fn known_latest(id: &str) -> Option<String> {+ let cache = cache().lock().unwrap();+ let prefix = format!("{id}\u{0}");+ cache+ .iter()+ .filter(|(key, _)| key.starts_with(&prefix))+ .max_by_key(|(_, entry)| entry.at)+ .and_then(|(_, entry)| entry.info.latest.clone())+}+// ---------------------------------------------------------------------------// 读取安装态(spec / 版本 / 锁定提交)// ---------------------------------------------------------------------------diff --git a/src-tauri/src/service/profile/mod.rs b/src-tauri/src/service/profile/mod.rsindex 32195bd9..472d5f52 100644--- a/src-tauri/src/service/profile/mod.rs+++ b/src-tauri/src/service/profile/mod.rs@@ -160,6 +160,30 @@ pub(crate) fn ensure_profile_pnpm_policy(app_handle: &AppHandle) -> Result<(), Sprofile_release_age_excludes(app_handle, &entries)}+/// 档案的 `minimumReleaseAgeExclude` 里是否已经有这个精确 `包名@版本`。+///+/// 用来区分「升级没落地」的两种成因:已经授权过这个版本还是不动,说明瓶颈不是发布时长+/// 策略(而是档案把来源钉死),界面就不该再提供「授权」这个没用的动作。档案缺失或读不出+/// 来时返回 false(宁可多给一次授权机会,也不替用户判定成钉死)。+pub(crate) fn profile_release_age_excluded(app_handle: &AppHandle, entry: &str) -> bool {+ let path = profile_dir_of(app_handle, &active_profile(app_handle)).join("pnpm-workspace.yaml");+ let Ok(content) = fs::read_to_string(&path) else {+ return false;+ };+ let Ok((document, _)) = parse_workspace_document(&content) else {+ return false;+ };+ let Some(sequence) = document+ .as_mapping()+ .and_then(|mapping| mapping.get(Value::String("minimumReleaseAgeExclude".to_string())))+ .and_then(|value| value.as_sequence())+ else {+ return false;+ };+ let wanted = Value::String(entry.to_string());+ sequence.iter().any(|item| item == &wanted)+}+/// 把用户明确授权过的精确 `包名@版本` 追加进档案的 `minimumReleaseAgeExclude`。////// pnpm 的发布时长策略(`minimumReleaseAge`,11 默认 24 小时)在解析与 lockfile 校验diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.jsonindex 4dc6d401..28594a68 100644--- a/src/i18n/locales/en-US.json+++ b/src/i18n/locales/en-US.json@@ -269,6 +269,9 @@"plugins.blocked_incompatible_desc": "Rejected version: {{blocked}} (running it may crash or lose data). Authorising records the exemption and retries.","plugins.blocked_policy_title": "{{name}}'s update is blocked by the release-age window","plugins.blocked_policy_desc": "Blocked version: {{blocked}} (published under 24 hours ago, so pnpm skips it). Authorising records the exemption and retries.",+ "plugins.hold_title": "{{name}} was not upgraded",+ "plugins.hold_desc": "{{blocked}} is still inside the release-age window (pnpm skips it). Authorising records the exemption and retries.",+ "plugins.hold_pinned_desc": "No new version to authorise: the profile pins the source (a catalog/git/link or exact spec), so `--latest` cannot move past it. The plugin itself is fine.","plugins.authorize_failed": "Authorisation failed","plugins.updated_toast": "Plugin {{name}} updated","plugins.removed_toast": "Plugin {{name}} uninstalled",diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.jsonindex 4a1ccded..5bfb00a2 100644--- a/src/i18n/locales/zh-CN.json+++ b/src/i18n/locales/zh-CN.json@@ -269,6 +269,9 @@"plugins.blocked_incompatible_desc": "被拒绝的版本:{{blocked}}(运行可能崩溃或丢数据)。授权后写入豁免并重试。","plugins.blocked_policy_title": "{{name}} 的更新被发布保护期拦下","plugins.blocked_policy_desc": "被挡住的版本:{{blocked}}(发布不足 24 小时,pnpm 默认不解析)。授权后写入豁免并重试。",+ "plugins.hold_title": "{{name}} 的升级没有生效",+ "plugins.hold_desc": "{{blocked}} 还在发布保护期内(pnpm 默认不解析),授权后写入豁免并重试。",+ "plugins.hold_pinned_desc": "没有可授权的新版本:档案把来源钉死了(catalog / git / link 或精确版本),`--latest` 越不过声明范围。插件本身没有损坏。","plugins.authorize_failed": "授权失败","plugins.updated_toast": "插件 {{name}} 已更新","plugins.removed_toast": "插件 {{name}} 已卸载",diff --git a/src/store/modules/preinstall/store.ts b/src/store/modules/preinstall/store.tsindex 0f12802c..3f6b1f0c 100644--- a/src/store/modules/preinstall/store.ts+++ b/src/store/modules/preinstall/store.ts@@ -20,11 +20,13 @@ const LOG_LIMIT = 200*/const INCOMPATIBLE_PREFIX = 'PLUGIN_VERSION_INCOMPATIBLE:'const POLICY_BLOCKED_PREFIX = 'PLUGIN_POLICY_BLOCKED:'+const NO_CHANGE_PREFIX = 'PLUGIN_UPDATE_NO_CHANGE:'-/** 被拦下的清单:核心版本兼容性拒绝,或 pnpm 发布时长策略拒绝。 */+/** 被拦下的清单:核心版本兼容性拒绝、pnpm 发布时长策略拒绝,或「升级没落地」。 */export type BlockedRefusal= | { kind: 'incompatible', versions: IncompatibleVersion[] }| { kind: 'policy', versions: PolicyBlockedVersion[] }+ | { kind: 'update-hold', versions: PolicyBlockedVersion[], retryable: boolean }/*** 解析后端拦截清单的错误载荷;识别不出来返回 null。@@ -39,7 +41,36 @@ export function parseBlockedRefusal(error: string): BlockedRefusal | null {const policy = parseVersions<PolicyBlockedVersion>(error, POLICY_BLOCKED_PREFIX)if (policy)return { kind: 'policy', versions: policy }- return null+ return parseUpdateHold(error)+}++/**+ * 「升级以 0 退出但版本没动」:只有「新版本还在发布保护期内」这一种成因有出路,后端因此+ * 连同目标版本(更新探测缓存里的 registry latest)与 `retryable` 一起给出。已经授权过还+ * 不动时 `retryable` 为 false——那是档案把来源钉死,界面就不要再给按钮。+ */+function parseUpdateHold(error: string): BlockedRefusal | null {+ if (!error.startsWith(NO_CHANGE_PREFIX))+ return null+ try {+ const payload = JSON.parse(error.slice(NO_CHANGE_PREFIX.length)) as {+ name?: unknown+ latest?: unknown+ retryable?: unknown+ }+ if (typeof payload.name !== 'string')+ return null+ const latest = typeof payload.latest === 'string' && payload.latest !== '' ? payload.latest : null+ return {+ kind: 'update-hold',+ versions: latest ? [{ name: payload.name, version: latest }] : [],+ retryable: payload.retryable === true && latest !== null,+ }+ }+ catch (err) {+ console.error(`[Harness] failed to parse ${NO_CHANGE_PREFIX} payload:`, err)+ return null+ }}function parseVersions<T>(error: string, prefix: string): T[] | null {diff --git a/src/ui/config/plugin.tsx b/src/ui/config/plugin.tsxindex 4042e97b..08f44850 100644--- a/src/ui/config/plugin.tsx+++ b/src/ui/config/plugin.tsx@@ -108,28 +108,43 @@ export function ConfigPlugin() {* 插件操作被拦下时的出路:标题 + 说明 + 被拦下的精确版本,动作按钮「授权」点一次补齐* 所需豁免并重跑原操作(不想要就关掉气泡,不另设取消按钮)。*- * 标题是**这次操作的插件名**,清单是**档案里真正挡住它的条目**——两者可以不同:插件- * 操作要过整份 lockfile 校验,档案里任何一个太新的条目都会拦下别人的升级;兼容性拒绝- * 同理扫的是档案里声明的插件。所以文案把角色分开写(标题=操作对象,说明=被挡住的版本),- * 不写成「{{name}} 的版本…」那种看起来自相矛盾的句子。+ * 三种情况共用这条通道:核心版本不兼容、发布保护期挡下、以及「升级以 0 退出但版本没动」+ * (最后一种只是同一种发布保护期的静默形态:`--latest` 盯着最新版本,而最新版本还在窗口+ * 内时 pnpm 直接不动、也不打印原因)。标题是**这次操作的插件**,清单是**档案里真正挡住+ * 它的条目**——两者可以不同:插件操作要过整份 lockfile 校验,档案里任何一条太新的版本+ * 都会拦下别人的升级。** 常驻(`timeout: 0`):这是需要用户决定的岔口,超时消失等于把人晾在原地。授权后重跑* 原操作——豁免写进档案后仍要由 pnpm 真正改一遍依赖,不能假定写入即生效。*/function onBlocked(refusal: BlockedRefusal, name: string, retry: () => Promise<void>) {const core = refusal.kind === 'incompatible'+ const hold = refusal.kind === 'update-hold'+ // 「升级没落地」只有发布保护期这一种成因有出路;后端判定为档案钉死(或没探测到新版+ // 本)时不给按钮,否则用户只会反复点一个没用的动作。+ const actionable = !hold || refusal.retryable+ const titleKey = core+ ? 'plugins.blocked_incompatible_title'+ : hold ? 'plugins.hold_title' : 'plugins.blocked_policy_title'+ const descKey = core+ ? 'plugins.blocked_incompatible_desc'+ : hold+ ? (actionable ? 'plugins.hold_desc' : 'plugins.hold_pinned_desc')+ : 'plugins.blocked_policy_desc'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 }), {+ const key = toast(t(titleKey, { 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)- },- },+ description: t(descKey, { blocked }),+ actionProps: actionable+ ? {+ children: t('buttons.authorize'),+ onPress: () => {+ toast.close(key)+ void authorise(refusal, retry)+ },+ }+ : undefined,})}diff --git a/test/preinstall-incompatible.test.ts b/test/preinstall-incompatible.test.tsindex 609eb782..4b269bf1 100644--- a/test/preinstall-incompatible.test.ts+++ b/test/preinstall-incompatible.test.ts@@ -34,7 +34,7 @@ vi.mock('../src/store/modules/harness-updater', () => ({harnessUpdater: { checkForUpdate: vi.fn() },}))-const { preinstall } = await import('../src/store/modules/preinstall')+const { preinstall, parseBlockedRefusal } = await import('../src/store/modules/preinstall')beforeEach(() => {eventListeners.clear()@@ -180,3 +180,29 @@ describe('preinstall release-age policy refusal', () => {expect(preinstall.policyBlocked).toEqual([])})})++describe('blocked-refusal parsing', () => {+ it('reads a held upgrade as an authorizable target version', () => {+ const refusal = parseBlockedRefusal(`PLUGIN_UPDATE_NO_CHANGE: ${JSON.stringify({ name: 'dshmarket', version: '1.66.2', latest: '1.66.5', retryable: true })}`)++ expect(refusal).toEqual({+ kind: 'update-hold',+ versions: [{ name: 'dshmarket', version: '1.66.5' }],+ retryable: true,+ })+ })++ it('keeps a pinned-or-unknown hold without an authorizable version', () => {+ // 已经授权过还是不动(或没探测到新版本):不能给出可授权项,否则用户只能空点+ const punished = parseBlockedRefusal(`PLUGIN_UPDATE_NO_CHANGE: ${JSON.stringify({ name: 'dshmarket', version: '1.66.2', latest: '1.66.5', retryable: false })}`)+ expect(punished).toEqual({ kind: 'update-hold', versions: [{ name: 'dshmarket', version: '1.66.5' }], retryable: false })++ const unknown = parseBlockedRefusal(`PLUGIN_UPDATE_NO_CHANGE: ${JSON.stringify({ name: 'dshmarket', version: '1.66.2', latest: null, retryable: false })}`)+ expect(unknown).toEqual({ kind: 'update-hold', versions: [], retryable: false })+ })++ it('degrades a malformed hold payload to a plain failure', () => {+ expect(parseBlockedRefusal('PLUGIN_UPDATE_NO_CHANGE: not-json')).toBeNull()+ expect(parseBlockedRefusal(`PLUGIN_UPDATE_NO_CHANGE: ${JSON.stringify({ version: '1.66.2' })}`)).toBeNull()+ })+})