Skip to content

feat(sidebar): open workspace in the system file manager - #907

Merged
agegr merged 1 commit into
agegr:mainfrom
Xiaooi:feat/open-in-file-manager
Sep 30, 2026
Merged

agegr merged 1 commit into
agegr:mainfrom
Xiaooi:feat/open-in-file-manager

Conversation

@Xiaooi

@Xiaooi Xiaooi commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

What

Adds a button to the file explorer header (left of the terminal button) that opens the current session workspace in the OS file manager: Explorer on Windows, Finder on macOS, xdg-open elsewhere.

Why

Reviewing files the agent just wrote usually means reaching for the OS file manager. Until now the only way was to copy the path out of the app.

How

  • lib/open-in-file-manager.ts — platform to command mapping, loopback-host check, detached launch. explorer.exe can exit with code 1 even on success, so only spawn success counts.
  • app/api/open-in-explorer/route.ts — GET capability probe (supported / reason / platform) so the UI can label and disable the button; POST opens the folder. The path goes through the same allow-list as /api/terminal (getAllowedFileRoots() + isExistingFilePathAllowed()).
  • components/SessionSidebar.tsx — the button plus an inline, dismissible error line.
  • components/DismissButton.tsx — extracted from FileExplorer.tsx so both reuse it.
  • i18n keys for en / zh-CN / zh-TW.

The button is disabled when the request does not come from a loopback host, so a phone on the LAN does not raise a window on the server. That check is a usability guard, not access control — Host is client-controlled. The real boundaries are the default 127.0.0.1 bind and the path allow-list.

Testing

  • npx tsc --noEmit, npm run lint, npm test pass locally.
  • New unit tests: platform mapping, host classification, unsupported-platform rejection.
  • Manual verification on Windows: button renders left of the terminal button and opens Explorer at the session cwd; spoofed Host: 192.168.1.20 → 403; path outside the allow-list → 403; missing cwd → 400; failures stay visible until dismissed and clear on the next success.
  • Not verified: macOS open and Linux xdg-open (no machine available) — covered by unit tests only.

Adds a button left of the terminal button in the file explorer header that opens the current session workspace in Explorer (Windows), Finder (macOS), or xdg-open (Linux).

The path goes through the same allow-list as /api/terminal, and requests that do not come from a loopback host are refused so a phone on the LAN does not raise a window on the server. That host check is a usability guard, not access control: the real boundaries are the default 127.0.0.1 bind and the path allow-list.

