Skip to content

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

refactor(panel-extension): resolve the data root from DSH_HOME

hairyfcff7ac988d4d
diff --git a/packages/dsh-tauri-panel-extension/src/host/apply.ts b/packages/dsh-tauri-panel-extension/src/host/apply.ts
index d04899be..5f294080 100644
--- a/packages/dsh-tauri-panel-extension/src/host/apply.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/apply.ts
@@ -15,7 +15,6 @@ import type { HostContext } from 'dsh-tauri'
import type { ExtensionRouteDeps } from './types'
import { existsSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
-import { DSH_HOME } from 'dsh-tauri'
import { dirname, join } from 'pathe'
import { PLUGIN_NAME } from '../shared/constants'
import { providerHooks } from './hooks'
@@ -146,7 +145,6 @@ export function apply(ctx: HostContext, config?: Config): void {
const deps: ExtensionRouteDeps = {
profileDirPath: profileDir(profile),
remountProvider,
- dshHome: DSH_HOME,
}
ctx.effect(() => routes(hostCtx, deps), 'dsh-tauri-panel-extension: routes')
return disposer
diff --git a/packages/dsh-tauri-panel-extension/src/host/routes/import/apply/post.ts b/packages/dsh-tauri-panel-extension/src/host/routes/import/apply/post.ts
index 22dfb6dc..02837bcb 100644
--- a/packages/dsh-tauri-panel-extension/src/host/routes/import/apply/post.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/routes/import/apply/post.ts
@@ -24,12 +24,12 @@ export default defineEventHandler(async (event) => {
typeof item === 'object' && item !== null && typeof (item as { agent?: unknown }).agent === 'string' && typeof (item as { name?: unknown }).name === 'string')
.map(item => `${item.agent}/${item.name}`),
)
- const dir = mcpScopeDir(normalizeMcpScope(body?.scope), deps.profileDirPath, deps.dshHome)
+ const dir = mcpScopeDir(normalizeMcpScope(body?.scope), deps.profileDirPath)
const results: Array<{ name: string, ok: boolean, error?: string }> = []
for (const server of scanAllMcp()) {
if (!wanted.has(`${server.agent}/${server.name}`))
continue
- const existing = listMcpScoped(deps.profileDirPath, deps.dshHome).servers.some(row => row.serverName === server.name)
+ const existing = listMcpScoped(deps.profileDirPath).servers.some(row => row.serverName === server.name)
if (existing) {
results.push({ name: server.name, ok: false, error: 'already in profile' })
continue
diff --git a/packages/dsh-tauri-panel-extension/src/host/routes/import/scan/get.ts b/packages/dsh-tauri-panel-extension/src/host/routes/import/scan/get.ts
index f051d7e2..a4c58673 100644
--- a/packages/dsh-tauri-panel-extension/src/host/routes/import/scan/get.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/routes/import/scan/get.ts
@@ -16,7 +16,7 @@ export default defineEventHandler((event) => {
return {
servers: scanAllMcp(),
// Profile serverNames, so the browser can grey out existing ones.
- existing: listMcpScoped(deps.profileDirPath, deps.dshHome).servers.map(row => row.serverName),
+ existing: listMcpScoped(deps.profileDirPath).servers.map(row => row.serverName),
}
}
catch (error) {
diff --git a/packages/dsh-tauri-panel-extension/src/host/routes/index.test.ts b/packages/dsh-tauri-panel-extension/src/host/routes/index.test.ts
index e831f7e0..97da52fc 100644
--- a/packages/dsh-tauri-panel-extension/src/host/routes/index.test.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/routes/index.test.ts
@@ -17,10 +17,17 @@ import { mkdirSync, mkdtempSync, rmSync } from 'node:fs'
import { createServer } from 'node:http'
import { tmpdir } from 'node:os'
import { join } from 'pathe'
-import { afterEach, describe, expect, it } from 'vitest'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { routes } from '.'
+import { resetTestDshHome } from '../../../../.test/test-utils'
import { API_PREFIX as P } from '../../shared/constants'
+vi.mock('dsh-tauri', async (importOriginal) => {
+ const actual = await importOriginal<typeof import('dsh-tauri')>()
+ const { testDshHome: home } = await import('../../../../.test/test-utils')
+ return { ...actual, DSH_HOME: home }
+})
+
const routeKey = (kind: string, path: string): string => `${kind}\u0000${path}`
/** 迁移前的路由表(路径 + 方法),防止声明漂移。 */
@@ -96,7 +103,6 @@ function createHarness(): Harness {
function mount(harness: Harness): () => void {
return routes(harness.ctx as RoutesContext, {
profileDirPath: join(harness.dir, 'profiles', 'web'),
- dshHome: harness.dir,
remountProvider: async () => {},
})
}
@@ -135,6 +141,10 @@ async function start(): Promise<{ base: string, dispose: () => void }> {
return { base, dispose }
}
+beforeEach(() => {
+ resetTestDshHome()
+})
+
afterEach(async () => {
await Promise.all(servers.splice(0).map(server => new Promise<void>(resolve => server.close(() => resolve()))))
for (const dir of dirs.splice(0))
@@ -296,8 +306,8 @@ describe('能力管理器路由声明', () => {
})
it('同一份声明两次注册下各读各的 deps(两次注册互不串台)', async () => {
- // 两次注册各带自己的 profileDirPath / dshHome。迁移前的模块级单例绑定会被后一次
- // 注册覆盖,先注册的一方会读后一方的目录——本用例即该回归。
+ // 两次注册各带自己的 profileDirPath(数据根 DSH_HOME 是全局的,profile 目录不是)。
+ // 迁移前的模块级单例绑定会被后一次注册覆盖,先注册的一方会读后一方的目录——本用例即该回归。
const first = createHarness()
const second = createHarness()
dirs.push(first.dir, second.dir)
diff --git a/packages/dsh-tauri-panel-extension/src/host/routes/mcp/check/post.ts b/packages/dsh-tauri-panel-extension/src/host/routes/mcp/check/post.ts
index 0d269176..3628b0c7 100644
--- a/packages/dsh-tauri-panel-extension/src/host/routes/mcp/check/post.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/routes/mcp/check/post.ts
@@ -22,7 +22,7 @@ export default defineEventHandler(async (event) => {
}
const id = body.id
try {
- const dir = mcpScopeDir(normalizeMcpScope(body.scope), deps.profileDirPath, deps.dshHome)
+ const dir = mcpScopeDir(normalizeMcpScope(body.scope), deps.profileDirPath)
const row = listMcp(dir).find(item => item.id === id)
if (row === undefined) {
event.res.status = 404
diff --git a/packages/dsh-tauri-panel-extension/src/host/routes/mcp/copy/post.ts b/packages/dsh-tauri-panel-extension/src/host/routes/mcp/copy/post.ts
index 79b0bd89..292e978c 100644
--- a/packages/dsh-tauri-panel-extension/src/host/routes/mcp/copy/post.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/routes/mcp/copy/post.ts
@@ -21,7 +21,7 @@ export default defineEventHandler(async (event) => {
}
const id = body.id
try {
- const sourceDir = mcpScopeDir(normalizeMcpScope(body.scope), deps.profileDirPath, deps.dshHome)
+ const sourceDir = mcpScopeDir(normalizeMcpScope(body.scope), deps.profileDirPath)
const source = listMcp(sourceDir).find(item => item.id === id)
if (source === undefined) {
event.res.status = 404
@@ -29,7 +29,7 @@ export default defineEventHandler(async (event) => {
}
const scope = normalizeMcpScope(body.toScope)
const createdId = upsertMcp(
- mcpScopeDir(scope, deps.profileDirPath, deps.dshHome),
+ mcpScopeDir(scope, deps.profileDirPath),
mcpRowToInput(source),
)
return { ok: true, id: createdId, scope, restartNeeded: true }
diff --git a/packages/dsh-tauri-panel-extension/src/host/routes/mcp/get.ts b/packages/dsh-tauri-panel-extension/src/host/routes/mcp/get.ts
index 6ebc6f88..aa4b194f 100644
--- a/packages/dsh-tauri-panel-extension/src/host/routes/mcp/get.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/routes/mcp/get.ts
@@ -11,5 +11,5 @@ import { listMcpScoped } from '../../service/mcp'
export default defineEventHandler((event) => {
const deps = dshRouteDepsOf<ExtensionRouteDeps>(event)!
- return { ...listMcpScoped(deps.profileDirPath, deps.dshHome), restartNeeded: true }
+ return { ...listMcpScoped(deps.profileDirPath), restartNeeded: true }
})
diff --git a/packages/dsh-tauri-panel-extension/src/host/routes/mcp/remove/post.ts b/packages/dsh-tauri-panel-extension/src/host/routes/mcp/remove/post.ts
index 465a1ac9..aeefa441 100644
--- a/packages/dsh-tauri-panel-extension/src/host/routes/mcp/remove/post.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/routes/mcp/remove/post.ts
@@ -21,7 +21,7 @@ export default defineEventHandler(async (event) => {
}
const id = body.id
try {
- const ok = removeMcp(mcpScopeDir(normalizeMcpScope(body.scope), deps.profileDirPath, deps.dshHome), id)
+ const ok = removeMcp(mcpScopeDir(normalizeMcpScope(body.scope), deps.profileDirPath), id)
if (!ok) {
event.res.status = 404
return { error: 'server row not found' }
diff --git a/packages/dsh-tauri-panel-extension/src/host/routes/mcp/save/post.ts b/packages/dsh-tauri-panel-extension/src/host/routes/mcp/save/post.ts
index 60512421..7c19c440 100644
--- a/packages/dsh-tauri-panel-extension/src/host/routes/mcp/save/post.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/routes/mcp/save/post.ts
@@ -25,7 +25,7 @@ export default defineEventHandler(async (event) => {
return { error: invalid }
}
const scope = normalizeMcpScope(body.scope)
- const id = upsertMcp(mcpScopeDir(scope, deps.profileDirPath, deps.dshHome), body)
+ const id = upsertMcp(mcpScopeDir(scope, deps.profileDirPath), body)
return { ok: true, id, restartNeeded: true }
}
catch (error) {
diff --git a/packages/dsh-tauri-panel-extension/src/host/routes/mcp/toggle/post.ts b/packages/dsh-tauri-panel-extension/src/host/routes/mcp/toggle/post.ts
index ab8c709b..7421a914 100644
--- a/packages/dsh-tauri-panel-extension/src/host/routes/mcp/toggle/post.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/routes/mcp/toggle/post.ts
@@ -22,7 +22,7 @@ export default defineEventHandler(async (event) => {
const id = body.id
const disabled = body.disabled
try {
- const ok = setMcpDisabled(mcpScopeDir(normalizeMcpScope(body.scope), deps.profileDirPath, deps.dshHome), id, disabled)
+ const ok = setMcpDisabled(mcpScopeDir(normalizeMcpScope(body.scope), deps.profileDirPath), id, disabled)
if (!ok) {
event.res.status = 404
return { error: 'server row not found' }
diff --git a/packages/dsh-tauri-panel-extension/src/host/service/mcp.ts b/packages/dsh-tauri-panel-extension/src/host/service/mcp.ts
index 69a1e33a..79a77dea 100644
--- a/packages/dsh-tauri-panel-extension/src/host/service/mcp.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/service/mcp.ts
@@ -21,6 +21,7 @@
import type { YAMLMap, YAMLSeq } from 'yaml'
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import process from 'node:process'
+import { DSH_HOME } from 'dsh-tauri'
import { join } from 'pathe'
import { Document, parseDocument } from 'yaml'
/** The plugin every managed row instantiates. */
@@ -232,12 +233,12 @@ export function listMcp(dirPath: string): McpRow[] {
* profile layer still lists (the assertPatchParses message names the file
* and the parser location, which is what the banner shows).
*/
-export function listMcpScoped(profileDirPath: string, dshHomePath: string): McpListResult {
+export function listMcpScoped(profileDirPath: string): McpListResult {
let globalRows: McpRow[] = []
let globalError: string | undefined
- if (existsSync(join(dshHomePath, 'cordis.patch.yml'))) {
+ if (existsSync(join(DSH_HOME, 'cordis.patch.yml'))) {
try {
- globalRows = listMcp(dshHomePath)
+ globalRows = listMcp(DSH_HOME)
}
catch (error) {
globalError = error instanceof Error ? error.message : String(error)
@@ -258,8 +259,8 @@ export function listMcpScoped(profileDirPath: string, dshHomePath: string): McpL
}
/** Resolve a write target: the layer's directory holding its cordis.patch.yml. */
-export function mcpScopeDir(scope: McpScope, profileDirPath: string, dshHomePath: string): string {
- return scope === 'global' ? dshHomePath : profileDirPath
+export function mcpScopeDir(scope: McpScope, profileDirPath: string): string {
+ return scope === 'global' ? DSH_HOME : profileDirPath
}
/**
diff --git a/packages/dsh-tauri-panel-extension/src/host/service/profile.ts b/packages/dsh-tauri-panel-extension/src/host/service/profile.ts
index 1beba328..e16b9997 100644
--- a/packages/dsh-tauri-panel-extension/src/host/service/profile.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/service/profile.ts
@@ -13,6 +13,6 @@ export function argvProfile(argv: readonly string[] = process.argv): string | un
}
/** Directory of a profile under DSH_HOME(数据根一律引用核心的 DSH_HOME)。 */
-export function profileDir(profile: string, dshHome: string = DSH_HOME): string {
- return join(dshHome, 'profiles', profile)
+export function profileDir(profile: string): string {
+ return join(DSH_HOME, 'profiles', profile)
}
diff --git a/packages/dsh-tauri-panel-extension/src/host/service/skills.ts b/packages/dsh-tauri-panel-extension/src/host/service/skills.ts
index 572d869e..1949e8fa 100644
--- a/packages/dsh-tauri-panel-extension/src/host/service/skills.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/service/skills.ts
@@ -23,8 +23,8 @@ export interface SkillInput {
}
/** The user-owned skill root this plugin writes into (provider rank 400). */
-export function userSkillsDir(dshHome: string = DSH_HOME): string {
- return join(dshHome, 'skills')
+export function userSkillsDir(): string {
+ return join(DSH_HOME, 'skills')
}
/** YAML double-quoted scalar (JSON string syntax is valid YAML 1.2). */
@@ -64,13 +64,13 @@ export function validateSkillInput(input: SkillInput): string | null {
}
/** Directory holding one user skill's SKILL.md; name grammar blocks traversal. */
-function skillDir(name: string, dshHome?: string): string {
- return join(userSkillsDir(dshHome), name)
+function skillDir(name: string): string {
+ return join(userSkillsDir(), name)
}
/** Create or update a user skill. Returns the written path. */
-export function writeSkill(input: SkillInput, dshHome?: string): string {
- const dir = skillDir(input.name, dshHome)
+export function writeSkill(input: SkillInput): string {
+ const dir = skillDir(input.name)
mkdirSync(dir, { recursive: true })
const file = join(dir, 'SKILL.md')
writeFileSync(file, serializeSkill(input), 'utf8')
@@ -78,10 +78,10 @@ export function writeSkill(input: SkillInput, dshHome?: string): string {
}
/** Delete a user skill directory. Returns false when it does not exist. */
-export function deleteSkill(name: string, dshHome?: string): boolean {
+export function deleteSkill(name: string): boolean {
if (!SKILL_NAME_RE.test(name))
return false
- const dir = skillDir(name, dshHome)
+ const dir = skillDir(name)
if (!existsSync(dir) || !statSync(dir).isDirectory())
return false
// Only ever remove the exact directory this name resolves to under the
diff --git a/packages/dsh-tauri-panel-extension/src/host/storage/index.ts b/packages/dsh-tauri-panel-extension/src/host/storage/index.ts
index 6c313b61..9f8cf3c4 100644
--- a/packages/dsh-tauri-panel-extension/src/host/storage/index.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/storage/index.ts
@@ -5,8 +5,14 @@
* 实现,不在此写包装。
*/
-import { fsAtomicDriver } from 'dsh-tauri'
+import { DSH_HOME, fsAtomicDriver } from 'dsh-tauri'
+import { join } from 'pathe'
import { createStorage } from 'unstorage'
-/** skills 功能目录存储(`$DSH_HOME/skills`;key 如 `state.json`)。 */
-export const storage = createStorage({ driver: fsAtomicDriver({ base: 'skills' }) })
+/**
+ * skills 功能目录存储(`$DSH_HOME/skills`;key 如 `state.json`)。
+ *
+ * base 必须是**绝对路径**:`fsAtomicDriver` 会把相对 base 拼到 dsh-tauri 内部的
+ * `DSH_HOME` 上,那样 `vi.mock('dsh-tauri')` 换掉数据根时驱动仍会写真实目录。
+ */
+export const storage = createStorage({ driver: fsAtomicDriver({ base: join(DSH_HOME, 'skills') }) })
diff --git a/packages/dsh-tauri-panel-extension/src/host/types/index.ts b/packages/dsh-tauri-panel-extension/src/host/types/index.ts
index 89ea34f7..f8369a7c 100644
--- a/packages/dsh-tauri-panel-extension/src/host/types/index.ts
+++ b/packages/dsh-tauri-panel-extension/src/host/types/index.ts
@@ -63,6 +63,4 @@ export interface ExtensionRouteDeps {
* 技能「刷新」与仓库增删都要先走它,避免删被 watch 的树(Windows EPERM)。
*/
remountProvider: () => Promise<void>
- /** 数据根;装配期由 `apply` 解析(默认 `DSH_HOME`)。 */
- dshHome: string
}