DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(model-config): recover invalid editor preferences
YunYouJun3ce1dccafeaf
diff --git a/packages/dsh-tauri-model-config/README.md b/packages/dsh-tauri-model-config/README.mdindex d42fb2d0..d1ea7f64 100644--- a/packages/dsh-tauri-model-config/README.md+++ b/packages/dsh-tauri-model-config/README.md@@ -21,7 +21,7 @@| 位置 | 能力 || --- | --- |-| 面板标题右侧(`.zGbnIq_title`) | **文本编辑器**:下拉菜单默认跟随系统,可选择 VS Code、Cursor 或自定义编辑器;预设点选即保存,自定义路径确认后保存。**打开配置文件**:使用所选编辑器打开 `$DSH_HOME/settings.yaml`;文件尚未创建时改为打开它所在目录 |+| 面板标题右侧(`.zGbnIq_title`) | **文本编辑器**:下拉菜单默认跟随系统,可选择 VS Code、Cursor 或自定义编辑器;预设点选即保存,自定义路径确认后保存。**打开配置文件**:使用所选编辑器打开 `$DSH_HOME/settings.yaml`(`DSH_HOME` 未设置或为空白时为 `~/.dsh/settings.yaml`);文件尚未创建时改为打开它所在目录 || 单个模型行(`.zGbnIq_modelRow`) | **获取配置**:仅在该条目只有 `id`/`name`/`description` 时出现,按 `id` 从提供方端点读取该模型的上下文与输出上限 || 模型目录标题(`.zGbnIq_modelCatalogHeading`) | 追加 `flex: 1`(按钮集中到右侧),并在右侧加入 **自动配置所有模型**;pi-ai 提供方与官方 DeepSeek 模型目录都有这个入口 || 单个模型高级区(`.zGbnIq_modelAdvanced`) | **图片输入** 开关 → `input` 声明;**思考模式** 开关 → `reasoningEfforts` 声明,打开后可按档位勾选;**关闭 Developer 角色** 开关 → `compat` 声明(仅路由显式声明 `openai-completions` 时出现) |@@ -122,6 +122,7 @@ compat:- 模型配置文件按 `$DSH_HOME`(非空白)→ `~/.dsh` 解析后取 `settings.yaml`,与官方 `resolveDshHome` 及桌面壳一致;如果 profile 的 `cordis.yml` 为 `settings-file` 配了自定义 `path`,这里无法感知。- 编辑器设置仅作用于本插件模型页面的“打开配置文件”;偏好保存于 `$DSH_HOME/dsh-tauri-model-config/editor.json`,不修改系统文件关联。自定义编辑器在 macOS 上支持应用名称、`.app` 路径或可执行文件路径;Windows 使用 `.exe` 完整路径;Linux 支持可执行程序名称或路径。无需引号,不支持附加参数。编辑器启动失败会显示错误,不自动切换应用。+- 编辑器偏好文件内容无效时跟随系统默认,读取时保留原文件,可重新选择编辑器并保存;权限或其他读取错误仍会报错。- 文件不存在时打开的是它所在的目录,而不是替用户创建一个空文档。- 图片能力既不在官方发现通道的返回里,也没有跨厂商的端点字段:它来自模型能力表,表里没有的靠家族规则。两者都是社区口径的近似值,用户随时可以在高级区改;单行「获取配置」也不会覆盖手写值。- 能力表需要一次网络请求(约 2.6 MB 的原始数据集,压成 72 KB 落盘,一天内不再请求)。离线且从未下载过时,只剩家族规则能补图片/思考,容量仍由端点清单提供。diff --git a/packages/dsh-tauri-model-config/src/host/service/config-file.test.ts b/packages/dsh-tauri-model-config/src/host/service/config-file.test.tsindex fd85ee96..ef8917ed 100644--- a/packages/dsh-tauri-model-config/src/host/service/config-file.test.ts+++ b/packages/dsh-tauri-model-config/src/host/service/config-file.test.ts@@ -1,4 +1,4 @@-import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'+import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'import { tmpdir } from 'node:os'import { join } from 'node:path'import { openDirectory } from 'dsh-tauri'@@ -6,6 +6,10 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { configFile } from './config-file'import { openInEditor } from './config-file.utils'+vi.mock('node:fs/promises', async (importOriginal) => {+ const actual = await importOriginal<typeof import('node:fs/promises')>()+ return { ...actual, readFile: vi.fn(actual.readFile) }+})vi.mock('dsh-tauri', async (importOriginal) => {const actual = await importOriginal<typeof import('dsh-tauri')>()return { ...actual, openDirectory: vi.fn() }@@ -34,6 +38,38 @@ describe('config file editor preference', () => {expect(openInEditor).toHaveBeenCalledWith(join(home, 'settings.yaml'), { editor: 'system', command: '' })})+ it.each([+ ['malformed JSON', '{'],+ ['invalid shape', 'null'],+ ['unknown editor', '{"editor":"unknown","command":""}'],+ ['empty custom command', '{"editor":"custom","command":" "}'],+ ])('recovers from %s and allows saving a new preference', async (_, content) => {+ const path = join(home, 'dsh-tauri-model-config', 'editor.json')+ await mkdir(join(home, 'dsh-tauri-model-config'))+ await writeFile(path, content)+ await writeFile(join(home, 'settings.yaml'), 'models: {}\n')++ expect(await configFile.load()).toEqual({ editor: 'system', command: '' })+ expect(await configFile.open()).toEqual({ ok: true, path: join(home, 'settings.yaml'), opened: 'file' })+ expect(openInEditor).toHaveBeenCalledWith(join(home, 'settings.yaml'), { editor: 'system', command: '' })+ expect(await readFile(path, 'utf8')).toBe(content)++ await configFile.save({ editor: 'vscode', command: '' })+ expect(await configFile.load()).toEqual({ editor: 'vscode', command: '' })+ })++ it.each(['EACCES', 'EIO'])('reports %s instead of falling back to the system editor', async (code) => {+ await writeFile(join(home, 'settings.yaml'), 'models: {}\n')+ const error = Object.assign(new Error(code), { code })+ vi.mocked(readFile).mockRejectedValueOnce(error)+ await expect(configFile.load()).rejects.toBe(error)++ vi.mocked(readFile).mockRejectedValueOnce(error)+ expect(await configFile.open()).toEqual({ ok: false, path: join(home, 'settings.yaml'), error: code })+ expect(openInEditor).not.toHaveBeenCalled()+ expect(openDirectory).not.toHaveBeenCalled()+ })+it('persists a custom editor and uses it on the next open', async () => {await writeFile(join(home, 'settings.yaml'), 'models: {}\n')await configFile.save({ editor: 'custom', command: ' /Applications/My Editor.app ' })diff --git a/packages/dsh-tauri-model-config/src/host/service/config-file.ts b/packages/dsh-tauri-model-config/src/host/service/config-file.tsindex 971d6243..173ec049 100644--- a/packages/dsh-tauri-model-config/src/host/service/config-file.ts+++ b/packages/dsh-tauri-model-config/src/host/service/config-file.ts@@ -10,14 +10,21 @@ import { openInEditor } from './config-file.utils'export const configFile = defineService({async load(): Promise<EditorPreference> {+ let content: stringtry {- return parseEditorPreference(JSON.parse(await readFile(preferencePath(), 'utf8')))+ content = await readFile(preferencePath(), 'utf8')}catch (error) {if ((error as NodeJS.ErrnoException).code === 'ENOENT')return { editor: 'system', command: '' }throw error}+ try {+ return parseEditorPreference(JSON.parse(content))+ }+ catch {+ return { editor: 'system', command: '' }+ }},async save(preference: EditorPreference): Promise<EditorPreference> {