Skip to content

feat(workbench): reveal local workspace files in file manager - #7584

Merged
M4n5ter merged 3 commits into
apache:mainfrom
ARE404:feat/reveal-in-file-manager
Dec 4, 2026
Merged

M4n5ter merged 3 commits into
apache:mainfrom
ARE404:feat/reveal-in-file-manager

Conversation

@ARE404

@ARE404 ARE404 commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

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

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Maka agent assisted with the change and PR preparation. Please retain a Generated-by: Maka trailer when squashing.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

Does this PR entail a breaking change or persisted-data migration?

  • Yes
  • No

Does this PR entail a change in behavior?

  • Yes - described under Summary above
  • No

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

@M4n5ter M4n5ter left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 for binary and directory items.
  • 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) in products/maka/workbench/src/lib.rs), and loading / absent / error states 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, and changed), keep only the single primary button in binary / directory empty states, hide Reveal during loading / 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_target returns files_private whenever dunce::canonicalize(&absolute)? != absolute.
  • PathBuf::eq is case-sensitive, while both Windows (NTFS) and default macOS (APFS) are case-insensitive. If a Markdown link cites readme.md while the file on disk is README.md, file_parent and symlink_metadata succeed, but dunce::canonicalize(&absolute) returns the on-disk casing (.../README.md), causing != to reject a valid workspace file as files_private ("This conversation cannot read that path.").
  • Since file_parent + validate_inner() already pins every ancestor with cap_std::fs::Dir and symlink_metadata rules out leaf symlinks/junctions, consider verifying canonical.parent() == Some(target.path.as_path()) (after confirming the leaf isn't a symlink) and returning canonical.

3. Reuse existing "Show in File Explorer" locale key & WSL error copy

  • All 12 workbench locales already define "Show in File Explorer" (used by plugins/application/applications/ui.tsx and PR #7583's file-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.localFolderPicker is still true, so the Reveal button is shown and fails on click with "File preview requires a local workspace." from read_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 的报错提示,或对外部沙箱直接隐藏按钮。

@ARE404

ARE404 commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @M4n5ter. I addressed the review in be56f05:

  • Binary and directory previews now have one primary Reveal action; text, image and changed views have one toolbar action. Loading, absent, error and symlink states show none. The headless test checks the button counts and the remote-client case.
  • The agent rejects non-native callers before resolving a host path. External sandboxes such as WSL now get a Reveal-specific local-workspace error rather than a preview error.
  • Windows leaf names can differ in case from the on-disk name. Reveal returns the canonical path and still checks the parent, links, private paths and read policy. Tests cover both a case-mismatched filename and case variants of private directory names.
  • Windows reuses the existing “Show in File Explorer” translation key.

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 M4n5ter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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::Remote as an untrusted remote network client (I later edited that item out, but you had already addressed the earlier version in be56f05b).
  • 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 at agent/native with Identity::Remote { request_id } (which is why save_file in the same file allows Identity::Native | Identity::Remote { .. }).
  • Restricting require_local_reveal to Identity::Native alone will cause every live desktop Reveal click to fail with "Only the local workspace client may reveal a file.". Please restore Identity::Native | Identity::Remote { .. } (rejecting Agent / Background / BrowserLease) and update reveal_requires_native_client_and_local_workspace accordingly.

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 via file_parent + validate_inner(), and the remaining checks enforce canonical.parent() == Some(target.path.as_path()), !excluded_child, and policy.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。

@ARE404

ARE404 commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for clarifying the transport identity and the APFS case, @M4n5ter. Both are addressed in c5b2657. Reveal now accepts the local Workbench's Remote transport identity as well as Native, while still rejecting agent, background, and browser-lease callers. A different leaf spelling no longer causes a rejection by itself; the symlink, parent, exclusion, and read-policy checks remain in place.

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 M4n5ter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

English

LGTM — transport identity handling and cross-platform case-insensitive path checks look solid now.

简体中文

LGTM —— transport 身份放行和跨平台大小写不敏感路径校验现在都妥了。

@M4n5ter
M4n5ter merged commit adb66c7 into apache:main Dec 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants