fix(tui): support cd before session creation (#39555)

This commit is contained in:
Kit Langton 2026-07-29 14:45:42 -04:00 committed by GitHub
parent f7ea2fc346
commit 4f871906bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 3 deletions

View file

@ -216,19 +216,34 @@ export function Prompt(props: PromptProps) {
})
Keymap.createLayer(() => ({
mode: "global",
enabled: props.sessionID !== undefined,
commands: [
{
id: "session.cd",
title: "Change working directory",
slash: { name: "cd", arguments: true },
run: async (input) => {
const sessionID = props.sessionID
if (!sessionID) return
if (!input?.trim()) {
toast.show({ message: "Directory is required", variant: "error" })
return
}
const sessionID = props.sessionID
if (!sessionID) {
const value = input.trim()
const expanded =
value === "~" ? paths.home : value.startsWith("~/") ? path.join(paths.home, value.slice(2)) : value
const directory = path.resolve(
currentLocation.current?.directory ?? data.location.default().directory,
expanded,
)
const location = await client.api.location.get({ location: { directory } }).catch((error) => {
toast.show({ title: "Failed to change directory", message: errorMessage(error), variant: "error" })
return undefined
})
if (!location) return
move.setDirectory(location.directory, location.directory !== location.project.directory)
currentLocation.set(location)
return
}
await client.api.session
.move({ sessionID, directory: input })
.catch((error) =>

View file

@ -158,6 +158,10 @@ export function usePromptMove(input: { projectID: () => string | undefined; sess
setCreating(false)
}
function setDirectory(directory: string, subdirectory: boolean) {
setDestination({ type: "directory", directory, subdirectory })
}
createEffect(() => {
if (!creating()) {
setCreatingDots(3)
@ -176,6 +180,7 @@ export function usePromptMove(input: { projectID: () => string | undefined; sess
pending,
pendingNew,
progress,
setDirectory,
startSubmit,
}
}