Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(settings): 保留权限设置保存失败提示 (#1222)

Hairybd54b67fc68c
diff --git a/.gitattributes b/.gitattributes
index 73763bec..d79cad1a 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -12,6 +12,7 @@
*.mjs text eol=lf
test/fixtures/chat-follow-anchor.txt text eol=lf
test/fixtures/scroll-follow-alpha5.txt text eol=lf
+test/fixtures/permission-settings-rc2.txt text eol=lf
*.sh text eol=lf
*.ico binary
*.icns binary
diff --git a/src-tauri/src/service/patch/mod.rs b/src-tauri/src/service/patch/mod.rs
index c1d16669..88b9a5ec 100644
--- a/src-tauri/src/service/patch/mod.rs
+++ b/src-tauri/src/service/patch/mod.rs
@@ -17,6 +17,7 @@ pub(crate) mod mcp_startup;
pub(crate) mod mobile_composer;
pub(crate) mod mobile_sidebar;
pub(crate) mod model_selection;
+pub(crate) mod permission_settings;
pub(crate) mod pi_ai_thinking;
pub(crate) mod plugin_visibility;
pub(crate) mod renderer;
@@ -37,11 +38,12 @@ use std::path::Path;
/// 让编排层能看见哪一条出了问题。
pub(crate) fn apply_all_at(core_dir: &Path) -> Result<(), String> {
#[allow(clippy::type_complexity)]
- let patches: [(&str, fn(&Path) -> Result<(), String>); 15] = [
+ let patches: [(&str, fn(&Path) -> Result<(), String>); 16] = [
("renderer", renderer::apply_at),
("mcp_startup", mcp_startup::apply_at),
("composer", composer::apply_at),
("conversation_draft", conversation_draft::apply_at),
+ ("permission_settings", permission_settings::apply_at),
("scroll_follow", scroll_follow::apply_at),
("chat_follow_anchor", chat_follow_anchor::apply_at),
("mobile_composer", mobile_composer::apply_at),
diff --git a/src-tauri/src/service/patch/permission_settings.rs b/src-tauri/src/service/patch/permission_settings.rs
new file mode 100644
index 00000000..ba347dd2
--- /dev/null
+++ b/src-tauri/src/service/patch/permission_settings.rs
@@ -0,0 +1,128 @@
+use std::path::Path;
+
+use crate::utils::{patch_core_file, patch_dsh, PatchOutcome};
+
+const PERMISSION_CLIENT_JS: &str =
+ "node_modules/@deepseek-ai/dsh-client-ui-permission-presets/lib/client.js";
+const SAVE_ERROR_ORIGINAL: &str = r#"saving = false;
+ disposed = false;"#;
+const SAVE_ERROR_PATCHED: &str = r#"saving = false;
+ saveError = null;
+ disposed = false;"#;
+const RESPONSE_ORIGINAL: &str = r#"if (!response.ok) {
+ this.fail(response.error);
+ return;
+ }
+ this.describeFace.acceptView(response.value);"#;
+const RESPONSE_PATCHED: &str = r#"if (!response.ok) {
+ this.saveError = response.error instanceof Error ? response.error.message : String(response.error);
+ this.fail(this.saveError);
+ return;
+ }
+ this.saveError = null;
+ this.describeFace.acceptView(response.value);"#;
+const DERIVE_ORIGINAL: &str = r#"state.status = "ready";
+ state.error = null;
+ state.writable = writable;
+ state.currentValue = resolved.currentValue;"#;
+const DERIVE_V1: &str = r#"state.status = state.error === null ? "ready" : "error";
+ state.writable = writable;
+ state.currentValue = resolved.currentValue;"#;
+const DERIVE_PATCHED: &str = r#"state.status = this.saveError === null ? "ready" : "error";
+ state.error = this.saveError;
+ state.writable = writable;
+ state.currentValue = resolved.currentValue;"#;
+
+fn patch_source(source: &str) -> PatchOutcome {
+ let replacements = [
+ (SAVE_ERROR_ORIGINAL, SAVE_ERROR_PATCHED),
+ (RESPONSE_ORIGINAL, RESPONSE_PATCHED),
+ (DERIVE_ORIGINAL, DERIVE_PATCHED),
+ ];
+ if replacements.iter().all(|(original, patched)| {
+ source.matches(patched).count() == 1 && !source.contains(original)
+ }) && !source.contains(DERIVE_V1)
+ {
+ return PatchOutcome::AlreadyPatched;
+ }
+ if source.matches(DERIVE_V1).count() > 1
+ || (source.contains(DERIVE_V1) && source.contains(DERIVE_ORIGINAL))
+ || replacements
+ .iter()
+ .any(|(_, patched)| source.contains(patched))
+ {
+ return PatchOutcome::AnchorMissing;
+ }
+ let source = source.replacen(DERIVE_V1, DERIVE_ORIGINAL, 1);
+ if replacements
+ .iter()
+ .any(|(original, _)| source.matches(original).count() != 1)
+ {
+ return PatchOutcome::AnchorMissing;
+ }
+ let patched = replacements
+ .iter()
+ .fold(source, |source, (original, patched)| {
+ source.replacen(original, patched, 1)
+ });
+ PatchOutcome::Patched(patched)
+}
+
+pub fn apply_at(core_dir: &Path) -> Result<(), String> {
+ patch_core_file(core_dir, PERMISSION_CLIENT_JS, patch_source)
+}
+
+pub fn apply(app_handle: &tauri::AppHandle) -> Result<(), String> {
+ patch_dsh(app_handle, PERMISSION_CLIENT_JS, patch_source)
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ const LEGACY_CONTROLLER: &str =
+ include_str!("../../../../test/fixtures/permission-settings-rc2.txt");
+
+ #[test]
+ fn patches_real_controller_and_upgrades_v1_once() {
+ for source in [
+ LEGACY_CONTROLLER.to_owned(),
+ LEGACY_CONTROLLER.replacen(DERIVE_ORIGINAL, DERIVE_V1, 1),
+ ] {
+ let PatchOutcome::Patched(patched) = patch_source(&source) else {
+ panic!("expected Patched");
+ };
+ assert!(patched.contains(DERIVE_PATCHED));
+ assert!(patched.contains(SAVE_ERROR_PATCHED));
+ assert!(patched.contains(RESPONSE_PATCHED));
+ assert_eq!(patch_source(&patched), PatchOutcome::AlreadyPatched);
+ }
+ }
+
+ #[test]
+ fn leaves_changed_or_ambiguous_anchors_unchanged() {
+ assert_eq!(patch_source(""), PatchOutcome::AnchorMissing);
+ for anchor in [SAVE_ERROR_ORIGINAL, RESPONSE_ORIGINAL, DERIVE_ORIGINAL] {
+ assert_eq!(
+ patch_source(&LEGACY_CONTROLLER.replacen(anchor, "", 1)),
+ PatchOutcome::AnchorMissing
+ );
+ assert_eq!(
+ patch_source(&LEGACY_CONTROLLER.replacen(anchor, &anchor.repeat(2), 1)),
+ PatchOutcome::AnchorMissing
+ );
+ }
+ assert_eq!(
+ patch_source(&LEGACY_CONTROLLER.replacen(DERIVE_ORIGINAL, &DERIVE_V1.repeat(2), 1)),
+ PatchOutcome::AnchorMissing
+ );
+ assert_eq!(
+ patch_source(&format!("{LEGACY_CONTROLLER}{DERIVE_V1}")),
+ PatchOutcome::AnchorMissing
+ );
+ assert_eq!(
+ patch_source(&LEGACY_CONTROLLER.replacen(DERIVE_ORIGINAL, DERIVE_PATCHED, 1)),
+ PatchOutcome::AnchorMissing
+ );
+ }
+}
diff --git a/src-tauri/src/service/workflow/launch.rs b/src-tauri/src/service/workflow/launch.rs
index a3f8e2e8..6d81d24e 100644
--- a/src-tauri/src/service/workflow/launch.rs
+++ b/src-tauri/src/service/workflow/launch.rs
@@ -709,6 +709,9 @@ pub async fn launch(app_handle: tauri::AppHandle) -> Result<(), String> {
if let Err(e) = crate::service::patch::conversation_draft::apply(&app_handle) {
log::warn!("conversation draft compatibility patch failed: {e}");
}
+ if let Err(e) = crate::service::patch::permission_settings::apply(&app_handle) {
+ log::warn!("permission settings error patch failed: {e}");
+ }
if let Err(e) = crate::service::patch::scroll_follow::apply(&app_handle) {
log::warn!("Scroll follow reduced-motion patch skipped: {e}");
}
diff --git a/test/fixtures/THIRD_PARTY_NOTICES.md b/test/fixtures/THIRD_PARTY_NOTICES.md
index 4ceded33..8a2a8029 100644
--- a/test/fixtures/THIRD_PARTY_NOTICES.md
+++ b/test/fixtures/THIRD_PARTY_NOTICES.md
@@ -2,6 +2,10 @@
[`scroll-follow-alpha5.txt`](<./scroll-follow-alpha5.txt>) is the `ScrollFollow` class extracted from `@deepseek-ai/[email protected]`, `lib/client.js`, with comments and blank lines removed. Source: [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness/blob/dsh-v0.2.1-alpha.5/packages/client/ui-chat/src/client/chat/use-scroll-follow.ts). This fixture does not change the read-only reference submodule.
+## Permission settings fixture
+
+[`permission-settings-rc2.txt`](<./permission-settings-rc2.txt>) contains `permissionDefaultOf` and `PermissionPresetSettingsController` extracted from `@deepseek-ai/[email protected]`, `lib/client.js`, with comments and blank lines removed and outer indentation normalized. Source: [npm package](https://www.npmjs.com/package/@deepseek-ai/dsh-client-ui-permission-presets/v/0.2.0-rc.2).
+
## MIT License
Copyright (c) 2026 DeepSeek
diff --git a/test/fixtures/permission-settings-rc2.txt b/test/fixtures/permission-settings-rc2.txt
new file mode 100644
index 00000000..55353e98
--- /dev/null
+++ b/test/fixtures/permission-settings-rc2.txt
@@ -0,0 +1,138 @@
+const PERMISSION_SETTINGS_NS = "permission";
+function permissionDefaultOf(view, catalog) {
+ const currentValue = view.value.defaultPreset ?? catalog.defaultPreset;
+ const options = catalog.defaultOptions.map((option) => ({
+ id: option.value,
+ label: displayPermissionPreset(option.value, option.name)
+ }));
+ if (!options.some((option) => option.id === currentValue)) throw new Error("permission catalog does not advertise its current default");
+ return {
+ currentValue,
+ options
+ };
+}
+var PermissionPresetSettingsController = class {
+ describeFace;
+ ctx;
+ catalog;
+ store = (0, _deepseek_ai_dsh_client_store.createSnapshotStore)({
+ status: "idle",
+ error: null,
+ writable: false,
+ currentValue: "",
+ options: [],
+ revision: 0
+ });
+ following;
+ followingCatalog;
+ saving = false;
+ disposed = false;
+ constructor(describeFace, ctx, catalog) {
+ this.describeFace = describeFace;
+ this.ctx = ctx;
+ this.catalog = catalog;
+ }
+ async load() {
+ if (this.disposed) return;
+ this.following ??= this.describeFace.subscribe(() => {
+ this.derive();
+ });
+ this.followingCatalog ??= this.catalog.store.subscribe(() => {
+ this.derive();
+ });
+ this.store.update((state) => {
+ state.status = "loading";
+ state.error = null;
+ });
+ await this.describeFace.ensure();
+ if (this.describeFace.getSnapshot().status !== "unavailable") try {
+ await this.catalog.load();
+ } catch (error) {
+ this.fail(error);
+ return;
+ }
+ this.derive();
+ }
+ async select(preset) {
+ const state = this.store.getSnapshot();
+ const view = this.describeFace.getSnapshot().view?.namespaces.find((entry) => entry.ns === PERMISSION_SETTINGS_NS);
+ if (view === void 0 || !state.writable || this.saving) return;
+ this.saving = true;
+ this.store.update((draft) => {
+ draft.status = "saving";
+ draft.error = null;
+ });
+ let response;
+ try {
+ response = await this.ctx.remote.settings.mutate(PERMISSION_SETTINGS_NS, [{
+ op: "set",
+ path: ["defaultPreset"],
+ value: preset
+ }], view.revision);
+ } finally {
+ this.saving = false;
+ }
+ if (this.disposed) return;
+ if (!response.ok) {
+ this.fail(response.error);
+ return;
+ }
+ this.describeFace.acceptView(response.value);
+ }
+ dispose() {
+ this.disposed = true;
+ this.following?.();
+ this.following = void 0;
+ this.followingCatalog?.();
+ this.followingCatalog = void 0;
+ }
+ derive() {
+ if (this.disposed || this.saving) return;
+ const mirrored = this.describeFace.getSnapshot();
+ if (mirrored.status === "unavailable") {
+ this.store.update((state) => {
+ state.status = "unavailable";
+ state.writable = false;
+ state.currentValue = "";
+ state.options = [];
+ });
+ return;
+ }
+ if (mirrored.view === void 0) {
+ if (mirrored.error !== null) this.fail(new Error(mirrored.error));
+ return;
+ }
+ const view = mirrored.view.namespaces.find((entry) => entry.ns === PERMISSION_SETTINGS_NS);
+ if (view === void 0) {
+ this.store.update((state) => {
+ state.status = "unavailable";
+ state.writable = false;
+ state.currentValue = "";
+ state.options = [];
+ });
+ return;
+ }
+ try {
+ const catalog = this.catalog.store.getSnapshot().value;
+ if (catalog === null) return;
+ const resolved = permissionDefaultOf(view, catalog);
+ const { writable } = mirrored.view;
+ this.store.update((state) => {
+ state.status = "ready";
+ state.error = null;
+ state.writable = writable;
+ state.currentValue = resolved.currentValue;
+ state.options = resolved.options;
+ state.revision = view.revision;
+ });
+ } catch (error) {
+ this.fail(error);
+ }
+ }
+ fail(error) {
+ this.store.update((state) => {
+ state.status = "error";
+ state.error = error instanceof Error ? error.message : String(error);
+ });
+ }
+ };
diff --git a/test/permission-settings-patch.test.ts b/test/permission-settings-patch.test.ts
new file mode 100644
index 00000000..41b08bd5
--- /dev/null
+++ b/test/permission-settings-patch.test.ts
@@ -0,0 +1,151 @@
+import { readFileSync } from 'node:fs'
+import { runInNewContext } from 'node:vm'
+import { createSnapshotStore } from '@deepseek-ai/dsh-client-store'
+import { describe, expect, it, vi } from 'vitest'
+
+const fixture = readFileSync(new URL('./fixtures/permission-settings-rc2.txt', import.meta.url), 'utf8')
+const patch = readFileSync(new URL('../src-tauri/src/service/patch/permission_settings.rs', import.meta.url), 'utf8')
+const replacements = ['SAVE_ERROR', 'RESPONSE', 'DERIVE'].map((name) => {
+ const original = patch.match(new RegExp(`const ${name}_ORIGINAL: &str = r#"([\\s\\S]*?)"#;`))![1]!
+ const replacement = patch.match(new RegExp(`const ${name}_PATCHED: &str = r#"([\\s\\S]*?)"#;`))![1]!
+ return [original, replacement] as const
+})
+const patchedFixture = replacements.reduce((source, [original, replacement]) => source.replace(original, replacement), fixture)
+
+function harness(patched = true) {
+ const view = (revision: number, defaultPreset = 'workspace-write') => ({
+ writable: true,
+ namespaces: [{ ns: 'permission', revision, value: { defaultPreset } }],
+ })
+ const mirror = createSnapshotStore<{ status: string, error: string | null, view: ReturnType<typeof view> | undefined }>({
+ status: 'ready',
+ error: null,
+ view: view(4),
+ })
+ const describeFace = {
+ ...mirror,
+ ensure: async () => {},
+ acceptView: (value: ReturnType<typeof view>) => mirror.update((draft) => { draft.view = value }),
+ }
+ const catalog = {
+ store: createSnapshotStore({
+ value: {
+ defaultPreset: 'workspace-write',
+ defaultOptions: ['workspace-write', 'danger-full-access'].map(value => ({ value, name: value })),
+ },
+ }),
+ load: vi.fn().mockResolvedValue(undefined),
+ }
+ const mutate = vi.fn().mockResolvedValue({ ok: false, error: 'configuration changed (expected 4, actual 6)' })
+ const Controller = runInNewContext(`${patched ? patchedFixture : fixture}\nPermissionPresetSettingsController`, {
+ _deepseek_ai_dsh_client_store: { createSnapshotStore },
+ displayPermissionPreset: (value: string) => value,
+ Error,
+ }) as new (describeFace: unknown, ctx: unknown, catalog: unknown) => {
+ store: { getSnapshot: () => { status: string, error: string | null, currentValue: string, revision: number, writable: boolean } }
+ load: () => Promise<void>
+ select: (preset: string) => Promise<void>
+ dispose: () => void
+ }
+ const controller = new Controller(describeFace, { remote: { settings: { mutate } } }, catalog)
+ return { controller, describeFace, catalog, mutate, view }
+}
+
+describe('permission settings error patch', () => {
+ it('reproduces upstream clearing a failed save on mirror refresh', async () => {
+ const { controller, describeFace, view } = harness(false)
+ await controller.load()
+ await controller.select('danger-full-access')
+ expect(controller.store.getSnapshot().status).toBe('error')
+ describeFace.acceptView(view(6))
+ expect(controller.store.getSnapshot()).toMatchObject({ status: 'ready', error: null })
+ controller.dispose()
+ })
+
+ it('clears catalog derivation errors after its choices recover', async () => {
+ const { controller, catalog } = harness()
+ await controller.load()
+ catalog.store.update((draft) => {
+ draft.value.defaultOptions = draft.value.defaultOptions.filter(option => option.value !== 'workspace-write')
+ })
+ expect(controller.store.getSnapshot()).toMatchObject({
+ status: 'error',
+ error: 'permission catalog does not advertise its current default',
+ })
+ catalog.store.update((draft) => {
+ draft.value.defaultOptions.push({ value: 'workspace-write', name: 'Workspace' })
+ })
+ expect(controller.store.getSnapshot()).toMatchObject({ status: 'ready', error: null })
+ controller.dispose()
+ })
+
+ it('clears a catalog load error after a catalog refresh succeeds', async () => {
+ const { controller, catalog } = harness()
+ catalog.load.mockRejectedValueOnce(new Error('catalog offline'))
+ await controller.load()
+ expect(controller.store.getSnapshot()).toMatchObject({ status: 'error', error: 'catalog offline' })
+ catalog.store.update((draft) => {
+ draft.value.defaultOptions[0]!.name = 'Workspace'
+ })
+ expect(controller.store.getSnapshot()).toMatchObject({ status: 'ready', error: null })
+ controller.dispose()
+ })
+
+ it('clears an absent mirror error when a view becomes available', async () => {
+ const { controller, describeFace, view } = harness()
+ await controller.load()
+ describeFace.update((draft) => {
+ draft.view = undefined
+ draft.error = 'mirror offline'
+ })
+ expect(controller.store.getSnapshot()).toMatchObject({ status: 'error', error: 'mirror offline' })
+ describeFace.acceptView(view(6))
+ expect(controller.store.getSnapshot()).toMatchObject({ status: 'ready', error: null, revision: 6 })
+ controller.dispose()
+ })
+
+ it('keeps failure visible across mirror and catalog refresh, then accepts a successful save', async () => {
+ const { controller, describeFace, catalog, mutate, view } = harness()
+ await controller.load()
+ await controller.select('danger-full-access')
+ expect(mutate).toHaveBeenLastCalledWith('permission', [{
+ op: 'set',
+ path: ['defaultPreset'],
+ value: 'danger-full-access',
+ }], 4)
+ describeFace.update((draft) => {
+ draft.view = undefined
+ draft.error = 'mirror offline'
+ })
+ expect(controller.store.getSnapshot().error).toBe('mirror offline')
+ describeFace.acceptView(view(6))
+ catalog.store.update((draft) => {
+ draft.value.defaultOptions = draft.value.defaultOptions.filter(option => option.value !== 'workspace-write')
+ })
+ expect(controller.store.getSnapshot().error).toBe('permission catalog does not advertise its current default')
+ catalog.store.update((draft) => {
+ draft.value.defaultOptions.push({ value: 'workspace-write', name: 'Workspace' })
+ })
+ catalog.store.update((draft) => {
+ draft.value.defaultOptions[0]!.name = 'Workspace'
+ })
+ expect(controller.store.getSnapshot()).toMatchObject({
+ status: 'error',
+ error: 'configuration changed (expected 4, actual 6)',
+ currentValue: 'workspace-write',
+ revision: 6,
+ writable: true,
+ })
+
+ mutate.mockResolvedValueOnce({ ok: true, value: view(7, 'danger-full-access') })
+ await controller.select('danger-full-access')
+ expect(mutate.mock.lastCall?.[2]).toBe(6)
+ expect(controller.store.getSnapshot()).toMatchObject({
+ status: 'ready',
+ error: null,
+ currentValue: 'danger-full-access',
+ revision: 7,
+ })
+ controller.dispose()
+ })
+})