-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Problem
The shuvcode attach feature that automatically passes the client's current working directory (cwd) to the server via --dir has regressed. This was a fork-specific enhancement that ensured when attaching to a running server, the TUI operates in the directory where the client was launched, not where the server was started.
Current behavior (broken): When running shuvcode attach http://localhost:4096 from /home/user/project, the session operates in the server's launch directory.
Expected behavior: The session should operate in /home/user/project (the client's cwd).
Root Cause
The regression was introduced in commit dee022674 (upstream PR anomalyco#7150 "fix(tui): restore attach session lookup behavior") which changed:
// Before (our fix from 401b498c7)
const directory = process.cwd()
await tui({
url: args.url,
args: { sessionID: args.session },
directory,
})
// After (regressed)
await tui({
url: args.url,
args: { sessionID: args.session },
directory: args.dir ? process.cwd() : undefined,
})The change makes directory conditional on --dir being explicitly provided, when it should ALWAYS be process.cwd().
Acceptance Criteria
- When attaching without
--dir, the client'scwdis passed to the SDK viax-opencode-directoryheader - File autocomplete, theme discovery, and exports use the client's directory
- Sessions created via attach operate in the client's directory
Implementation
Restore the behavior from commit 401b498c7:
File: packages/opencode/src/cli/cmd/tui/attach.ts:23-29
handler: async (args) => {
if (args.dir) process.chdir(args.dir)
const directory = process.cwd() // Always capture cwd
await tui({
url: args.url,
args: { sessionID: args.session },
directory, // Always pass it
})
},Technical Context
The directory flows through:
attach.ts→ capturesprocess.cwd()app.tsx→ passesdirectoryprop toSDKProvidersdk.tsx→ passes tocreateOpencodeClient({ directory })client.ts→ setsx-opencode-directoryheader on all SDK requests
References
- Original fix:
401b498c7- PR #6715 - Regression commit:
dee022674- upstream PR fix(tui): restore attach session lookup behavior anomalyco/opencode#7150 - Fork feature doc: This should be documented in
script/sync/fork-features.jsonto prevent future regressions