Skip to content

feat(tui): inherit session directory when creating a new session - #39753

Merged
kitlangton merged 1 commit into
v2from
v2-home-cd
Jul 31, 2026
Merged

feat(tui): inherit session directory when creating a new session#39753
kitlangton merged 1 commit into
v2from
v2-home-cd

Conversation

@kitlangton

@kitlangton kitlangton commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

What

In the V2 TUI, /new always 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 ~/b under the prompt and the session is created in ~/b. /cd on 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), /cd updates it, session.create reads it. No parallel staging state.

  • context/location.tsx — the provider exposes ref (the target location as set) alongside current (the server-synced info), so creation and display can honor a location before its sync completes.
  • app.tsxsession.new passes the active session's location when navigating home.
  • component/prompt/index.tsxsession.create falls back to currentLocation.ref instead of data.location.default(); /cd before 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 calls location.set inside untrack: location.set reads 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 — documents HomeRoute.location as 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 })
Loading

Scope

  • /move's "new working copy" staging is untouched and still takes precedence at submit when explicitly selected.
  • Error-path navigations to home (session not found) intentionally do not carry a location.
  • Closing the last session tab lands on home with the launch cwd (deliberate: closing is a "done" gesture, not a "continue" gesture).
  • No changes to the desktop app, which already inherits the active tab's directory.

Testing

  • bun typecheck and bun test in packages/tui (573 pass).
  • End-to-end against a hermetic serve instance with termctrl, verified via the server API: launched the TUI in project A with a session in project B; /new showed B on home and created the next session in B; /cd after /new updated 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, /new inherits it and the label shows it, new session created there, then /new + /cd overrides back to newtab-a.

newtab-demo2.mp4

@kitlangton
kitlangton merged commit a460f02 into v2 Jul 31, 2026
10 checks passed
@kitlangton
kitlangton deleted the v2-home-cd branch July 31, 2026 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant