feat(cli): add --cwd flag to web and serve commands#7011
Open
temujin9 wants to merge 1 commit intoanomalyco:devfrom
Open
feat(cli): add --cwd flag to web and serve commands#7011temujin9 wants to merge 1 commit intoanomalyco:devfrom
temujin9 wants to merge 1 commit intoanomalyco:devfrom
Conversation
The web and serve commands did not preserve the working directory, causing process.cwd() to return an unexpected value (often '/') when the server handles requests. This resulted in sessions being created with worktree: '/' instead of the intended project directory. This change adds a --cwd flag to both commands, following the same pattern used by the TUI command (thread.ts) which correctly calls process.chdir() before starting the server. Fixes working directory detection for headless server modes.
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Duplicate PR Check ResultsNo duplicate PRs found. ✓ The search returned only PR #7011 (the current PR) when searching for variations of the Two related but distinct PRs were found that address similar directory/path issues in different contexts:
These are not duplicates of the current PR as they address different problems in different parts of the codebase. |
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.