agegr commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Thanks @Xiaooi, we're going with this one for #859. It's the narrow version we want: one button on the explorer root, directories only, the same allow-list as /api/terminal, spawn without a shell, and a loopback check that is honestly labeled as a usability guard. (#951 covered the same ground with extra surfaces and is closed in favor of this.)

Merged locally with current main (clean): tsc --noEmit, eslint, and the full unit suite (1328/1328) pass. LGTM 👍

Small follow-ups, none blocking:

  • POST runs stat() before the allow-list check, so a path outside the roots answers 400/500 instead of 403, which leaks whether it exists. isExistingFilePathAllowed() already requires the path to exist, so checking it first and then isDirectory() closes that.
  • AGENTS.md keeps a file map of every API route. app/api/open-in-explorer/route.ts should be added there.
  • On macOS, open <dir> launches an .app bundle instead of showing it. The UI only ever sends the explorer root, so this is fine as is, but it's worth a comment if the route ever takes other paths.
  • The new code's comments are in Chinese. The codebase mostly uses English.

Generated by Claude Code

@agegr
agegr merged commit a0c00f3 into agegr:main Sep 30, 2026
agegr added a commit that referenced this pull request Sep 30, 2026
* fix(open-in-explorer): authorize the path before looking at it

POST stat()ed the requested cwd before the allow-list check, so a path
outside the roots answered 400 (a file), 500 (missing) or 403 (a
directory) and told the caller whether it exists. Check the allow-list
first; isExistingFilePathAllowed() already requires the path to exist.

Also translate the new module's comments to English like the rest of the
codebase, note that macOS `open` launches .app bundles, and add the
route to the AGENTS.md file map.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q8e4GL1QSNFveKtnFfP3FZ

* refactor(subagents): share parseNpmSource through lib/npm-source

subagents.ts imported plugin-updates.ts only for parseNpmSource, which
pulled child_process, semver and the SDK package manager into the
session-reader import graph. Move the parser into a dependency-free
module that both use.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q8e4GL1QSNFveKtnFfP3FZ

* fix(chat): word the unanswered truncation notice for a full context too

A length stop with no answer is not always thinking's fault: pi clamps
the output to the room left in the context, so a nearly full context can
return nothing at all. Name both causes and drop the fixed "medium or
below" advice, which is wrong for sessions already on a low level.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q8e4GL1QSNFveKtnFfP3FZ

---------

Co-authored-by: Claude <[email protected]>
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
上游已合并的 agegr#884/agegr#871/agegr#996 我们已同步(代码与上游一致),agegr#892 已回退,
四行都不再是取舍信息,删掉;保留的都是上游仍未合并(我们领先)或被我们
拒绝的 PR。顺带修掉 agegr#907 的理由措辞:状态列里出现「已摘取」会让
scripts/prs.sh 把它误判成已摘取。
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
…#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 的其他入口另行收尾)。
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
上游只接受「资源管理器头部一个按钮」的窄版(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(含平台文案、远程/不支持时的置灰与错误提示)
保持不变。
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
agegr#967 / agegr#963 已由上游的 agegr#1009 / agegr#1008 落地,agegr#961 上游原样合并(逐字节相同),
agegr#951 已收敛到上游的 agegr#907,agegr#960 上下游都拒绝——这些都与上游一致,按台账规则删行。
agegr#899 上游关闭但本地保留,状态注明为永久分叉。
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
Adds a button left of the terminal button in the file explorer header that opens the current session workspace in Explorer (Windows), Finder (macOS), or xdg-open (Linux).

The path goes through the same allow-list as /api/terminal, and requests that do not come from a loopback host are refused so a phone on the LAN does not raise a window on the server. That host check is a usability guard, not access control: the real boundaries are the default 127.0.0.1 bind and the path allow-list.

Co-authored-by: xiao <[email protected]>
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
* fix(open-in-explorer): authorize the path before looking at it

POST stat()ed the requested cwd before the allow-list check, so a path
outside the roots answered 400 (a file), 500 (missing) or 403 (a
directory) and told the caller whether it exists. Check the allow-list
first; isExistingFilePathAllowed() already requires the path to exist.

Also translate the new module's comments to English like the rest of the
codebase, note that macOS `open` launches .app bundles, and add the
route to the AGENTS.md file map.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q8e4GL1QSNFveKtnFfP3FZ

* refactor(subagents): share parseNpmSource through lib/npm-source

subagents.ts imported plugin-updates.ts only for parseNpmSource, which
pulled child_process, semver and the SDK package manager into the
session-reader import graph. Move the parser into a dependency-free
module that both use.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q8e4GL1QSNFveKtnFfP3FZ

* fix(chat): word the unanswered truncation notice for a full context too

A length stop with no answer is not always thinking's fault: pi clamps
the output to the room left in the context, so a nearly full context can
return nothing at all. Name both causes and drop the fixed "medium or
below" advice, which is wrong for sessions already on a low level.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q8e4GL1QSNFveKtnFfP3FZ

---------

Co-authored-by: Claude <[email protected]>
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
Adds a button left of the terminal button in the file explorer header that opens the current session workspace in Explorer (Windows), Finder (macOS), or xdg-open (Linux).

The path goes through the same allow-list as /api/terminal, and requests that do not come from a loopback host are refused so a phone on the LAN does not raise a window on the server. That host check is a usability guard, not access control: the real boundaries are the default 127.0.0.1 bind and the path allow-list.

Co-authored-by: xiao <[email protected]>
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
* fix(open-in-explorer): authorize the path before looking at it

POST stat()ed the requested cwd before the allow-list check, so a path
outside the roots answered 400 (a file), 500 (missing) or 403 (a
directory) and told the caller whether it exists. Check the allow-list
first; isExistingFilePathAllowed() already requires the path to exist.

Also translate the new module's comments to English like the rest of the
codebase, note that macOS `open` launches .app bundles, and add the
route to the AGENTS.md file map.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q8e4GL1QSNFveKtnFfP3FZ

* refactor(subagents): share parseNpmSource through lib/npm-source

subagents.ts imported plugin-updates.ts only for parseNpmSource, which
pulled child_process, semver and the SDK package manager into the
session-reader import graph. Move the parser into a dependency-free
module that both use.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q8e4GL1QSNFveKtnFfP3FZ

* fix(chat): word the unanswered truncation notice for a full context too

A length stop with no answer is not always thinking's fault: pi clamps
the output to the room left in the context, so a nearly full context can
return nothing at all. Name both causes and drop the fixed "medium or
below" advice, which is wrong for sessions already on a low level.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q8e4GL1QSNFveKtnFfP3FZ

---------

Co-authored-by: Claude <[email protected]>
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