feat: editable explorer root path input + outside-cwd preview allowance - #84
feat: editable explorer root path input + outside-cwd preview allowance#84NolanHo wants to merge 1 commit into
Conversation
The explorer header root label becomes an editable input: submitting a directory roots the tree at it, submitting a file roots at its parent directory (new host fs.resolve route); relative inputs join the current root. The override lives in the per-session state (persisted, expansion reset on switch). Media/HTML previews and downloads outside the session cwd are allowed by default under roots fs.resolve confirmed for the session (capped at 16), gated by the explorerOutsideCwdPreview side-card toggle.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
@codex Do CR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c591c9633a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| api.fsResolve({ sessionId, cwd }, text, root).then((result) => { | ||
| setResolvingRoot(false) | ||
| setEditingRoot(false) | ||
| setRootError(null) | ||
| // A same-root submit never collapses the tree (the reducer no-ops). | ||
| if (result.root !== root) applyRoot(result.root) |
There was a problem hiding this comment.
Apply resolved roots to the originating session
If fs.resolve is still pending when the user switches conversations, the explorer component can be reused because tabs are keyed only by tab.id, while this completion calls store.reduce() against whichever session is currently active. A response initiated in session A can therefore persist its root into session B, and the shared edit/error state can also update B's view. Capture the initiating session and use a session-targeted update, or cancel/ignore the completion when sessionId changes.
Useful? React with 👍 / 👎.
| if (root === undefined) return | ||
| if (lastRootRef.current !== root) { | ||
| lastRootRef.current = root | ||
| dataRef.current = {} | ||
| setData({}) | ||
| } | ||
| loadDir(root) |
There was a problem hiding this comment.
Reapprove persisted roots after host restart
When explorerRoot is restored from localStorage after the host or plugin restarts, the host's approvedRoots map is newly empty, but this effect loads the persisted root only through fs.tree. The tree consequently works while image/PDF/HTML previews and downloads beneath that outside-cwd root return 403 until the user manually resubmits the same path through fs.resolve. Revalidate/reapprove a restored override before loading it.
Useful? React with 👍 / 👎.
改什么
资源管理器顶部的根路径标签变为可编辑输入框:
/sidebar/api/fs.resolve,stat判定)SidebarState.explorerRoot),切换根时重置展开集并清空层级缓存;同根重提交不折叠树cwd 外预览/下载默认放行(可开关):
/sidebar/file(图片/PDF/下载)与/sidebar/html原先受isWithin(cwd)限制,根切到 cwd 外后预览 403fs.resolve确认过的根目录记入 per-session 已批准目录注册表(上限 16,按最近使用淘汰);media/html 路由放行cwd ∪ 已批准根内的路径——只对用户在资源管理器里显式确认过的目录放开,不放任意路径explorerOutsideCwdPreview(默认开,schema/默认值/客户端解析/声明式设置 UI 全链路);关闭后立即恢复严格 cwd 围栏(每次请求读当前设置);cwd 内文件不受影响;文本打开(fs.read)不受影响为什么
原实现 root 固定为会话 cwd,无法在侧边栏里浏览其它目录;放开后图片/PDF/HTML 预览与下载却因 media/html 路由的 cwd 围栏而 403,体验断裂。本 PR 用「用户确认过的根目录」作为放行边界,兼顾完整性与安全面(不放任意客户端声称的路径,仍受浏览器信任栅栏保护)。
影响范围
fs.resolve新路由、已批准根注册表、media/html 路由门禁改由isPathServable判定(含新偏好读取)explorerRoot状态、侧边卡片新开关验收与证据
fs.resolve路由(目录/文件/相对/缺失/非法 base)、批准放行与 403 边界、开关实时 200↔403、无 settings 服务默认开、16 上限淘汰、sanitize/parsePrefs/内置开关声明断言、ExplorerView 9 个 jsdom 交互用例(含 resolve 中不 disable 的回归钉)bundle-route的 /tmp mtime 粒度 flaky,与本 PR 无关——已用 stash 对照确认);typecheck / build / check-consumer-types / diff-check 全绿备注
explorerOutsideCwdPreview)What
The explorer header root label becomes an editable input: entering a directory roots the tree at it, entering a file roots at its parent directory (new
fs.resolvehost route); relative inputs join the current root; the override is per-session persisted. Previews/downloads outside the session cwd are now allowed by default under roots the explorer confirmed per session (capped at 16), gated by a newexplorerOutsideCwdPreviewside-card toggle (live, default on).Why
The explorer root was fixed to the session cwd, and the media/HTML routes' strict cwd fence made outside-cwd previews 403 right after switching roots. Approving only user-confirmed roots keeps the byte-serving surface bounded while the feature stays coherent.
Verification
/tmpmtime flake in bundle-route.spec is intermittent, confirmed unrelated via stash control); typecheck/build/check-consumer-types clean.