feat(files-widget): browse outside the current working directory#37
feat(files-widget): browse outside the current working directory#37
Conversation
Resolves #34. - `u` re-roots the `/readfiles` browser to the parent directory - `.` jumps back to the starting directory - `/readfiles <path>` accepts an absolute, relative, or `~`-prefixed starting path and validates it up front - Header shows the current root (home-relative when possible) so you always know where you are - Re-rooting rebuilds git status, branch, diff stats, tree, and scan state cleanly, and reuses the existing safe-mode logic when jumping into `$HOME` or `/` - Comments on files outside the project cwd fall back to absolute paths so the agent can still locate them Manual tmux test covered: opening the project root, `u`/`.`, explicit path arg (absolute, relative, `~`-prefixed), invalid path error, git -> non-git transitions, no-op at filesystem root.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9492b4c8c1
ℹ️ 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".
| const relPath = normalizeGitPath(relative(rootPath, node.path)); | ||
| node.gitStatus = gitStatus.get(relPath); |
There was a problem hiding this comment.
Normalize git status keys to the selected root
loadRoot populates gitStatus/diffStats from git commands run in rootPath, but applyGitUpdates looks up those maps using relative(rootPath, node.path). For subdirectory roots this mismatches Git path semantics (for example, git -C app ls-files returns src/f.txt while git -C app status --porcelain reports app/src/f.txt), so modified files lose status/diff metadata and untracked handling can synthesize invalid nested paths. That means the new /readfiles <path> flow is incorrect when <path> is inside a git repo but not at its top-level root.
Useful? React with 👍 / 👎.
| stopBackgroundTasks(); | ||
| scanQueue.length = 0; |
There was a problem hiding this comment.
Cancel in-flight scan batches when re-rooting
setRoot stops timers and clears queues, but any already-running processScanBatch/processLineCountBatch continues after its awaited I/O and still mutates shared browser state. If a user re-roots with u or . while scanning is active, stale results from the previous root can be applied to the new root (polluting nodeByPath and tree stats). A root-generation or cancellation token check is needed before applying batch results.
Useful? React with 👍 / 👎.
Summary
Support browsing and searching outside the current working directory in
/readfiles. Resolves #34.Behavior
ure-roots the browser to the parent directory (no-op at/)..jumps back to the starting directory./readfiles <path>accepts an absolute, relative (to the agent's cwd), or~-prefixed starting path and validates it up front — invalid paths surface a clear error toast and keep the prior state.$HOMEor/.Implementation
createFileBrowsernow takesinitialPath+ optionalprojectCwd(default:initialPath).rootPathstate plusloadRoot(newRoot)/setRoot(newRoot)that stop background tasks, clear queues, and rebuild the tree.{ getRoot, projectCwd }so git/diff commands run against the current root while comment payloads stay anchored to the agent's cwd.u,., and the path argument.CHANGELOG.mdupdated under[Unreleased].Testing
tsc --noEmit --strict ...— no new errors introduced (remaining errors are pre-existing inmain).u, and.via a compiled Node script (all assertions passed).pirunning the modifiedindex.ts:/readfilesopens at the project root; header and footer help show the new keys.ure-roots to the parent dir; tree lists the original project as a subfolder.ueventually hits/and triggers[partial]safe-mode..returns to the initial project root./readfiles /some/absolute/pathopens that path (including a git repo with correct branch/diff stats)./readfiles ../siblingresolves the relative path against the agent's cwd./readfiles /nopesurfaces an error toast and keeps prior state.Credits: prompted by Pi Discord feedback from avg8888.