Repository navigation
feat(workbench): reveal local workspace files in file manager - #7584
Conversation
Resolve the original session's workspace path against its current read policy at activation. Keep external previews and remote Host paths out of native desktop navigation. Refs apache#2664
There was a problem hiding this comment.
English
1. Duplicate Reveal buttons in binary/directory states & dead Reveal button in loading/absent/error states
- In
products/maka/workbench/app/CurrentFile.tsx,<If when={model.reveal && view()?.kind !== 'text'}>renders a top-right<RevealFile />, while<If when={emptyReveal()}>renders a second<RevealFile primary />inside the empty state forbinaryanddirectoryitems. - As a result, binary and directory views display two identical Reveal buttons at the same time (currently locked in by
assert_eq!(app.screen().count(button).unwrap(), 2)inproducts/maka/workbench/src/lib.rs), andloading/absent/errorstates still keep the top-right Reveal button visible even though clicking it will fail. - Suggestion: Restrict the top-right
<RevealFile />to non-text views that don't render the empty-state primary button and can actually be revealed (e.g.image, andchanged), keep only the single primary button inbinary/directoryempty states, hide Reveal duringloading/absent/error/symlink, and update the headless test to assert 1 (or 0) button per state.
2. dunce::canonicalize(&absolute)? != absolute can falsely reject valid paths with differing case on Windows & macOS
- In
plugins/workspace/workspace-files/engine/src/files/preview.rs,reveal_targetreturnsfiles_privatewheneverdunce::canonicalize(&absolute)? != absolute. PathBuf::eqis case-sensitive, while both Windows (NTFS) and default macOS (APFS) are case-insensitive. If a Markdown link citesreadme.mdwhile the file on disk isREADME.md,file_parentandsymlink_metadatasucceed, butdunce::canonicalize(&absolute)returns the on-disk casing (.../README.md), causing!=to reject a valid workspace file asfiles_private("This conversation cannot read that path.").- Since
file_parent+validate_inner()already pins every ancestor withcap_std::fs::Dirandsymlink_metadatarules out leaf symlinks/junctions, consider verifyingcanonical.parent() == Some(target.path.as_path())(after confirming the leaf isn't a symlink) and returningcanonical.
3. Reuse existing "Show in File Explorer" locale key & WSL error copy
- All 12 workbench locales already define
"Show in File Explorer"(used byplugins/application/applications/ui.tsxand PR #7583'sfile-search/ui.tsx, matching native Windows terminology). Introducing a new"Reveal in File Explorer"key duplicates existing translations and diverges across the UI. - Minor UX note: on a local desktop client with a WSL (
Sandbox::External) session,host.localFolderPickeris stilltrue, so the Reveal button is shown and fails on click with"File preview requires a local workspace."fromread_policy. Using a reveal-specific error (or hiding the button for external sandboxes) would be cleaner.
简体中文
1. 二进制/目录空态下同时出现两个相同的 Reveal 按钮,且 loading / 缺失 / 报错态顶栏仍挂着失效按钮
products/maka/workbench/app/CurrentFile.tsx在顶部通过<If when={model.reveal && view()?.kind !== 'text'}>渲染了一个右上角<RevealFile />,同时又在空态里通过<If when={emptyReveal()}>为binary和directory渲染了第二个<RevealFile primary />。- 这导致二进制文件和目录视图中同时出现两个功能完全重复的 Reveal 按钮(
products/maka/workbench/src/lib.rs中的assert_eq!(app.screen().count(button).unwrap(), 2)还把这一重复行为锁死了);同时在loading、absent(文件已不存在)和error状态下,右上角依然挂着点下去必报错的 Reveal 按钮。 - 建议:顶栏
<RevealFile />仅在非文本、无空态主按钮且确实可定位的状态下显示(如image、changed);binary/directory空态只保留正中一个主按钮;loading/absent/error/symlink状态不展示按钮,并同步把测试断言改为每个状态 1 个(或 0 个)按钮。
2. preview.rs 中 dunce::canonicalize(&absolute)? != absolute 在 Windows / macOS 路径大小写不同时会误报 files_private
plugins/workspace/workspace-files/engine/src/files/preview.rs的reveal_target在dunce::canonicalize(&absolute)? != absolute时直接返回files_private。PathBuf::eq区分大小写,但 Windows(NTFS)和默认 macOS(APFS)都是大小写不敏感文件系统。如果对话里的 Markdown 链接写了readme.md而磁盘实际文件名是README.md,file_parent和symlink_metadata都会成功,但dunce::canonicalize(&absolute)返回磁盘真实大小写(.../README.md),导致!=成立并把合法的工作区文件误判为files_private(前端提示无权读取)。- 前面的
file_parent+validate_inner()已用cap_std::fs::Dir锚定整条父目录链,symlink_metadata也排除了叶节点 symlink/junction;建议在确认非 symlink 后校验canonical.parent() == Some(target.path.as_path())并直接返回canonical。
3. 复用既有的 "Show in File Explorer" 文案键 & WSL 报错文案
- 全仓 12 套 workbench locale 早已有
"Show in File Explorer"(plugins/application/applications/ui.tsx和 PR #7583 的file-search/ui.tsx都在用,也更符合 Windows 原生术语)。新增"Reveal in File Explorer"会造成翻译重复且应用内文案不统一。 - 小细节:本地桌面端打开 WSL(
Sandbox::External)会话时,host.localFolderPicker仍为true,Reveal 按钮依然显示,点击后会在read_policy报错并弹出"File preview requires a local workspace."。建议换成贴合 reveal 的报错提示,或对外部沙箱直接隐藏按钮。
|
Thanks @M4n5ter. I addressed the review in be56f05:
Tested locally on Windows: file-engine library 32/32, Workbench frontend 457/457, and the targeted Workbench headless and agent-native Reveal tests passed, as did tsc, Biome on changed files, i18n and ASF checks. The external-sandbox case was unit-tested, not exercised in a live WSL desktop session. |
M4n5ter
left a comment
There was a problem hiding this comment.
English
Thanks for the quick turnaround—the CurrentFile button cleanup, "Show in File Explorer" reuse, WSL error message, and Windows tests all look great. Two follow-up items:
1. Please revert require_local_reveal back to allowing Identity::Remote (my earlier review mistake—sorry!)
- Apologies: my initial review comment misread
Identity::Remoteas an untrusted remote network client (I later edited that item out, but you had already addressed the earlier version inbe56f05b). - In Maka, Desktop Workbench connects to the local Host over the Application Transport (
platform/host-runtime/src/application/transport/policy.rs), so every local Workbench call arrives atagent/nativewithIdentity::Remote { request_id }(which is whysave_filein the same file allowsIdentity::Native | Identity::Remote { .. }). - Restricting
require_local_revealtoIdentity::Nativealone will cause every live desktop Reveal click to fail with"Only the local workspace client may reveal a file.". Please restoreIdentity::Native | Identity::Remote { .. }(rejectingAgent/Background/BrowserLease) and updatereveal_requires_native_client_and_local_workspaceaccordingly.
2. Drop the !cfg!(windows) guard on canonical != absolute so macOS APFS is covered too
- In
plugins/workspace/workspace-files/engine/src/files/preview.rs,(!cfg!(windows) && canonical != absolute)will still falsely reject valid links whose casing differs from the on-disk filename on default macOS (case-insensitive APFS), e.g.readme.md->README.md. - Since the leaf is already verified non-symlink via
symlink_metadata, the ancestor chain is pinned viafile_parent+validate_inner(), and the remaining checks enforcecanonical.parent() == Some(target.path.as_path()),!excluded_child, andpolicy.access(&canonical).can_read(), removing(!cfg!(windows) && canonical != absolute) ||handles Windows, macOS, and Linux uniformly.
简体中文
感谢快速响应,CurrentFile 的按钮精简、复用 "Show in File Explorer"、WSL 报错文案和 Windows 测试都改得很干净。还有两处需要调整:
1. 请把 require_local_reveal 改回放行 Identity::Remote(抱歉,这是我上一轮初版 review 的误报)
- 先道个歉:我上一轮初版 review 误把
Identity::Remote理解成了远端客户端(后来编辑删掉了那条,但你已经按旧版改在了be56f05b里)。 - 实际架构里,本机 Desktop Workbench 是通过 Application Transport(
platform/host-runtime/src/application/transport/policy.rs)连本机 Host 的,所有本机桌面端请求到达agent/native时scope.identity都是Identity::Remote { request_id }(同文件的save_file也因此放行Identity::Native | Identity::Remote { .. })。 - 仅放行
Identity::Native会导致真机桌面端每次点击 Reveal 都报错"Only the local workspace client may reveal a file."。请改回放行Identity::Native | Identity::Remote { .. }(拒绝Agent/Background/BrowserLease),并同步更新reveal_requires_native_client_and_local_workspace单测。
2. preview.rs 建议去掉 !cfg!(windows) && canonical != absolute,一并兼容 macOS APFS 大小写
plugins/workspace/workspace-files/engine/src/files/preview.rs目前的(!cfg!(windows) && canonical != absolute)在默认 macOS(大小写不敏感 APFS)上依然会把大小写不一致的合法链接(如readme.md->README.md)误判为files_private。- 前面已通过
symlink_metadata排除叶节点符号链接、通过file_parent+validate_inner()锚定父目录链,后面也已校验canonical.parent() == Some(target.path.as_path())、!excluded_child和policy.access(&canonical).can_read(),直接去掉(!cfg!(windows) && canonical != absolute) ||就能同时覆盖 Windows、macOS 和 Linux。
|
Thanks for clarifying the transport identity and the APFS case, @M4n5ter. Both are addressed in c5b2657. Reveal now accepts the local Workbench's Tested locally on Windows only: all 32 file-engine tests, the identity and headless Reveal tests, and all 457 workbench frontend tests passed. Biome, rustfmt, and ASF checks passed too. I checked the macOS path statically; CI verification of this revision is pending. |
M4n5ter
left a comment
There was a problem hiding this comment.
English
LGTM — transport identity handling and cross-platform case-insensitive path checks look solid now.
简体中文
LGTM —— transport 身份放行和跨平台大小写不敏感路径校验现在都妥了。
Summary
Add a Reveal action to CurrentFile so users can locate a workspace file or directory in the local file manager, even when no preview is available. This does not open files in their default application.
Relates to #2664
Security
Resolve the originating session and relative path against the current workspace read policy on each click. Remote and WSL hosts and external previews cannot supply a path for native reveal.
Verification
Implementation checks: 7/7 file-engine tests and 457/457 Workbench frontend tests passed. Mounted CurrentFile interaction and link-navigation tests, native agent cargo check, Workbench and Plugin SDK typechecks, formatting and 12-locale validation passed. Native file-manager launch was not manually tested on all three desktop platforms.
AI use
Tool(s) and scope: Maka agent assisted with the change and PR preparation. Please retain a
Generated-by: Makatrailer when squashing.Checklist
Does this PR entail a breaking change or persisted-data migration?
Does this PR entail a change in behavior?