From d0b52370704d2ebd3454053ff3faa637fd490955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Flor=C3=AAncio?= Date: Mon, 2 Mar 2026 21:32:21 +0000 Subject: [PATCH] feat: improve chat input ux (#350) --- apps/web/app/globals.css | 28 +++++++ .../settings/editors-settings-state.tsx | 1 + .../components/task/chat/chat-input-area.tsx | 3 - .../components/task/chat/chat-input-body.tsx | 46 ++++++----- .../task/chat/chat-input-container.tsx | 16 ++-- .../components/task/chat/resize-handle.tsx | 21 +++-- .../task/chat/use-chat-input-container.ts | 3 + .../components/task/chat/use-tiptap-editor.ts | 2 +- .../task/dockview-desktop-layout.tsx | 9 +-- apps/web/components/task/task-chat-panel.tsx | 4 - apps/web/components/task/task-plan-panel.tsx | 19 +---- apps/web/components/vcs/vcs-dialogs.tsx | 81 +++++++++++-------- apps/web/hooks/use-is-utility-configured.ts | 6 ++ apps/web/hooks/use-resizable-input.ts | 19 ++++- apps/web/hooks/use-user-display-settings.ts | 1 + apps/web/lib/ssr/user-settings.ts | 2 + .../state/slices/settings/settings-slice.ts | 1 + apps/web/lib/state/slices/settings/types.ts | 1 + apps/web/lib/types/backend.ts | 1 + apps/web/lib/ws/handlers/users.ts | 1 + 20 files changed, 159 insertions(+), 106 deletions(-) create mode 100644 apps/web/hooks/use-is-utility-configured.ts diff --git a/apps/web/app/globals.css b/apps/web/app/globals.css index 3219ed02d5..7a8071330f 100644 --- a/apps/web/app/globals.css +++ b/apps/web/app/globals.css @@ -386,6 +386,34 @@ animation: chat-input-running-plan 3s ease-in-out infinite; } +@keyframes chat-input-starting { + 0%, + 100% { + border-color: color-mix(in oklab, oklch(0.7 0.12 85) 40%, var(--border)); + box-shadow: + 0 0 4px 1px color-mix(in oklab, oklch(0.7 0.12 85) 10%, transparent), + 0 0 10px 2px color-mix(in oklab, oklch(0.7 0.12 85) 5%, transparent); + } + 50% { + border-color: color-mix(in oklab, oklch(0.7 0.12 85) 60%, var(--border)); + box-shadow: + 0 0 12px 3px color-mix(in oklab, oklch(0.7 0.12 85) 15%, transparent), + 0 0 30px 6px color-mix(in oklab, oklch(0.7 0.12 85) 8%, transparent); + } +} + +.chat-input-starting { + animation: chat-input-starting 2s ease-in-out infinite; +} + +@media (prefers-reduced-motion: reduce) { + .chat-input-running, + .chat-input-running-plan, + .chat-input-starting { + animation: none; + } +} + @layer components { .border-flash-animation { position: relative; diff --git a/apps/web/components/settings/editors-settings-state.tsx b/apps/web/components/settings/editors-settings-state.tsx index 9a34fcd868..30df114120 100644 --- a/apps/web/components/settings/editors-settings-state.tsx +++ b/apps/web/components/settings/editors-settings-state.tsx @@ -236,6 +236,7 @@ function buildUserSettingsFromResponse( shellOptions: shellOptions ?? [], defaultEditorId: s.default_editor_id || null, enablePreviewOnClick: s.enable_preview_on_click ?? false, + defaultUtilityAgentId: s.default_utility_agent_id || null, ...mapEditorSettingsFields(s), }; } diff --git a/apps/web/components/task/chat/chat-input-area.tsx b/apps/web/components/task/chat/chat-input-area.tsx index e9a196012c..1fab80c23c 100644 --- a/apps/web/components/task/chat/chat-input-area.tsx +++ b/apps/web/components/task/chat/chat-input-area.tsx @@ -259,7 +259,6 @@ type ChatInputAreaProps = { handleCancelTurn: () => Promise; showRequestChangesTooltip: boolean; onRequestChangesTooltipDismiss?: () => void; - isPanelFocused?: boolean; panelState: ReturnType; isSending: boolean; }; @@ -272,7 +271,6 @@ export function ChatInputArea({ handleCancelTurn, showRequestChangesTooltip, onRequestChangesTooltipDismiss, - isPanelFocused, panelState, isSending, }: ChatInputAreaProps) { @@ -357,7 +355,6 @@ export function ChatInputArea({ onToggleContextFile={handleToggleContextFile} onAddContextFile={handleAddContextFile} todoItems={todoItems} - isPanelFocused={isPanelFocused} onImplementPlan={handleImplementPlan} /> diff --git a/apps/web/components/task/chat/chat-input-body.tsx b/apps/web/components/task/chat/chat-input-body.tsx index 2fb28033aa..d4c3081c09 100644 --- a/apps/web/components/task/chat/chat-input-body.tsx +++ b/apps/web/components/task/chat/chat-input-body.tsx @@ -176,8 +176,7 @@ export type ChatInputBodyProps = { containerRef: React.RefObject; height: React.CSSProperties["height"]; resizeHandleProps: { onMouseDown: (e: React.MouseEvent) => void; onDoubleClick: () => void }; - isPanelFocused: boolean | undefined; - isInputFocused: boolean; + isStarting: boolean; isAgentBusy: boolean; hasClarification: boolean; showRequestChangesTooltip: boolean; @@ -192,8 +191,7 @@ export function ChatInputBody({ containerRef, height, resizeHandleProps, - isPanelFocused, - isInputFocused, + isStarting, isAgentBusy, hasClarification, showRequestChangesTooltip, @@ -204,28 +202,32 @@ export function ChatInputBody({ editorAreaProps, }: ChatInputBodyProps) { return ( -
+
- - - +
+ + + +
); } diff --git a/apps/web/components/task/chat/chat-input-container.tsx b/apps/web/components/task/chat/chat-input-container.tsx index 71aebd539a..d33046d280 100644 --- a/apps/web/components/task/chat/chat-input-container.tsx +++ b/apps/web/components/task/chat/chat-input-container.tsx @@ -15,6 +15,7 @@ import { } from "./chat-input-body"; import type { ContextItem } from "@/lib/types/context"; import { useUtilityAgentGenerator } from "@/hooks/use-utility-agent-generator"; +import { useIsUtilityConfigured } from "@/hooks/use-is-utility-configured"; // Re-export ImageAttachment type for consumers export type { ImageAttachment } from "./image-attachment-preview"; @@ -72,7 +73,6 @@ type ChatInputContainerProps = { onToggleContextFile?: (file: ContextFile) => void; onAddContextFile?: (file: ContextFile) => void; todoItems?: TodoItem[]; - isPanelFocused?: boolean; onImplementPlan?: () => void; }; @@ -196,7 +196,6 @@ export const ChatInputContainer = forwardRef ); }, diff --git a/apps/web/components/task/chat/resize-handle.tsx b/apps/web/components/task/chat/resize-handle.tsx index 3f614e2a71..22950d5a5d 100644 --- a/apps/web/components/task/chat/resize-handle.tsx +++ b/apps/web/components/task/chat/resize-handle.tsx @@ -3,15 +3,25 @@ import { cn } from "@/lib/utils"; type ResizeHandleProps = { - visible: boolean; planModeEnabled?: boolean; + isAgentBusy?: boolean; + isStarting?: boolean; onMouseDown: (e: React.MouseEvent) => void; onDoubleClick: () => void; }; +function getHandleColor(planModeEnabled?: boolean, isAgentBusy?: boolean, isStarting?: boolean) { + if (isStarting) return "bg-amber-400/60 hover:bg-amber-400"; + if (isAgentBusy && planModeEnabled) return "bg-slate-400/60 hover:bg-slate-400"; + if (isAgentBusy) return "bg-primary/40 hover:bg-primary/70"; + if (planModeEnabled) return "bg-slate-400/60 hover:bg-slate-400"; + return "bg-border hover:bg-muted-foreground"; +} + export function ResizeHandle({ - visible, planModeEnabled, + isAgentBusy, + isStarting, onMouseDown, onDoubleClick, }: ResizeHandleProps) { @@ -20,9 +30,8 @@ export function ResizeHandle({ type="button" className={cn( "absolute left-1/2 top-[-1px] -translate-x-1/2 -translate-y-1/2 z-10", - "w-12 h-2 cursor-ns-resize transition-opacity", + "w-12 h-2 cursor-ns-resize", "flex items-center justify-center", - visible ? "opacity-100" : "opacity-0 pointer-events-none", )} onMouseDown={onMouseDown} onDoubleClick={onDoubleClick} @@ -31,9 +40,7 @@ export function ResizeHandle({
diff --git a/apps/web/components/task/chat/use-chat-input-container.ts b/apps/web/components/task/chat/use-chat-input-container.ts index 8ea50342c1..1d80f18e8a 100644 --- a/apps/web/components/task/chat/use-chat-input-container.ts +++ b/apps/web/components/task/chat/use-chat-input-container.ts @@ -60,7 +60,9 @@ function getInputPlaceholder( placeholder: string | undefined, isAgentBusy: boolean, hasAgentCommands: boolean, + isStarting: boolean, ): string { + if (isStarting) return "Preparing workspace..."; if (placeholder) return placeholder; if (isAgentBusy) return "Queue more instructions..."; if (hasAgentCommands) return "Ask to make changes, @mention files, run /commands"; @@ -93,6 +95,7 @@ function computeDerivedState(params: { params.placeholder, params.isAgentBusy, params.hasAgentCommands, + params.isStarting, ); return { isDisabled, diff --git a/apps/web/components/task/chat/use-tiptap-editor.ts b/apps/web/components/task/chat/use-tiptap-editor.ts index 982745508c..dc64c21082 100644 --- a/apps/web/components/task/chat/use-tiptap-editor.ts +++ b/apps/web/components/task/chat/use-tiptap-editor.ts @@ -56,7 +56,7 @@ const DynamicPlaceholder = Extension.create({ key: new PluginKey("dynamicPlaceholder"), props: { decorations: ({ doc, selection }) => { - if (!editor.isEditable) return null; + if (!editor.isEditable && !editor.isEmpty) return null; const { anchor } = selection; const decorations: InstanceType[] = []; const isEmptyDoc = editor.isEmpty; diff --git a/apps/web/components/task/dockview-desktop-layout.tsx b/apps/web/components/task/dockview-desktop-layout.tsx index 8ab54535e0..d3a297e2c0 100644 --- a/apps/web/components/task/dockview-desktop-layout.tsx +++ b/apps/web/components/task/dockview-desktop-layout.tsx @@ -191,14 +191,7 @@ function ChatContent({ panelId }: { panelId: string }) { ); } - return ( - - ); + return ; } function DiffViewerContent({ diff --git a/apps/web/components/task/task-chat-panel.tsx b/apps/web/components/task/task-chat-panel.tsx index fee2cb810f..e222b692d9 100644 --- a/apps/web/components/task/task-chat-panel.tsx +++ b/apps/web/components/task/task-chat-panel.tsx @@ -56,8 +56,6 @@ type TaskChatPanelProps = { onRequestChangesTooltipDismiss?: () => void; /** Callback to open a file at a specific line (for comment clicks) */ onOpenFileAtLine?: (filePath: string) => void; - /** Whether the dockview group containing this panel is focused */ - isPanelFocused?: boolean; }; export const TaskChatPanel = memo(function TaskChatPanel({ @@ -67,7 +65,6 @@ export const TaskChatPanel = memo(function TaskChatPanel({ showRequestChangesTooltip = false, onRequestChangesTooltipDismiss, onOpenFileAtLine, - isPanelFocused, }: TaskChatPanelProps) { const isArchived = useIsTaskArchived(); const lastAgentMessageCountRef = useRef(0); @@ -156,7 +153,6 @@ export const TaskChatPanel = memo(function TaskChatPanel({ handleCancelTurn={handleCancelTurn} showRequestChangesTooltip={showRequestChangesTooltip} onRequestChangesTooltipDismiss={onRequestChangesTooltipDismiss} - isPanelFocused={isPanelFocused} panelState={panelState} isSending={isSending} /> diff --git a/apps/web/components/task/task-plan-panel.tsx b/apps/web/components/task/task-plan-panel.tsx index 215696e3d2..d06e5a9677 100644 --- a/apps/web/components/task/task-plan-panel.tsx +++ b/apps/web/components/task/task-plan-panel.tsx @@ -4,7 +4,6 @@ import { memo, useState, useCallback, useEffect, useRef, useMemo } from "react"; import { PanelRoot, PanelBody } from "./panel-primitives"; import dynamic from "next/dynamic"; import { IconLoader2, IconFileText, IconRobot, IconMessage, IconClick } from "@tabler/icons-react"; -import { GridSpinner } from "@/components/grid-spinner"; import { cn } from "@/lib/utils"; import { useTaskPlan } from "@/hooks/domains/session/use-task-plan"; import { useAppStore } from "@/components/state-provider"; @@ -103,6 +102,7 @@ function useTaskPlanPanelState(taskId: string | null, visible: boolean) { handleEditorReady, handleCommentDeleted, commentHighlights, + isAgentBusy, isAgentCreatingPlan, editorWrapperRef, editorInstanceRef, @@ -131,6 +131,7 @@ export const TaskPlanPanel = memo(function TaskPlanPanel({ handleEditorReady, handleCommentDeleted, commentHighlights, + isAgentBusy, isAgentCreatingPlan, editorWrapperRef, editorInstanceRef, @@ -163,7 +164,7 @@ export const TaskPlanPanel = memo(function TaskPlanPanel({ @@ -178,7 +179,6 @@ export const TaskPlanPanel = memo(function TaskPlanPanel({ onCommentDeleted={handleCommentDeleted} onEditorReady={handleEditorReady} /> - -
- - Agent is creating a plan... -
-
- ); -} - /** Draft content, editor key, focus tracking, and auto-save */ function usePlanDraft( plan: { content?: string; title?: string } | null | undefined, diff --git a/apps/web/components/vcs/vcs-dialogs.tsx b/apps/web/components/vcs/vcs-dialogs.tsx index ab1e40150b..32760232da 100644 --- a/apps/web/components/vcs/vcs-dialogs.tsx +++ b/apps/web/components/vcs/vcs-dialogs.tsx @@ -26,6 +26,7 @@ import { useSessionGitStatus } from "@/hooks/domains/session/use-session-git-sta import { useGitOperations } from "@/hooks/use-git-operations"; import { useGitWithFeedback } from "@/hooks/use-git-with-feedback"; import { useUtilityAgentGenerator } from "@/hooks/use-utility-agent-generator"; +import { useIsUtilityConfigured } from "@/hooks/use-is-utility-configured"; import { useToast } from "@/components/toast-provider"; import type { FileInfo } from "@/lib/state/slices"; @@ -408,35 +409,13 @@ function usePRDialogState(): UsePRDialogReturn { return { open, setOpen, title, setTitle, body, setBody, draft, setDraft, openDialog }; } -export function VcsDialogsProvider({ - sessionId, - baseBranch, - taskTitle, - displayBranch, - children, -}: VcsDialogsProviderProps) { - const cs = useCommitDialogState(); - const ps = usePRDialogState(); - const { toast } = useToast(); - const gitWithFeedback = useGitWithFeedback(); - const gitStatus = useSessionGitStatus(sessionId); - const { commit, createPR, isLoading: isGitLoading } = useGitOperations(sessionId); - const { - isGeneratingCommitMessage, - isGeneratingPRDescription, - generateCommitMessage, - generatePRDescription, - } = useUtilityAgentGenerator({ sessionId, taskTitle }); - const fileSummary = computeFileSummary(gitStatus?.files); - - const handleCommit = useCallback(async () => { - if (!cs.message.trim()) return; - cs.setOpen(false); - await gitWithFeedback(() => commit(cs.message.trim(), cs.stageAll), "Commit"); - cs.setMessage(""); - }, [cs, gitWithFeedback, commit]); - - const handleCreatePR = useCallback(async () => { +function useCreatePRHandler( + ps: UsePRDialogReturn, + baseBranch: string | undefined, + createPR: ReturnType["createPR"], + toast: ReturnType["toast"], +) { + return useCallback(async () => { if (!ps.title.trim()) return; ps.setOpen(false); try { @@ -466,6 +445,38 @@ export function VcsDialogsProvider({ ps.setTitle(""); ps.setBody(""); }, [ps, baseBranch, createPR, toast]); +} + +export function VcsDialogsProvider({ + sessionId, + baseBranch, + taskTitle, + displayBranch, + children, +}: VcsDialogsProviderProps) { + const cs = useCommitDialogState(); + const ps = usePRDialogState(); + const { toast } = useToast(); + const gitWithFeedback = useGitWithFeedback(); + const gitStatus = useSessionGitStatus(sessionId); + const { commit, createPR, isLoading: isGitLoading } = useGitOperations(sessionId); + const isUtilityConfigured = useIsUtilityConfigured(); + const { + isGeneratingCommitMessage, + isGeneratingPRDescription, + generateCommitMessage, + generatePRDescription, + } = useUtilityAgentGenerator({ sessionId, taskTitle }); + const fileSummary = computeFileSummary(gitStatus?.files); + + const handleCommit = useCallback(async () => { + if (!cs.message.trim()) return; + cs.setOpen(false); + await gitWithFeedback(() => commit(cs.message.trim(), cs.stageAll), "Commit"); + cs.setMessage(""); + }, [cs, gitWithFeedback, commit]); + + const handleCreatePR = useCreatePRHandler(ps, baseBranch, createPR, toast); const contextValue = useMemo( () => ({ @@ -488,8 +499,10 @@ export function VcsDialogsProvider({ onStageAllChange={cs.setStageAll} isGitLoading={isGitLoading} onCommit={handleCommit} - onGenerateMessage={() => generateCommitMessage(cs.setMessage)} - isGenerating={isGeneratingCommitMessage} + onGenerateMessage={ + isUtilityConfigured ? () => generateCommitMessage(cs.setMessage) : undefined + } + isGenerating={isUtilityConfigured ? isGeneratingCommitMessage : undefined} /> generatePRDescription(ps.setBody)} - isGenerating={isGeneratingPRDescription} + onGenerateDescription={ + isUtilityConfigured ? () => generatePRDescription(ps.setBody) : undefined + } + isGenerating={isUtilityConfigured ? isGeneratingPRDescription : undefined} /> ); diff --git a/apps/web/hooks/use-is-utility-configured.ts b/apps/web/hooks/use-is-utility-configured.ts new file mode 100644 index 0000000000..7ca42750cd --- /dev/null +++ b/apps/web/hooks/use-is-utility-configured.ts @@ -0,0 +1,6 @@ +import { useAppStore } from "@/components/state-provider"; + +/** Returns true when the user has configured a default utility agent. */ +export function useIsUtilityConfigured(): boolean { + return useAppStore((s) => !!s.userSettings.defaultUtilityAgentId); +} diff --git a/apps/web/hooks/use-resizable-input.ts b/apps/web/hooks/use-resizable-input.ts index 1d46cff4ed..ca6dbac028 100644 --- a/apps/web/hooks/use-resizable-input.ts +++ b/apps/web/hooks/use-resizable-input.ts @@ -3,9 +3,9 @@ import { useCallback, useEffect, useRef, useState } from "react"; import { getChatInputHeight, setChatInputHeight } from "@/lib/local-storage"; -const MIN_HEIGHT = 100; -const DEFAULT_HEIGHT = 134; -const MAX_ABSOLUTE = 450; +const MIN_HEIGHT = 110; +const DEFAULT_HEIGHT = 110; +const MAX_ABSOLUTE = 400; function clampHeight(value: number): number { const maxHeight = Math.min(window.innerHeight * 0.6, MAX_ABSOLUTE); @@ -22,6 +22,13 @@ function measureContentHeight(container: HTMLElement, content: HTMLElement): num return clampHeight(naturalHeight + chrome); } +/** When the input grows, scroll the chat down so messages don't shift up. */ +function compensateChatScroll(delta: number) { + if (delta <= 0) return; + const el = document.querySelector(".chat-message-list"); + if (el) el.scrollTop += delta; +} + export function useResizableInput( sessionId: string | undefined, getContentElement?: () => HTMLElement | null, @@ -104,8 +111,12 @@ export function useResizableInput( const container = containerRef.current; const content = getContentElement?.(); if (!container || !content || isDragging.current) return; - const needed = measureContentHeight(container, content); + const raw = measureContentHeight(container, content); + // Never shrink below DEFAULT_HEIGHT during auto-expand; + // MIN_HEIGHT is only for manual drag-resize. + const needed = Math.max(raw, DEFAULT_HEIGHT); if (needed !== height) { + compensateChatScroll(needed - height); setHeight(needed); persistHeight(needed); } diff --git a/apps/web/hooks/use-user-display-settings.ts b/apps/web/hooks/use-user-display-settings.ts index cf44081981..80aa5dc98a 100644 --- a/apps/web/hooks/use-user-display-settings.ts +++ b/apps/web/hooks/use-user-display-settings.ts @@ -38,6 +38,7 @@ function carryForwardSettings(current: DisplaySettings) { lspAutoInstallLanguages: current.lspAutoInstallLanguages ?? [], lspServerConfigs: current.lspServerConfigs ?? {}, savedLayouts: current.savedLayouts ?? [], + defaultUtilityAgentId: current.defaultUtilityAgentId ?? null, }; } diff --git a/apps/web/lib/ssr/user-settings.ts b/apps/web/lib/ssr/user-settings.ts index 56544e2b1b..0f7a29035c 100644 --- a/apps/web/lib/ssr/user-settings.ts +++ b/apps/web/lib/ssr/user-settings.ts @@ -16,6 +16,7 @@ export function buildCoreFields(s: UserSettingsData) { showReleaseNotification: s.show_release_notification ?? true, releaseNotesLastSeenVersion: s.release_notes_last_seen_version || null, savedLayouts: s.saved_layouts ?? [], + defaultUtilityAgentId: s.default_utility_agent_id || null, }; } @@ -49,6 +50,7 @@ export function mapUserSettingsResponse(response: UserSettingsResponse | null) { showReleaseNotification: true, releaseNotesLastSeenVersion: null, savedLayouts: [] as SavedLayout[], + defaultUtilityAgentId: null, ...buildLspFields(undefined), loaded: false, }; diff --git a/apps/web/lib/state/slices/settings/settings-slice.ts b/apps/web/lib/state/slices/settings/settings-slice.ts index 71b428b944..1d6c6d095e 100644 --- a/apps/web/lib/state/slices/settings/settings-slice.ts +++ b/apps/web/lib/state/slices/settings/settings-slice.ts @@ -36,6 +36,7 @@ export const defaultSettingsState: SettingsSliceState = { lspAutoInstallLanguages: [], lspServerConfigs: {}, savedLayouts: [], + defaultUtilityAgentId: null, loaded: false, }, }; diff --git a/apps/web/lib/state/slices/settings/types.ts b/apps/web/lib/state/slices/settings/types.ts index f60b61fecb..61d3f6a709 100644 --- a/apps/web/lib/state/slices/settings/types.ts +++ b/apps/web/lib/state/slices/settings/types.ts @@ -114,6 +114,7 @@ export type UserSettingsState = { lspAutoInstallLanguages: string[]; lspServerConfigs: Record>; savedLayouts: SavedLayout[]; + defaultUtilityAgentId: string | null; loaded: boolean; }; diff --git a/apps/web/lib/types/backend.ts b/apps/web/lib/types/backend.ts index 012a1f4ff5..b1308566c1 100644 --- a/apps/web/lib/types/backend.ts +++ b/apps/web/lib/types/backend.ts @@ -352,6 +352,7 @@ export type UserSettingsUpdatedPayload = { lsp_auto_start_languages?: string[]; lsp_auto_install_languages?: string[]; saved_layouts?: SavedLayout[]; + default_utility_agent_id?: string; updated_at?: string; }; diff --git a/apps/web/lib/ws/handlers/users.ts b/apps/web/lib/ws/handlers/users.ts index 600e11b28d..15e5a3b8af 100644 --- a/apps/web/lib/ws/handlers/users.ts +++ b/apps/web/lib/ws/handlers/users.ts @@ -26,6 +26,7 @@ export function registerUsersHandlers(store: StoreApi): WsHandlers { lspAutoStartLanguages: message.payload.lsp_auto_start_languages ?? [], lspAutoInstallLanguages: message.payload.lsp_auto_install_languages ?? [], savedLayouts: message.payload.saved_layouts ?? [], + defaultUtilityAgentId: message.payload.default_utility_agent_id || null, loaded: true, }, }));