Repository navigation
# [bug] Windows 工作区路径未保留映射盘符拼写 Windows workspace paths do not preserve the mapped drive letter spelling #9223
Replies: 1 comment
|
根因确认了:做的就是这个函数。但有一点比你的报告更简单——「会话 cwd 也变成 UNC」不是第二个 bug,而是必然结果;另外仓库里已经有你要的那个分离模式,可以直接当先例,改法能落到很具体的位置。 1. 根因与调用链
export async function realpathNormalize(path: string): Promise<string> {
if (!fullyQualifiedWorkspacePath(path)) { throw new TypeError(...) }
return await realpath(path)
}你引的片段逐字准确。三条入口都过它:
2. 「会话 cwd 也是 UNC」不是第二个 bug
const cwd = workspace?.path ?? request.cwd ?? this.defaultCwd会话 cwd 直接取 workspace 的 3. ⭐ 仓库里已经有你要的「身份 / 表示」分离这条最有说服力,因为它把抽象建议变成"照隔壁写"。 export interface LocalTarget {
/** Absolute path (symlinks not resolved) — used for display. */
displayPath: string
/** Realpath identity — used as the stable target key and the I/O path. */
targetKey: FsTargetKey
}
缺的只是一路带到头: 4. 由此得到的改法(很小)
这正好是包内已有的做法:
5. 两处措辞
6. 版本你写的是 小结诉求方向(内部身份 / 用户表示分离)正确,而且与仓库现有架构完全兼容 —— 援引 |
Uh oh!
There was an error while loading. Please reload this page.
[bug] Windows 工作区路径未保留映射盘符拼写
0.2.0-rc.2摘要
在 Windows 上通过映射盘符添加工作区时,DSH 经
fs.realpath规范化路径,盘符会被解析为 UNC 形式并持久化。此后工作区标题、会话 cwd、所有工具调用中呈现的路径全部使用 UNC 拼写。直接后果:保存的工作区路径与用户输入/认可的路径不一致,且被改写后的网络位置会进入模型上下文。
希望工作区路径保留用户输入的原始拼写,同时减少不必要的上下文暴露。
复现步骤
将网络共享映射为盘符:
以
Z:\demo添加工作区。实际表现:工作区被存储并显示为
\\server\share\username\projects\demo;模型与用户看到的全部路径(会话 cwd、文件工具、交付物路径)均为 UNC 拼写。根因
源码
@deepseek-ai/dsh-workspace通过realpathNormalize(源码src/paths.ts,编译产物见lib/types/paths.js及lib/index.js中的内联拷贝)规范化工作区路径:平台行为
在 Windows 上,realpath 的 native 路径(
GetFinalPathNameByHandle,VOLUME_NAME_DOS)会把经映射网络盘符打开的句柄解析为 UNC 形式。该行为由 Win32 API 的既有语义决定,自引入
GetFinalPathNameByHandle的系统版本起一贯如此,理论上与具体 Windows 版本无关。这是已知的平台行为,并非 DSH 特有:
fs.realpath在 Windows 上无法保留挂载点/盘符拼写;File.getCanonicalPath在网络驱动器上同样解析为 UNC。影响
建议
workaround:当持久化的路径与用户输入的拼写不一致时,明确告知用户"工作区路径改写为 ...",让静默改写可见;
fix:工作区记录尽量保存用户提供的原始拼写,内部身份与用户表示分离。
用户表示:工作区应保存用户一侧提供的合法路径拼写,界面展示、会话提示词、模型上下文一律以用户提供的表示为准;
内部身份:在需要一致表示的内部环节(如路径解析、沙箱判定、命令执行等),将同一路径的不同拼写,幂等地映射到规范表示(如UNC),从而保留等价的合法拼写同时不产生歧义。
这样可连带修复BUG: 超出工作区(Windows·SMB映射驱动器)File operations judged as "out of workspace" #3749。
English Version:
[bug] Windows workspace paths do not preserve the mapped drive letter spelling
0.2.0-rc.2Summary
When a workspace is added on Windows via a mapped drive letter, DSH canonicalizes the path through
fs.realpath, which resolves the drive letter to its UNC form and persists it. From then on, the workspace title, the session cwd, and every path surfaced by tool calls all use the UNC spelling.Immediate consequence: the stored workspace path no longer matches the path the user entered or endorsed, and the rewritten network location enters the model's context.
The workspace path should preserve the spelling the user entered, and unnecessary context exposure should be reduced.
Reproduction
Map a network share to a drive letter:
Add
Z:\demoas a workspace.Observed: the workspace is stored and displayed as
\\server\share\username\projects\demo; every path seen by the model and the user (session cwd, file tools, deliverable paths) uses the UNC spelling.Root cause
Source
@deepseek-ai/dsh-workspacecanonicalizes workspace paths throughrealpathNormalize(sourcesrc/paths.ts; compiled artifacts inlib/types/paths.jsand the inlined copy inlib/index.js):Platform behavior
On Windows, the native realpath path (
GetFinalPathNameByHandlewithVOLUME_NAME_DOS) resolves handles opened through a mapped network drive to their UNC form.This behavior follows from the established semantics of the Win32 API and has been consistent ever since the system version that introduced
GetFinalPathNameByHandle; in principle it is independent of the specific Windows version.It is a known platform behavior, not DSH-specific:
fs.realpathcannot preserve mount-point/drive-letter spellings on Windows;File.getCanonicalPathlikewise resolves network drives to UNC.Impact
Proposal
Workaround: whenever the persisted path's spelling differs from what the user entered, tell the user explicitly ("workspace path rewritten to ..."), making the silent rewrite visible;
Fix: store the user-supplied spelling in the workspace record, decoupling internal identity from the user-facing representation.
User representation: the workspace should keep the legal path spelling supplied by the user; UI display, session prompts, and model context should all follow the user-supplied representation.
Internal identity: in internal steps that need a consistent representation (path resolution, sandbox checks, command execution, etc.), map the different spellings of the same path idempotently onto a canonical form (e.g. UNC), so that equivalent legal spellings are preserved without ambiguity.
This would also fix BUG: 超出工作区(Windows·SMB映射驱动器)File operations judged as "out of workspace" #3749 as a side effect.
All reactions