Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions packages/opencode/src/cli/cmd/tui/component/prompt/move.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import { DialogMoveSession, type MoveSessionSelection } from "../dialog-move-ses
import { DialogWorkspaceFileChanges } from "../dialog-workspace-file-changes"
import { useHomeSessionDestination } from "../../routes/home/session-destination"

function moveReminderText(directory: string) {
return `<system-reminder>The user has changed the current working directory to "${directory}". This is still the same project but at a possibly new location; take this into account when working with any files from now on.</system-reminder>`
}

export function usePromptMove(input: { projectID: () => string | undefined; sessionID: () => string | undefined }) {
const dialog = useDialog()
const sdk = useSDK()
Expand Down Expand Up @@ -93,24 +97,37 @@ export function usePromptMove(input: { projectID: () => string | undefined; sess
return
}
setProgress("Moving session")
await sdk.client.experimental.controlPlane
.moveSession(
try {
await sdk.client.experimental.controlPlane.moveSession(
{
sessionID,
destination: { directory },
moveChanges: choice === "yes",
},
{ throwOnError: true },
)
.then(() => dialog.clear())
.catch((error) => {
toast.error(error)
dialog.clear()
})
.finally(() => {
setProgress(undefined)
setCreating(false)
})
await sdk.client.session
.promptAsync({
sessionID,
directory,
noReply: true,
parts: [
{
type: "text",
text: moveReminderText(directory),
synthetic: true,
},
],
})
.catch(() => undefined)
dialog.clear()
} catch (error) {
toast.error(error)
dialog.clear()
} finally {
setProgress(undefined)
setCreating(false)
}
}

const pending = createMemo(() => Boolean(homeDestination?.destination()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ function message(error: MoveSession.Error) {
if (error instanceof SessionV2.NotFoundError) return `Session not found: ${error.sessionID}`
if (error instanceof MoveSession.DestinationProjectMismatchError)
return "Destination directory belongs to another project"
if (error instanceof MoveSession.ApplyChangesError)
return `Unable to apply your changes in the destination directory. The files may conflict with existing changes.`
return error.message
}
Loading