opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix: don't ask for permission for cd within project

Open a7medev opened this issue 2 days ago • 2 comments

What does this PR do?

Fixes #8192.

Fixes false permission requests when chained cd commands navigate within the project directory. Previously, commands like cd subdir && do something && cd .. would incorrectly trigger an external_directory permission request because all paths were resolved relative to the initial working directory rather than tracking the effective directory after each cd.

image

The fix tracks an effectiveCwd variable that updates after each cd command, so subsequent path resolutions use the correct context.

How did you verify your code works?

Added three tests in test/tool/bash.test.ts:

  • cd subdir && ls && cd .. does not request external_directory permission
  • cd a && cd b && cd c && cd .. && cd .. && cd .. (nested navigation) does not request permission
  • cd subdir && cd ../.. (actually escapes project) still correctly requests permission

Verified tests fail before the fix and pass after.


WIP: Not all combinations of commands are &&s, so cd shouldn't always change the effective working directory of the next command. We should instead use the AST provided by the tree-sitter and track the working directory along its paths.

a7medev avatar Jan 13 '26 10:01 a7medev