Skip to content

fix(ui): 修复 Windows Home 路径缩写 - #356

Open
627150795 wants to merge 3 commits into
openpi-dev:mainfrom
627150795:fix/issue-335-windows-home-path
Open

fix(ui): 修复 Windows Home 路径缩写#356
627150795 wants to merge 3 commits into
openpi-dev:mainfrom
627150795:fix/issue-335-windows-home-path

Conversation

@627150795

Copy link
Copy Markdown
Contributor

Problem

在 Windows 上,homedir() 和当前工作目录使用反斜杠(\),而 formatDirectory 只检查 ${home}/。因此 Home 目录下的工作目录无法缩写为 ~/...,页脚会显示完整绝对路径。

关联 Issue:#335

Value

修复 Windows 页脚当前目录显示,减少无用的绝对路径占用,同时保持 POSIX 路径、Home 根目录和 Home 外路径的现有行为。

Approach

  • 让 Home 子路径判断同时支持 /\\ 分隔符。
  • 将 Windows 子路径转换为页脚统一使用的 / 展示格式。
  • 保留 Home 根目录显示为 ~,并避免把 C:\\Users\\Adam2 等相邻路径误判为 Home 子路径。
  • 增加 POSIX、Windows、Home 根目录及 Home 外路径的回归测试。

Validation

  • node --test tests/extensions/ui-customization/footer.test.ts:14/14 通过。
  • bun run check:通过(配置契约、纪律检查、Web 语法、格式、Lint、TypeScript)。
  • git diff --check:通过。
  • bun run test:Windows 本地完整套件仍遇到已有的 background-terminals 进程测试失败并挂起;相关问题与本 PR 修改的页脚文件无关。

Impact

  • 用户可见行为:Windows Home 目录下的页脚 cwd 改为 ~/...,其他路径行为不变。
  • 模型可见工具:无变化。
  • 运行时与生命周期:无变化。
  • 持久化配置或数据:无变化。
  • 兼容性与风险:低;仅调整目录显示格式。

Fixes #335

@github-actions github-actions Bot added the area:ui Terminal UI, rendering, themes, or visual assets label Sep 2, 2026

@tt-a1i tt-a1i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the focused fix. The common Windows backslash case is covered and the current CI is green, but the containment check still needs to be path-flavor aware. Please address the inline cross-platform regression and add the two boundary tests before this merges.

Comment thread extensions/ui-customization/footer.ts Outdated
export function formatDirectory(cwd: string, home = homedir()) {
if (cwd === home) return "~";
const display = cwd.startsWith(`${home}/`) ? `~/${relative(home, cwd)}` : cwd;
const separator = cwd.startsWith(home) ? cwd[home.length] : undefined;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This accepts both / and \\ as separators on every platform. On POSIX, \\ is an ordinary filename character, so formatDirectory("/Users/adam\\\\project", "/Users/adam") incorrectly returns ~/project even though that cwd is not inside the Home directory. The raw prefix check is also case-sensitive on Windows: c:\\\\users\\\\adam\\\\project is not shortened against C:\\\\Users\\\\Adam, although Windows treats them as the same path. Please make containment platform/path-flavor aware (for example, use the appropriate win32.relative or posix.relative behind an injectable path flavor), reject parent/absolute relative results, normalize separators only for display, and add regression tests for both cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ui Terminal UI, rendering, themes, or visual assets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(ui-customization): support Windows backslash home path shortening in footer cwd segment

2 participants