Skip to content

feat(files-widget): browse outside the current working directory#37

Open
tmustier wants to merge 1 commit intomainfrom
feat/files-widget-outside-cwd
Open

feat(files-widget): browse outside the current working directory#37
tmustier wants to merge 1 commit intomainfrom
feat/files-widget-outside-cwd

Conversation

@tmustier
Copy link
Copy Markdown
Owner

Summary

Support browsing and searching outside the current working directory in /readfiles. Resolves #34.

Behavior

  • u re-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.
  • The browser header shows the current root (home-relative when possible) so you can see where you are at a glance.
  • Re-rooting rebuilds git status, branch, diff stats, the tree, and scan state cleanly. Existing safe-mode behavior is preserved when re-rooting to $HOME or /.
  • Comments on files outside the project cwd fall back to absolute paths so the agent can still find them. Files inside the project continue to use project-relative paths.

Implementation

  • createFileBrowser now takes initialPath + optional projectCwd (default: initialPath).
  • Introduced internal mutable rootPath state plus loadRoot(newRoot) / setRoot(newRoot) that stop background tasks, clear queues, and rebuild the tree.
  • Viewer constructor now takes a config object { getRoot, projectCwd } so git/diff commands run against the current root while comment payloads stay anchored to the agent's cwd.
  • Help footer and README updated to document u, ., and the path argument.
  • CHANGELOG.md updated under [Unreleased].

Testing

  • Typecheck: tsc --noEmit --strict ... — no new errors introduced (remaining errors are pre-existing in main).
  • Targeted smoke test exercising initial render, u, and . via a compiled Node script (all assertions passed).
  • Manual tmux test with real pi running the modified index.ts:
    • /readfiles opens at the project root; header and footer help show the new keys.
    • u re-roots to the parent dir; tree lists the original project as a subfolder.
    • Continuing to press u eventually hits / and triggers [partial] safe-mode.
    • . returns to the initial project root.
    • /readfiles /some/absolute/path opens that path (including a git repo with correct branch/diff stats).
    • /readfiles ../sibling resolves the relative path against the agent's cwd.
    • /readfiles /nope surfaces an error toast and keeps prior state.
    • Git → non-git transitions show the correct root header, scan behavior, and stats.

Credits: prompted by Pi Discord feedback from avg8888.

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.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment thread files-widget/browser.ts
Comment on lines +584 to 585
const relPath = normalizeGitPath(relative(rootPath, node.path));
node.gitStatus = gitStatus.get(relPath);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment thread files-widget/browser.ts
Comment on lines +783 to +784
stopBackgroundTasks();
scanQueue.length = 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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.

files-widget: support browsing/searching outside the current working directory

1 participant