feat(tui): inherit session directory when creating a new session - #39753
Merged
Conversation
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.
What
In the V2 TUI,
/newalways created the next session in the directory the TUI was launched from, even when the current session lived in a different project. Now the home route inherits the previous session's location — matching the desktop app's new-tab behavior — and the label under the prompt always shows where the next session will be created.Before: launch in
~/a, open a session in~/b, hit/new, submit → session created in~/a, with no indication anywhere.After: same steps → home shows
~/bunder the prompt and the session is created in~/b./cdon home overrides it (and the label updates), and a plain launch keeps using the launch cwd.This also fixes the open menu / project picker: it already navigated home with
route.location, but the next session was still created in the launch cwd.How
The design principle: the location context is where the next session is created. Home seeds it (launch cwd, inherited session location, or picked project),
/cdupdates it,session.createreads it. No parallel staging state.context/location.tsx— the provider exposesref(the target location as set) alongsidecurrent(the server-synced info), so creation and display can honor a location before its sync completes.app.tsx—session.newpasses the active session'slocationwhen navigating home.component/prompt/index.tsx—session.createfalls back tocurrentLocation.refinstead ofdata.location.default();/cdbefore a session exists now only sets the context (its extra move-staging call is gone); the under-prompt location label always renders on home.routes/home.tsx— the seeding effect tracks only the route location (and, when absent, the default) and callslocation.setinsideuntrack:location.setreads other signals internally, and tracking them re-asserted the route location after a user/cd, silently changing where the session would be created.context/route.tsx— documentsHomeRoute.locationas the carried-over location.Flow
sequenceDiagram participant S as Session route (~/b) participant H as Home route participant L as Location context participant P as Prompt participant API as Server S->>H: /new — navigate({ type: "home", location: session.location }) H->>L: location.set({ directory: "~/b" }) Note over P: label shows ~/b opt user overrides P->>L: /cd ~/elsewhere — location.set(...) Note over P: label shows ~/elsewhere end P->>API: session.create({ location: currentLocation.ref })Scope
/move's "new working copy" staging is untouched and still takes precedence at submit when explicitly selected.Testing
bun typecheckandbun testinpackages/tui(573 pass).serveinstance withtermctrl, verified via the server API: launched the TUI in project A with a session in project B;/newshowed B on home and created the next session in B;/cdafter/newupdated the label and created in A instead; plain launch kept the cwd.Demo
Real end-to-end run (hermetic server, real TUI): session in
newtab-b,/newinherits it and the label shows it, new session created there, then/new+/cdoverrides back tonewtab-a.newtab-demo2.mp4