Repository navigation
Conversation
Add POST /api/open-folder, which authorizes the target against the same file-access allow-list as /api/files and /api/terminal, then launches explorer.exe / open / xdg-open without a shell. A directory opens as-is; a file is revealed with its entry selected (explorer.exe /select, on Windows, open -R on macOS). Wire it up in three places: - a folder button in the sidebar explorer toolbar, next to the terminal button, opening the selected project folder - a folder button in every file-viewer header, revealing the open file - inline-code paths in replies become chips: clicking the path keeps opening the in-app viewer (a directory falls back to opening the folder, which cannot be previewed), and the folder icon reveals the path on disk windowsHide stays false on Windows: SW_HIDE inherited from STARTUPINFO suppresses the Explorer window even though explorer.exe is a GUI app.
533d7fa to
ab4f60e
Compare
|
感谢这个 PR —— #859 的诉求基本都覆盖了,细节也做得扎实(复用 我这边还有一个场景没被覆盖:文件树本身没有入口。
我的用法正是"在树里看到这个目录/文件,就想直接交给资源管理器"(用原生程序改文件、拖拽、复制真实路径)。 树行上其实已经有现成的模式可以复用: 顺便两个小点:
再次感谢。 |
|
Thanks @planb788, the write-up is excellent, including the The two extra surfaces are where it goes beyond what we want Pi Web to carry:
If #907 lands and a "reveal this file" action still feels missing in practice, a small follow-up on top of it can be discussed in an issue. Generated by Claude Code |
…#907 agegr#941 agegr#946 agegr#961 agegr#968 agegr#969 agegr#1007 agegr#1008 agegr#1009 agegr#1010) 上游已把我们提前摘取的 agegr#884 / agegr#871 / agegr#996 / agegr#961 原样合并(agegr#961 逐字节相同), agegr#967 与 agegr#963 由上游的 agegr#1009 / agegr#1008 接管。 冲突解决: - demo/ 对齐上游 fe288c0,撤销 agegr#963 对 demo 的两处改动(`@/lib/chat-phase-label` 在 demo/lib 下不存在,会打断 Pages 构建)。 - AGENTS.md:保留我们的 default-project 条目,open-folder 换成上游的 open-in-explorer。 - MessageView.tsx / SessionSidebar.tsx / FileExplorer.tsx:以上游为准, DismissButton 采用上游的独立文件,保留我们的思考卡片与文件管理改动。 - SessionSidebar 移除引用已删函数的旧 agegr#951 工作区按钮(agegr#951 的其他入口另行收尾)。
上游只接受「资源管理器头部一个按钮」的窄版(agegr#907 / a0c00f3,含 agegr#1010 的收尾), 并以「超出薄前端范围」关闭了我们的宽版 agegr#951,因此移除 agegr#951 的两个额外入口: - 聊天回复里行内代码路径的 chip(MarkdownBody.tsx 还原上游版本, lib/file-links.ts、MarkdownBody.test.mjs、file-links.test.mjs 与 app/globals.css 的样式一并还原) - 文件查看器头部的「在资源管理器中显示」按钮 同时删除只服务于它们的模块:/api/open-folder、lib/open-folder.ts、 lib/path-actions.ts、hooks/useLocalFileManager.ts、lib/loopback-host.ts, 以及两条只被它们使用的 i18n 文案。上游的 /api/open-in-explorer + lib/open-in-file-manager.ts(含平台文案、远程/不支持时的置灰与错误提示) 保持不变。
agegr#967 / agegr#963 已由上游的 agegr#1009 / agegr#1008 落地,agegr#961 上游原样合并(逐字节相同), agegr#951 已收敛到上游的 agegr#907,agegr#960 上下游都拒绝——这些都与上游一致,按台账规则删行。 agegr#899 上游关闭但本地保留,状态注明为永久分叉。
What
Adds
POST /api/open-folder, which opens a path in the OS file manager(Explorer / Finder / xdg-open), and wires it into three places in the UI.
Why
Pi Web can already preview a file in a tab, but a browser cannot navigate to a
file://URL, so there was no way to jump from the app to the folder on disk.Note that this is not a browser capability: #206 was closed with "the web has
no reveal capability", which is true for a plain page — but Pi Web is a local
server, so a route handler can launch the file manager itself. The path is
gated by the same allow-list as
/api/files, and the request has to come fromthis machine (see below).
How
Route —
app/api/open-folder/route.tsPOST { path };statfirst (400 when missing), then authorizes against thesame allow-list as
/api/filesand/api/terminal(
getAllowedFileRoots+isExistingFilePathAllowed, 403 when outside).(403 otherwise), so a phone or another computer on the LAN cannot raise
windows on the host.
Hostis client-controlled, so this is a usabilityguard, not access control — the real boundaries stay the loopback bind and
the path allow-list.
stdio: "ignore", and resolves on thespawnevent so a launch failure becomes a 500 instead of a falseok.Commands —
lib/open-folder.tsopenFolderCommand:explorer.exe <dir>/open <dir>/xdg-open <dir>revealFileCommand:explorer.exe /select,<file>/open -R <file>/xdg-open <parent>(xdg-open has no portable "select this entry" flag)isLoopbackHost: host classification for the guard above.UI
components/SessionSidebar.tsx— folder button in the explorer toolbar, nextto the terminal button, opening the selected project folder.
components/FileViewer.tsx+components/RevealInFileManagerButton.tsx—reveal button in all five viewer headers (hidden for deleted diffs). The icon
is the file tree's own folder icon.
components/MarkdownBody.tsx+lib/file-links.ts— an inline-code span thatis unambiguously a path becomes a chip. Clicking the path keeps the existing
in-app preview; a directory (which
/api/filescannot serve) falls back toopening the folder. The folder icon in the chip reveals it on disk.
Relationship to existing issues and PRs
in the OS file manager, with explicit behavior in unsupported environments).
The 403 above plus the button's tooltip is that explicit behavior.
superset of it: the same sidebar button, plus a reveal button in the file
viewer and path chips in replies, on a shared route + platform helpers.
Happy to drop either of the two extra surfaces, or to consolidate with feat(sidebar): open workspace in the system file manager #907
in whichever direction you prefer — the route and the command helpers are the
part that has to exist either way.
deliberately does none of that: it only opens locations in the OS file
manager, and writes nothing.
Notes
windowsHidemust stayfalse:SW_HIDEinherited fromSTARTUPINFOsuppresses the Explorer window even though
explorer.exeis a GUI app. Thiswas verified by enumerating top-level windows before/after the spawn.
often prose than a path: a single token that is either rooted (drive letter,
UNC,
/…) or slash-separated with a file-looking tail.npm test,application/json,read/write,Node.js,v0.9.2,--flagand URLs stayplain code, and a relative path that would escape the message cwd is ignored.
en,zh-CN,zh-TW.demo/is intentionally not updated here: it keeps its owncopies with Pages-specific changes. Happy to sync it in a follow-up PR.
Tests
lib/open-folder.test.mjs— pure command builder for all platforms, plusloopback host classification (
127.0.0.1,localhost,[::1],::1vs.LAN IPs and lookalike domains such as
127.0.0.1.evil.com).app/api/open-folder/route.test.mjs— validation paths only (400 / 403,including a non-loopback request); tests never spawn a real file manager.
lib/path-actions.test.mjs— probe + reveal against a stubbedfetch.lib/file-links.test.mjs— inline-code detection, including prose negativesand cwd-escape cases.
components/MarkdownBody.test.mjs— chip rendering, prose stays code, codenested in a link is untouched.
tsc --noEmitandeslint .are clean. The full suite matchesmainapart fromthe pre-existing Windows-only failures (symlink / pty / git) that are present
without this change.
Manually verified on Windows: opening a folder, revealing a file (window opens
with the entry selected), a path outside the allow-list returning 403, and a
spoofed non-loopback
Hostreturning 403 without opening anything.