diff --git a/backend/src/services/repo.ts b/backend/src/services/repo.ts index c7c5f706..64db47f4 100644 --- a/backend/src/services/repo.ts +++ b/backend/src/services/repo.ts @@ -607,9 +607,10 @@ function normalizeRepoUrl(url: string): { url: string; name: string } { const sshMatch = url.match(/^git@([^:]+):(.+?)(?:\.git)?$/) if (sshMatch) { const [, host, pathPart] = sshMatch - const repoName = pathPart.split('/').pop() || `repo-${Date.now()}` + const path = pathPart ?? '' + const repoName = path.split('/').pop() || `repo-${Date.now()}` return { - url: `https://${host}/${pathPart.replace(/\.git$/, '')}`, + url: `https://${host}/${path.replace(/\.git$/, '')}`, name: repoName } } @@ -619,7 +620,7 @@ function normalizeRepoUrl(url: string): { url: string; name: string } { const [, owner, repoName] = shorthandMatch return { url: `https://github.com/${owner}/${repoName}`, - name: repoName + name: repoName ?? `repo-${Date.now()}` } } diff --git a/frontend/src/components/message/EditableUserMessage.tsx b/frontend/src/components/message/EditableUserMessage.tsx index 5fc3f716..43de5ec3 100644 --- a/frontend/src/components/message/EditableUserMessage.tsx +++ b/frontend/src/components/message/EditableUserMessage.tsx @@ -3,6 +3,7 @@ import { Send, X, Pencil, Loader2 } from 'lucide-react' import { useRefreshMessage } from '@/hooks/useRemoveMessage' import { useUIState } from '@/stores/uiStateStore' import { useMobile } from '@/hooks/useMobile' +import { useSessionAgent } from '@/hooks/useSessionAgent' interface EditableUserMessageProps { opcodeUrl: string @@ -12,7 +13,6 @@ interface EditableUserMessageProps { assistantMessageId: string onCancel: () => void model?: string - agent?: string } export const EditableUserMessage = memo(function EditableUserMessage({ @@ -22,14 +22,15 @@ export const EditableUserMessage = memo(function EditableUserMessage({ content, assistantMessageId, onCancel, - model, - agent + model }: EditableUserMessageProps) { const [editedContent, setEditedContent] = useState(content) const textareaRef = useRef(null) const isMobile = useMobile() const refreshMessage = useRefreshMessage({ opcodeUrl, sessionId, directory }) const setIsEditingMessage = useUIState((state) => state.setIsEditingMessage) + const sessionAgent = useSessionAgent(opcodeUrl, sessionId, directory) + const currentMode = sessionAgent.agent useEffect(() => { if (textareaRef.current) { @@ -61,7 +62,7 @@ export const EditableUserMessage = memo(function EditableUserMessage({ assistantMessageID: assistantMessageId, userMessageContent: editedContent.trim(), model, - agent + agent: currentMode }, { onSuccess: () => { onCancel() diff --git a/frontend/src/components/message/MessageThread.tsx b/frontend/src/components/message/MessageThread.tsx index 41e1267f..aae0d826 100644 --- a/frontend/src/components/message/MessageThread.tsx +++ b/frontend/src/components/message/MessageThread.tsx @@ -29,7 +29,6 @@ interface MessageThreadProps { onChildSessionClick?: (sessionId: string) => void onUndoMessage?: (restoredPrompt: string) => void model?: string - agent?: string } const isMessageStreaming = (msg: MessageWithParts): boolean => { @@ -70,8 +69,7 @@ export const MessageThread = memo(function MessageThread({ onFileClick, onChildSessionClick, onUndoMessage, - model, - agent + model }: MessageThreadProps) { const [editingUserMessageId, setEditingUserMessageId] = useState(null) const [editingForAssistantId, setEditingForAssistantId] = useState(null) @@ -229,7 +227,6 @@ const state = latestTodoPart.state assistantMessageId={editingForAssistantId} onCancel={handleCancelEdit} model={model} - agent={agent} /> ) : msg.info.role === 'user' && canEditUserMessage && nextAssistantMessage ? ( (funct const [selectedMentionIndex, setSelectedMentionIndex] = useState(0) const [selectedCommandIndex, setSelectedCommandIndex] = useState(0) const [selectedAgent, setSelectedAgent] = useState(null) + const [localMode, setLocalMode] = useState(null) const [isFocused, setIsFocused] = useState(false) const textareaRef = useRef(null) @@ -121,7 +122,6 @@ export const PromptInput = forwardRef(funct const sendShell = useSendShell(opcodeUrl, directory) const abortSession = useAbortSession(opcodeUrl, directory, sessionID) const { data: messages } = useMessages(opcodeUrl, sessionID, directory) - const { preferences, updateSettings } = useSettings() const { filterCommands } = useCommands(opcodeUrl) const { executeCommand } = useCommandHandler({ opcodeUrl, @@ -348,7 +348,7 @@ export const PromptInput = forwardRef(funct const handleModeToggle = () => { const newMode = currentMode === 'plan' ? 'build' : 'plan' - updateSettings({ mode: newMode }) + setLocalMode(newMode) } const addImageAttachment = (file: File) => { @@ -680,7 +680,8 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read) const lastAssistantMessage = messages?.filter(msg => msg.info.role === 'assistant').at(-1) const hasIncompleteMessages = lastAssistantMessage ? isMessageIncomplete(lastAssistantMessage) : false - const currentMode = preferences?.mode || 'build' + const sessionAgent = useSessionAgent(opcodeUrl, sessionID, directory) + const currentMode = localMode ?? sessionAgent.agent const modeColor = currentMode === 'plan' ? 'text-yellow-600 dark:text-yellow-500' : 'text-green-600 dark:text-green-500' const modeBg = currentMode === 'plan' ? 'bg-yellow-500/20 border-yellow-400 hover:bg-yellow-500/30 hover:border-yellow-300' : 'bg-green-500/20 border-green-400 hover:bg-green-500/30 hover:border-green-300' const modeShadow = currentMode === 'plan' ? 'shadow-yellow-500/20 hover:shadow-yellow-500/30' : 'shadow-green-500/20 hover:shadow-green-500/30' @@ -708,6 +709,10 @@ const { model, modelString } = useModelSelection(opcodeUrl, directory) onPromptChange?.(prompt.trim().length > 0) }, [prompt, onPromptChange]) + useEffect(() => { + setLocalMode(null) + }, [sessionID]) + @@ -773,6 +778,7 @@ return (
+ )} {hasItems && (