feat(cli): add --cwd flag to web and serve commands #7011
+32
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
The
opencode webandopencode servecommands did not preserve the working directory, causingprocess.cwd()to return an unexpected value (often/) when the server handles requests. This resulted in sessions being created withworktree: "/"instead of the intended project directory.Changes
--cwdflag to bothwebandservecommandsprocess.chdir()before starting the server, following the same pattern used by the TUI command (thread.ts)Testing
--cwdoption appears in--helpoutput for both commandsRoot Cause
The server middleware in
server.ts(line 249) determines the directory per-request:Unlike the TUI command which calls
process.chdir(cwd)before starting, thewebandservecommands did not set the working directory, causing the fallback toprocess.cwd()to return an unintended value.