feat: improve chat input ux (#350)

This commit is contained in:
Carlos Florêncio
2026-03-02 21:32:21 +00:00
committed by GitHub
parent 2aab682cd8
commit d0b5237070
20 changed files with 159 additions and 106 deletions
+28
View File
@@ -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;
@@ -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),
};
}
@@ -259,7 +259,6 @@ type ChatInputAreaProps = {
handleCancelTurn: () => Promise<void>;
showRequestChangesTooltip: boolean;
onRequestChangesTooltipDismiss?: () => void;
isPanelFocused?: boolean;
panelState: ReturnType<typeof useChatPanelState>;
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}
/>
</div>
@@ -176,8 +176,7 @@ export type ChatInputBodyProps = {
containerRef: React.RefObject<HTMLDivElement | null>;
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 (
<div
ref={containerRef}
className={cn(
"relative flex flex-col border rounded ",
"bg-background border-border",
isAgentBusy && !planModeEnabled && "chat-input-running",
isAgentBusy && planModeEnabled && "chat-input-running-plan",
planModeEnabled && !isAgentBusy && "border-slate-400/50",
hasClarification && "border-sky-400/50",
showRequestChangesTooltip && "animate-pulse border-orange-500",
hasPendingComments && "border-amber-500/50",
)}
style={{ height }}
>
<div className="relative">
<ResizeHandle
visible={isPanelFocused || isInputFocused}
planModeEnabled={planModeEnabled}
isAgentBusy={isAgentBusy}
isStarting={isStarting}
{...resizeHandleProps}
/>
<ChatInputFocusHint visible={showFocusHint} />
<ChatInputContextArea {...contextAreaProps} />
<ChatInputEditorArea {...editorAreaProps} />
<div
ref={containerRef}
className={cn(
"flex flex-col overflow-hidden border rounded ",
"bg-background border-border",
isStarting && !isAgentBusy && "chat-input-starting",
isAgentBusy && !planModeEnabled && "chat-input-running",
isAgentBusy && planModeEnabled && "chat-input-running-plan",
planModeEnabled && !isAgentBusy && "border-slate-400/50",
hasClarification && "border-sky-400/50",
showRequestChangesTooltip && "animate-pulse border-orange-500",
hasPendingComments && "border-amber-500/50",
)}
style={{ height }}
>
<ChatInputFocusHint visible={showFocusHint} />
<ChatInputContextArea {...contextAreaProps} />
<ChatInputEditorArea {...editorAreaProps} />
</div>
</div>
);
}
@@ -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<ChatInputContainerHandle, ChatInput
isStarting,
isSending,
isFailed = false,
isPanelFocused,
showRequestChangesTooltip = false,
} = props;
@@ -232,6 +231,7 @@ export const ChatInputContainer = forwardRef<ChatInputContainerHandle, ChatInput
onSubmit: props.onSubmit,
});
const isUtilityConfigured = useIsUtilityConfigured();
const { enhancePrompt, isEnhancingPrompt } = useUtilityAgentGenerator({
sessionId,
taskTitle,
@@ -264,8 +264,7 @@ export const ChatInputContainer = forwardRef<ChatInputContainerHandle, ChatInput
containerRef={s.containerRef}
height={s.height}
resizeHandleProps={s.resizeHandleProps}
isPanelFocused={isPanelFocused}
isInputFocused={s.isInputFocused}
isStarting={isStarting}
isAgentBusy={isAgentBusy}
hasClarification={s.hasClarification}
showRequestChangesTooltip={showRequestChangesTooltip}
@@ -273,10 +272,11 @@ export const ChatInputContainer = forwardRef<ChatInputContainerHandle, ChatInput
planModeEnabled={props.planModeEnabled}
showFocusHint={s.showFocusHint}
contextAreaProps={buildContextAreaProps(s, p)}
editorAreaProps={buildEditorAreaProps(s, p, {
onEnhancePrompt: handleEnhancePrompt,
isEnhancingPrompt,
})}
editorAreaProps={buildEditorAreaProps(
s,
p,
isUtilityConfigured ? { onEnhancePrompt: handleEnhancePrompt, isEnhancingPrompt } : {},
)}
/>
);
},
@@ -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({
<div
className={cn(
"w-8 h-0.5 rounded-full transition-colors",
planModeEnabled
? "bg-slate-400/60 hover:bg-slate-400"
: "bg-border hover:bg-muted-foreground",
getHandleColor(planModeEnabled, isAgentBusy, isStarting),
)}
/>
</button>
@@ -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,
@@ -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<typeof Decoration>[] = [];
const isEmptyDoc = editor.isEmpty;
@@ -191,14 +191,7 @@ function ChatContent({ panelId }: { panelId: string }) {
);
}
return (
<TaskChatPanel
sessionId={sessionId}
onOpenFile={openFile}
onOpenFileAtLine={openFile}
isPanelFocused={false}
/>
);
return <TaskChatPanel sessionId={sessionId} onOpenFile={openFile} onOpenFileAtLine={openFile} />;
}
function DiffViewerContent({
@@ -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}
/>
+3 -16
View File
@@ -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({
<PanelBody
padding={false}
scroll={false}
className={cn("relative transition-colors cursor-text")}
className={cn("relative transition-colors cursor-text", isAgentBusy && "bg-background")}
ref={editorWrapperRef}
onClick={handleEmptyStateClick}
>
@@ -178,7 +179,6 @@ export const TaskPlanPanel = memo(function TaskPlanPanel({
onCommentDeleted={handleCommentDeleted}
onEditorReady={handleEditorReady}
/>
<PlanCreatingOverlay isAgentCreatingPlan={isAgentCreatingPlan} />
<PlanEmptyState
isLoading={isLoading}
draftContent={draftContent}
@@ -263,19 +263,6 @@ function PlanSelectionPopoverWrapper({
);
}
/** Agent creating plan overlay */
function PlanCreatingOverlay({ isAgentCreatingPlan }: { isAgentCreatingPlan: boolean }) {
if (!isAgentCreatingPlan) return null;
return (
<div className="absolute inset-0 flex items-center justify-center bg-background">
<div className="flex flex-col items-center gap-4">
<GridSpinner className="h-5 w-5" />
<span className="text-sm text-muted-foreground">Agent is creating a plan...</span>
</div>
</div>
);
}
/** Draft content, editor key, focus tracking, and auto-save */
function usePlanDraft(
plan: { content?: string; title?: string } | null | undefined,
+48 -33
View File
@@ -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<typeof useGitOperations>["createPR"],
toast: ReturnType<typeof useToast>["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}
/>
<PRDialog
open={ps.open}
@@ -504,8 +517,10 @@ export function VcsDialogsProvider({
onPrDraftChange={ps.setDraft}
isGitLoading={isGitLoading}
onCreatePR={handleCreatePR}
onGenerateDescription={() => generatePRDescription(ps.setBody)}
isGenerating={isGeneratingPRDescription}
onGenerateDescription={
isUtilityConfigured ? () => generatePRDescription(ps.setBody) : undefined
}
isGenerating={isUtilityConfigured ? isGeneratingPRDescription : undefined}
/>
</VcsDialogsContext.Provider>
);
@@ -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);
}
+15 -4
View File
@@ -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<HTMLElement>(".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);
}
@@ -38,6 +38,7 @@ function carryForwardSettings(current: DisplaySettings) {
lspAutoInstallLanguages: current.lspAutoInstallLanguages ?? [],
lspServerConfigs: current.lspServerConfigs ?? {},
savedLayouts: current.savedLayouts ?? [],
defaultUtilityAgentId: current.defaultUtilityAgentId ?? null,
};
}
+2
View File
@@ -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,
};
@@ -36,6 +36,7 @@ export const defaultSettingsState: SettingsSliceState = {
lspAutoInstallLanguages: [],
lspServerConfigs: {},
savedLayouts: [],
defaultUtilityAgentId: null,
loaded: false,
},
};
@@ -114,6 +114,7 @@ export type UserSettingsState = {
lspAutoInstallLanguages: string[];
lspServerConfigs: Record<string, Record<string, unknown>>;
savedLayouts: SavedLayout[];
defaultUtilityAgentId: string | null;
loaded: boolean;
};
+1
View File
@@ -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;
};
+1
View File
@@ -26,6 +26,7 @@ export function registerUsersHandlers(store: StoreApi<AppState>): 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,
},
}));