diff --git a/packages/tui/src/component/prompt/index.tsx b/packages/tui/src/component/prompt/index.tsx index 732359a4a75..2d554a49b15 100644 --- a/packages/tui/src/component/prompt/index.tsx +++ b/packages/tui/src/component/prompt/index.tsx @@ -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) => diff --git a/packages/tui/src/component/prompt/move.tsx b/packages/tui/src/component/prompt/move.tsx index 7b99d80167d..e7d420cd1b2 100644 --- a/packages/tui/src/component/prompt/move.tsx +++ b/packages/tui/src/component/prompt/move.tsx @@ -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, } }