Web UI abbreviates POSIX home paths as `~`
Web UI abbreviates POSIX home paths as `~`
Workspace hover cards and Tool call summaries showed full POSIX home paths. Those strings are long, repeat the same prefix on every row, and make the sidebar and transcript harder to scan. Windows paths must stay verbatim because `~` is not a Windows filesystem convention.
English
Problem
Workspace hover cards and Tool call summaries showed full POSIX home paths. Those strings are long, repeat the same prefix on every row, and make the sidebar and transcript harder to scan. Windows paths must stay verbatim because ~ is not a Windows filesystem convention.
Decision
host.describe reports the host account home as a required field. Client and Host ship together, so the field is required rather than optional. ApiProxy fills it from homedir() at describe time.
abbreviateHomePath in dsh-client-runtime is the display-only helper. It returns ~ or ~/… when the path is the POSIX home or a descendant, and leaves the path unchanged when home is missing, empty, or /, when either value is a Windows drive or UNC path, or when the match is only a prefix (/Users/u does not claim /Users/u2). Tool summaries run workspace-relative shortening first, then this helper, so a path inside the session cwd stays short. filePath, Host open, and Workspace hover copy keep the authored filesystem path.
ui-tool and ui-workspace inject connection.hostDescription at their own slot registrations. ChatView does not grow a Host-description hook. The field is required on ConnectionHandle; test fakes supply a source whose snapshot may be undefined before connect.
The fixture Host home is /home/fixture. A second fixture Workspace at /home/fixture/Documents/project lets assembled replay hover ~/Documents/project without moving the existing /tmp/fixture account. TerminalBlock's own prompt-label collapse is unchanged.
Alternatives considered
Guess /Users or /home without the real home. Rejected because a shared prefix is not an account home, and /Users/shared or /home/src would abbreviate incorrectly.
Abbreviate Windows %USERPROFILE% as ~ as well. Rejected because the acceptance rule keeps Windows paths verbatim, and ~ is not how Explorer or cmd spell those paths.
Put the helper in dsh-home-paths. Rejected because that package expands configuration tildes on Node; this helper is a browser display rewrite and must not pull Node os into client bundles.
Thread home from ChatView owner props. Rejected because it enlarges the conversation inject face and every ChatView test harness for a display fact only Tool and Workspace cards consume.
Consequences
POSIX home-rooted Workspace hover paths and leftover Tool path summaries display as ~. Copy and open still use the full path. Windows drive and UNC paths never become ~. A Host that reports / as home does not turn the whole filesystem into ~. Before the first describe, or while reconnecting, the source snapshot is undefined and paths stay unabbreviated.
Testing
Package tests cover abbreviateHomePath, toolRowModel / readCardModel home abbreviation, Workspace hover display versus copy, and host.describe schema plus live homedir(). Assembled replay apps/web/tests/home-path-tilde.snapshot.ts hovers the fixture home-descendant Workspace. Product-GUI PRs still record a real-browser GIF of the hover card.
中文
Problem
Workspace 悬停卡片和 Tool 调用摘要会显示完整的 POSIX 家目录路径。这些字符串很长,每行重复同一前缀,侧边栏和对话记录更难扫读。Windows 路径必须保持原样,因为 ~ 不是 Windows 文件系统约定。
Decision
host.describe 把宿主账户的 home 作为必填字段上报。Client 与 Host 一同发布,因此该字段是必填而不是可选。ApiProxy 在 describe 时用 homedir() 填入。
dsh-client-runtime 中的 abbreviateHomePath 是仅用于展示的辅助函数。当路径是 POSIX 家目录或其后代时返回 ~ 或 ~/…;home 缺失、为空或为 /,任一侧是 Windows 盘符或 UNC 路径,或只是前缀命中(/Users/u 不能收走 /Users/u2)时,路径保持不变。Tool 摘要先做工作区相对缩短,再调用该辅助函数,因此会话 cwd 内的路径仍然更短。filePath、Host 打开以及 Workspace 悬停复制仍使用作者给出的文件系统路径。
ui-tool 与 ui-workspace 在各自的 slot 注册上注入 connection.hostDescription。ChatView 不增加 Host 描述钩子。该字段在 ConnectionHandle 上是必填的;测试假对象提供一个来源,其快照在连接完成前可以为 undefined。
fixture 的 Host 家目录是 /home/fixture。第二个 fixture Workspace 位于 /home/fixture/Documents/project,组装回放可以悬停出 ~/Documents/project,而不必移动现有的 /tmp/fixture 账户。TerminalBlock 自有的提示符标签折叠保持不变。
Alternatives considered
在没有真实 home 的情况下猜测 /Users 或 /home。 否决,因为共享前缀不是账户家目录,/Users/shared 或 /home/src 会被错误缩写。
同样把 Windows %USERPROFILE% 缩写成 ~。 否决,因为验收规则要求 Windows 路径保持原样,而且 Explorer 与 cmd 并不这样拼写这些路径。
把辅助函数放进 dsh-home-paths。 否决,因为该包在 Node 上展开配置里的波浪号;本辅助函数是浏览器展示改写,不能把 Node os 拉进 client 包。
从 ChatView owner props 向下传递 home。 否决,因为它会扩大 conversation 注入面和每一份 ChatView 测试夹具,而只有 Tool 与 Workspace 卡片消费这个展示事实。
Consequences
POSIX 家目录下的 Workspace 悬停路径,以及缩短 cwd 后仍落在家目录里的 Tool 路径摘要,会显示为 ~。复制与打开仍使用完整路径。Windows 盘符和 UNC 路径永远不会变成 ~。若 Host 把 / 报成 home,不会把整个文件系统收成 ~。首次 describe 之前或重连期间,来源快照为 undefined,路径保持未缩写。
Testing
包测试覆盖 abbreviateHomePath、toolRowModel/readCardModel 的家目录缩写、Workspace 悬停展示与复制,以及 host.describe schema 与实时 homedir()。组装回放 apps/web/tests/home-path-tilde.snapshot.ts 悬停 fixture 中位于家目录下的 Workspace。面向产品 GUI 的 PR 仍需录制悬停卡片的真实浏览器 GIF。