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

This commit is contained in:
Kit Langton 2026-07-30 20:31:38 -04:00 committed by GitHub
commit a460f02f67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 25 additions and 5 deletions

View file

@ -646,6 +646,7 @@ function App(props: { pair?: DialogPairCredentials }) {
run: () => { run: () => {
route.navigate({ route.navigate({
type: "home", type: "home",
location: route.data.type === "session" ? data.session.get(route.data.sessionID)?.location : undefined,
}) })
dialog.clear() dialog.clear()
}, },

View file

@ -240,7 +240,6 @@ export function Prompt(props: PromptProps) {
return undefined return undefined
}) })
if (!location) return if (!location) return
move.setDirectory(location.directory, location.directory !== location.project.directory)
currentLocation.set(location) currentLocation.set(location)
return return
} }
@ -963,7 +962,10 @@ export function Prompt(props: PromptProps) {
const directory = await move.getDirectory() const directory = await move.getDirectory()
if (move.pending() && !directory) return false if (move.pending() && !directory) return false
finishMoveProgress = Boolean(move.progress()) finishMoveProgress = Boolean(move.progress())
const location = data.location.default() // The location context is where the next session is created: seeded by the home
// route (launch cwd, inherited session location, or picked project) and updated
// by /cd before a session exists.
const location = currentLocation.ref ?? data.location.default()
const created = await client.api.session const created = await client.api.session
.create({ .create({
@ -1299,7 +1301,12 @@ export function Prompt(props: PromptProps) {
return `Ask anything... "${list()[store.placeholder % list().length]}"` return `Ask anything... "${list()[store.placeholder % list().length]}"`
}) })
const locationLabel = createMemo(() => { const locationLabel = createMemo(() => {
if (!props.sessionID || status() !== "idle") return if (!props.sessionID) {
// No session yet: show where the next session will be created.
const directory = currentLocation.ref?.directory ?? data.location.default().directory
return abbreviateHome(directory, paths.home)
}
if (status() !== "idle") return
const directory = data.session.get(props.sessionID)?.location.directory const directory = data.session.get(props.sessionID)?.location.directory
return directory ? abbreviateHome(directory, paths.home) : undefined return directory ? abbreviateHome(directory, paths.home) : undefined
}) })

View file

@ -5,6 +5,8 @@ import { useData } from "./data"
const context = createContext<{ const context = createContext<{
readonly current: LocationGetOutput | undefined readonly current: LocationGetOutput | undefined
// The target location as set, available before the server-synced info in `current` arrives.
readonly ref: LocationRef | undefined
set: (location?: LocationRef) => void set: (location?: LocationRef) => void
}>() }>()
@ -37,6 +39,9 @@ export function LocationProvider(props: ParentProps) {
get current() { get current() {
return current() return current()
}, },
get ref() {
return ref()
},
set, set,
}} }}
> >

View file

@ -7,6 +7,7 @@ import { useTuiStartup } from "./runtime"
export type HomeRoute = { export type HomeRoute = {
type: "home" type: "home"
prompt?: PromptInfo prompt?: PromptInfo
// Location carried over from the previous session or project picker so a new session lands there.
location?: LocationRef location?: LocationRef
} }

View file

@ -1,5 +1,5 @@
import { Prompt, type PromptRef } from "../component/prompt" import { Prompt, type PromptRef } from "../component/prompt"
import { createEffect, createMemo, createSignal, onMount, Show } from "solid-js" import { createEffect, createMemo, createSignal, onMount, Show, untrack } from "solid-js"
import { Logo } from "../component/logo" import { Logo } from "../component/logo"
import { useArgs } from "../context/args" import { useArgs } from "../context/args"
import { useRouteData } from "../context/route" import { useRouteData } from "../context/route"
@ -31,7 +31,13 @@ export function Home() {
const forms = createMemo(() => data.session.form.list("global", currentLocation()) ?? []) const forms = createMemo(() => data.session.form.list("global", currentLocation()) ?? [])
let sent = false let sent = false
createEffect(() => location.set(currentLocation())) // Track only the route location and (when absent) the default location; location.set
// reads other signals internally and tracking them would re-assert the route location
// after the user overrides it with /cd.
createEffect(() => {
const target = currentLocation()
untrack(() => location.set(target))
})
onMount(() => { onMount(() => {
editor.clearSelection() editor.clearSelection()