refactor(config): centralize DSH home paths

This commit is contained in:
Turtle
2026-07-31 16:49:55 +08:00
parent 9e11f438f3
commit 885f1ed1ac
22 changed files with 88 additions and 27 deletions

View File

@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write packages/util/paths/README.md
README.md: b28e684f3183d739c8e229a9b341801dbf345d86
README.zh.md: ab4e8123d19fd56749e3e7a0d59e8cd6bea0c3d0
README.md: 2b3272e019ef2f37386da9156b06a5c151836d8c
README.zh.md: 75cc22581e0e0c5ab18573eb0785251243009121

View File

@@ -8,6 +8,8 @@ Shared filesystem path helpers for DeepSeek Harness user data.
`resolveDshHome()` resolves the single-root DeepSeek Harness home. Precedence, highest first: an explicit configured path, `$DSH_HOME`, then `~/.dsh`. The harness keeps all user data under one root.
`dshHomePath(...segments)` joins child segments onto that resolved home with Node's platform path rules. With no segments it returns the home itself.
`dshHomeDisplay()` names an active root symbolically for user-facing paths: `~/.dsh` for the default home, `$DSH_HOME` for any configured home. It never leaks an absolute machine path.
`DSH_HOME_DIR_NAME` owns the default user-data directory name: `.dsh`.

View File

@@ -8,6 +8,8 @@ DeepSeek Harness 用户数据的共享文件系统路径辅助工具。
`resolveDshHome()` 解析 DeepSeek Harness 的单根主目录。优先级从高到低为:显式配置的路径、`$DSH_HOME``~/.dsh`。harness 将所有用户数据保存在同一根目录下。
`dshHomePath(...segments)` 使用 Node 的平台路径规则,将子路径段拼接到解析后的主目录下。不传入任何路径段时,返回主目录本身。
`dshHomeDisplay()` 以符号方式表示当前根目录,用于面向用户的路径:默认主目录表示为 `~/.dsh`,任何已配置的主目录表示为 `$DSH_HOME`。它绝不会泄露机器的绝对路径。
`DSH_HOME_DIR_NAME` 定义默认用户数据目录名:`.dsh`

View File

@@ -52,6 +52,15 @@ export function resolveDshHome(configured?: string, env: Record<string, string |
return resolve(expandHomePath(selected))
}
/**
* Join path segments onto the resolved DeepSeek Harness home.
* @param segments - path segments appended to the Harness home; an empty list returns the home itself.
* @returns the normalized absolute joined path.
*/
export function dshHomePath(...segments: string[]): string {
return join(resolveDshHome(), ...segments)
}
/**
* Describe a resolved harness home symbolically for user-facing display.
*

View File

@@ -1,15 +1,20 @@
import { homedir } from 'node:os'
import { join, resolve } from 'node:path'
import { describe, expect, it } from 'vitest'
import { afterEach, describe, expect, it, vi } from 'vitest'
import {
DEFAULT_DSH_HOME_DISPLAY,
DSH_HOME_DIR_NAME,
defaultDshHome,
dshHomeDisplay,
dshHomePath,
expandHomePath,
resolveDshHome,
} from '@deepseek-ai/dsh-paths'
afterEach(() => {
vi.unstubAllEnvs()
})
describe('dsh path helpers', () => {
it('owns the shared default DSH home directory name', () => {
expect(DSH_HOME_DIR_NAME).toBe('.dsh')
@@ -38,6 +43,12 @@ describe('dsh path helpers', () => {
expect(resolveDshHome(undefined, { DSH_HOME: ' ' })).toBe(defaultDshHome())
})
it('joins child segments onto the resolved DSH_HOME', () => {
vi.stubEnv('DSH_HOME', '~/env-dsh')
expect(dshHomePath()).toBe(join(homedir(), 'env-dsh'))
expect(dshHomePath('storages', 'cache')).toBe(join(homedir(), 'env-dsh', 'storages', 'cache'))
})
it('labels a resolved home by whether it is the default root', () => {
expect(dshHomeDisplay(resolve(defaultDshHome()))).toBe('~/.dsh')
expect(dshHomeDisplay('/some/other/root')).toBe('$DSH_HOME')