fix(tui): restore attach command cwd auto-pass feature #324
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
shuvcode attachautomatically passes the client's current working directory to the server--dirpaths by early-returning when the directory doesn't exist locallyChanges
When no
--diris provided, the attach command now passesprocess.cwd()as the directory, ensuring file autocomplete, theme discovery, and exports use the client's directory when attaching to a remote server.Greptile Overview
Greptile Summary
This PR successfully restores a fork-specific feature where
shuvcode attachautomatically passes the client's current working directory to the server. The regression occurred during the upstream merge of PR anomalyco#8969 (commit8ebb76647), which added support for remote--dirpaths but inadvertently removed the automatic cwd passing when no--dirwas specified.Key changes:
--dirflag is provided, the attach command now passesprocess.cwd()as the directory parameter--diris provided but doesn't exist locally, the path is passed through to the server (for remote attach scenarios)--diris provided and exists locally, changes to that directory and passes it viaprocess.cwd()Impact:
Ensures that file autocomplete, theme discovery, and exports operate in the client's directory context when attaching to remote servers, rather than using the server's launch directory.
Confidence Score: 5/5
Important Files Changed
Sequence Diagram
sequenceDiagram participant CLI as CLI Client participant Handler as AttachCommand Handler participant FS as File System participant TUI as TUI (app.tsx) participant SDK as SDKProvider participant Server as OpenCode Server CLI->>Handler: attach <url> [--dir <path>] [--session <id>] alt --dir provided Handler->>FS: process.chdir(args.dir) alt chdir succeeds (local directory) FS-->>Handler: success Note over Handler: Directory changed locally Handler->>FS: process.cwd() FS-->>Handler: current working directory Handler->>TUI: tui({ url, sessionID, directory: cwd }) else chdir fails (remote directory) FS-->>Handler: throws error Note over Handler: Directory doesn't exist locally Handler->>TUI: tui({ url, sessionID, directory: args.dir }) Handler->>Handler: return early end else no --dir provided Handler->>FS: process.cwd() FS-->>Handler: current working directory Handler->>TUI: tui({ url, sessionID, directory: cwd }) end TUI->>SDK: Initialize SDK with directory SDK->>Server: API calls with x-opencode-directory header Note over Server: Uses client's directory for:<br/>- File autocomplete<br/>- Theme discovery<br/>- Exports Server-->>SDK: Responses SDK-->>TUI: Data TUI-->>CLI: Render interface