feat(webui): inspect file context in a live graph sidebar (#6562)

* feat(webui): inspect file context in a live graph sidebar

* refactor(webui): place preview controls in the shared sidebar header

* fix(webui): synchronize npm lockfile for graph dependencies

* fix(webui): preserve compacted context and refine graph inspection

* fix(context): harden provenance, request usage, and drawer lifecycle

* fix(webui): align source skeleton and browser fixtures

* perf(context): reuse source analysis and capture request graphs once

* perf(webui): compact graph history and render graph motion on canvas

* fix(webui): remove redundant context sidebar header

* style(webui): clarify context replay icon

* perf(webui): pace context replay on an adaptive timeline

* feat(webui): briefly reveal labels for new context nodes

* fix(webui): reveal new labels only for loaded context files

* fix(webui): restart graph animation clock after idle

* fix(webui): reveal labels when replay reverses node exit

* refactor(context): project file-use facts without retention tracking

* refactor(context): observe file reads outside agent execution

* fix(webui): animate context sidebar closing

* refactor(context): remove unused graph and usage panel code

* refactor(context): isolate prompt observation from execution metadata

* fix(webui): clarify cache rate and show context token usage

* fix(webui): abbreviate context token counts in thousands

* fix(webui): omit token unit from context usage details

* fix(webui): restore large source preview highlighting and panel elevation

* fix(webui): distinguish modifier scrolling from keyboard focus

* fix(webui): align preview tab and panel corner radii

* fix(webui): attach file tabs to the header divider

* fix(webui): use one action to toggle file preview mode

* fix(webui): use hover hint for context replay

* fix(webui): share composer layout between graph and file sidebars

* fix(webui): align sidebar bottom with composer surface

* fix(webui): restore mobile graph drawing and touch file details

* test(webui): align legacy cache assertions with current label

* perf(context): retain source analysis and bound graph animation work

* style(webui): add light elevation to user messages

* test(webui): await lazy graph scene before replay assertions

* fix(webui): align preview skeleton and browser contracts
This commit is contained in:
chengyongru authored and GitHub committed 2026-11-05 17:09:20 +08:00
1 parent 2b44088413
commit 519ed81132
132 files changed
+4673 -1159

No files matched your search

+124 -11
View File
@@ -41,26 +41,29 @@ DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
const DialogPositionedContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
contained?: boolean;
positionerStyle?: React.CSSProperties;
placement?: "center" | "bottom";
overlayClassName?: string;
}
>(({ positionerStyle, placement, overlayClassName, ...props }, ref) => (
<DialogOverlay forceMount className={overlayClassName}>
<div className={cn("fixed inset-0 z-50 flex items-start justify-center overflow-y-auto overscroll-contain", placement !== "bottom" && "p-4")} style={{
>(({ contained, positionerStyle, placement, overlayClassName, ...props }, ref) => {
const Overlay = contained ? "div" : DialogOverlay;
return <Overlay data-dialog-backdrop {...(contained ? {} : { forceMount: true })} className={cn(contained && "absolute inset-0 z-50", overlayClassName)}>
<div className={cn("fixed inset-0 z-50 flex items-start justify-center overscroll-contain", placement === "bottom" ? "overflow-clip" : "overflow-y-auto p-4", contained && "absolute")} style={{
top: "var(--app-viewport-top, 0px)",
height: "var(--app-viewport-height, 100%)",
bottom: "auto",
...positionerStyle,
...(contained ? { top: 0, height: "100%" } : positionerStyle),
}}>
<DialogPrimitive.Content ref={ref} {...props} />
</div>
</DialogOverlay>
));
</Overlay>;
});
DialogPositionedContent.displayName = "DialogPositionedContent";
interface DialogContentProps
extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> {
portalContainer?: HTMLElement | null;
showCloseButton?: boolean;
overlayClassName?: string;
layoutAnchor?: HTMLElement | null;
@@ -71,10 +74,73 @@ interface DialogContentProps
const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
DialogContentProps
>(({ className, children, showCloseButton = true, overlayClassName, placement = "center", layoutAnchor: explicitLayoutAnchor, centerInLayoutAnchor = false, onOpenAutoFocus, ...props }, ref) => {
>(({ className, children, portalContainer, showCloseButton = true, overlayClassName, placement = "center", layoutAnchor: explicitLayoutAnchor, centerInLayoutAnchor = false, onOpenAutoFocus, ...props }, ref) => {
const { t } = useTranslation();
const [container, setContainer] = React.useState<HTMLDivElement | null>(null);
const contentNode = React.useRef<HTMLDivElement | null>(null);
const gesture = React.useRef<{ id: number; start: number; y: number; time: number; speed: number; moved: boolean } | null>(null);
const suppressClick = React.useRef(false);
const settleAnimation = React.useRef<Animation | null>(null);
const backdropFrame = React.useRef<number | null>(null);
const dragBackdrop = React.useRef<{ node: HTMLElement; color: string; blur: number } | null>(null);
const paintBackdrop = (distance: number, height: number) => {
const backdrop = dragBackdrop.current;
if (!backdrop) return;
const remaining = 1 - Math.min(1, Math.max(0, distance) / Math.max(1, height));
backdrop.node.style.backgroundColor = `color-mix(in srgb, ${backdrop.color} ${remaining * 100}%, transparent)`;
backdrop.node.style.backdropFilter = `blur(${backdrop.blur * remaining}px)`;
};
const cancelBackdropFrame = () => {
if (backdropFrame.current !== null) cancelAnimationFrame(backdropFrame.current);
backdropFrame.current = null;
};
React.useEffect(() => () => {
settleAnimation.current?.cancel();
if (backdropFrame.current !== null) cancelAnimationFrame(backdropFrame.current);
}, []);
const finishDrag = (button: HTMLButtonElement, pointerId: number, cancelled: boolean) => {
const drag = gesture.current;
const node = contentNode.current;
if (!drag || drag.id !== pointerId || !node) return;
gesture.current = null;
suppressClick.current = drag.moved;
if (!drag.moved) {
if (dragBackdrop.current) {
const style = dragBackdrop.current.node.style;
for (const property of ["background-color", "backdrop-filter", "transition"]) style.removeProperty(property);
dragBackdrop.current = null;
}
return;
}
const distance = Math.max(0, drag.y - drag.start);
const dismiss = !cancelled && (distance > Math.min(120, node.offsetHeight * 0.22)
|| (distance > 24 && drag.speed > 0.65 && performance.now() - drag.time < 100));
const destination = dismiss ? node.offsetHeight : 0;
const animation = node.animate([{ translate: `0 ${distance}px` }, { translate: `0 ${destination}px` }], {
duration: window.matchMedia("(prefers-reduced-motion: reduce)").matches ? 0 : dismiss ? 180 : 260,
easing: "cubic-bezier(0.2, 0, 0, 1)", fill: "forwards",
});
settleAnimation.current = animation;
const follow = () => {
paintBackdrop(parseFloat(getComputedStyle(node).getPropertyValue("translate").split(" ")[1]) || 0, node.offsetHeight);
backdropFrame.current = requestAnimationFrame(follow);
};
backdropFrame.current = requestAnimationFrame(follow);
animation.onfinish = () => {
cancelBackdropFrame();
node.style.translate = `0 ${destination}px`;
paintBackdrop(destination, node.offsetHeight);
if (!dismiss && dragBackdrop.current) {
const style = dragBackdrop.current.node.style;
for (const property of ["background-color", "backdrop-filter", "transition"]) style.removeProperty(property);
dragBackdrop.current = null;
}
animation.cancel();
settleAnimation.current = null;
if (dismiss) { suppressClick.current = false; button.click(); }
};
};
const inheritedLayoutAnchor = React.useContext(DialogLayoutContext);
const layoutAnchor = explicitLayoutAnchor ?? inheritedLayoutAnchor;
const [layout, setLayout] = React.useState<React.CSSProperties>();
@@ -114,13 +180,22 @@ const DialogContent = React.forwardRef<
}, [layoutAnchor, placement, centerInLayoutAnchor]);
const contentRef = React.useCallback((node: HTMLDivElement | null) => {
contentNode.current = node;
if (!node) {
settleAnimation.current?.cancel();
settleAnimation.current = null;
if (backdropFrame.current !== null) cancelAnimationFrame(backdropFrame.current);
backdropFrame.current = null;
dragBackdrop.current = null;
gesture.current = null;
}
setContainer(node);
if (typeof ref === "function") ref(node);
else if (ref) ref.current = node;
}, [ref]);
return (
<DialogPortal>
<DialogPortal container={portalContainer}>
<DialogPositionedContent
contained={!!portalContainer}
positionerStyle={layout}
placement={placement}
overlayClassName={overlayClassName}
@@ -136,9 +211,10 @@ const DialogContent = React.forwardRef<
modalSurfaceClassName,
"relative grid w-full max-w-lg gap-4 p-6 duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 motion-reduce:animate-none",
placement === "bottom"
? "mt-auto max-h-[85dvh] overflow-y-auto overscroll-contain rounded-t-modal pb-[max(1rem,env(safe-area-inset-bottom))] data-[state=open]:slide-in-from-bottom-4 data-[state=closed]:slide-out-to-bottom-4"
? "mt-auto max-h-[85dvh] overflow-y-auto overscroll-contain rounded-t-modal pb-[max(1rem,env(safe-area-inset-bottom))] data-[state=open]:slide-in-from-bottom-full data-[state=closed]:slide-out-to-bottom-full ease-[cubic-bezier(0.2,0,0,1)] duration-300"
: "my-auto origin-center rounded-modal data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",
className,
placement === "bottom" && "pt-9 transition-none",
)}
{...props}
>
@@ -146,8 +222,45 @@ const DialogContent = React.forwardRef<
{children}
</FloatingPortalContext.Provider>
{showCloseButton ? (
<DialogPrimitive.Close className={cn("absolute right-2.5 top-2.5 grid place-items-center rounded-full text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none", placement === "bottom" ? "h-11 w-11" : "h-7 w-7")}>
<X className="h-4 w-4" />
<DialogPrimitive.Close
onPointerDown={(event) => {
if (placement !== "bottom" || !event.isPrimary || event.button !== 0) return;
const node = contentNode.current;
const offset = node ? parseFloat(getComputedStyle(node).getPropertyValue("translate").split(" ")[1]) || 0 : 0;
cancelBackdropFrame();
settleAnimation.current?.cancel();
if (node) node.style.translate = `0 ${offset}px`;
const backdrop = node?.closest<HTMLElement>("[data-dialog-backdrop]");
if (backdrop && !dragBackdrop.current) {
const style = getComputedStyle(backdrop);
dragBackdrop.current = { node: backdrop, color: style.backgroundColor,
blur: parseFloat(style.getPropertyValue("backdrop-filter").match(/blur\(([^)]+)/)?.[1] ?? "0") || 0 };
backdrop.style.transition = "none";
backdrop.style.animation = "none";
}
suppressClick.current = false;
gesture.current = { id: event.pointerId, start: event.clientY - offset, y: event.clientY, time: performance.now(), speed: 0, moved: offset > 5 };
event.currentTarget.setPointerCapture(event.pointerId);
}}
onPointerMove={(event) => {
const drag = gesture.current;
if (!drag || drag.id !== event.pointerId) return;
const now = performance.now();
drag.speed = (event.clientY - drag.y) / Math.max(1, now - drag.time);
drag.y = event.clientY; drag.time = now;
drag.moved ||= Math.abs(drag.y - drag.start) > 5;
if (contentNode.current) {
const distance = Math.max(0, drag.y - drag.start);
contentNode.current.style.translate = `0 ${distance}px`;
paintBackdrop(distance, contentNode.current.offsetHeight);
}
}}
onPointerUp={(event) => finishDrag(event.currentTarget, event.pointerId, false)}
onPointerCancel={(event) => finishDrag(event.currentTarget, event.pointerId, true)}
onLostPointerCapture={(event) => finishDrag(event.currentTarget, event.pointerId, true)}
onClick={(event) => { if (suppressClick.current) { event.preventDefault(); suppressClick.current = false; } }}
className={cn("absolute grid place-items-center rounded-full text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none", placement === "bottom" ? "left-1/2 top-0 h-8 w-16 -translate-x-1/2 touch-none cursor-grab active:cursor-grabbing" : "right-2.5 top-2.5 h-7 w-7")}>
{placement === "bottom" ? <span aria-hidden="true" className="h-1 w-9 rounded-full bg-current opacity-40" /> : <X className="h-4 w-4" />}
<span className="sr-only">{t("common.close")}</span>
</DialogPrimitive.Close>
) : null}
@@ -12,6 +12,9 @@ export const modalOverlayClassName =
export const modalSurfaceClassName =
"outline-none bg-background text-foreground shadow-[0_12px_36px_rgba(15,23,42,0.12)] dark:bg-popover dark:shadow-[0_18px_44px_rgba(0,0,0,0.32)]";
export const sidePanelSurfaceClassName =
"side-panel-surface outline-none bg-background text-foreground dark:bg-popover overflow-hidden rounded-[24px]";
export const floatingSurfaceClassName =
`${floatingSurfaceVisualClassName} z-50 overflow-x-hidden overflow-y-auto overscroll-contain scrollbar-thin`;
+3 -2
View File
@@ -1,3 +1,4 @@
import { surfaceFocusProps } from "@/lib/surface-focus";
import { useCallback, useEffect, useRef, useState, type PointerEvent } from "react";
import { Minus, Plus } from "lucide-react";
import { useTranslation } from "react-i18next";
@@ -121,8 +122,8 @@ export function ImageViewport({
const buttonClass = "grid size-9 shrink-0 place-items-center rounded-full transition-colors hover:text-foreground disabled:opacity-30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring";
return <>
<div ref={viewport} data-testid={testId} tabIndex={0} role="group" aria-label={t("lightbox.gestures")}
className={cn("flex min-h-0 min-w-0 touch-none select-none items-center justify-center overflow-hidden focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring", view.scale > 1 ? dragging ? "cursor-grabbing" : "cursor-grab" : "cursor-zoom-in", className)}
<div ref={viewport} data-testid={testId} {...surfaceFocusProps} tabIndex={0} role="group" aria-label={t("lightbox.gestures")}
className={cn("flex min-h-0 min-w-0 touch-none select-none items-center justify-center overflow-hidden outline-none data-[keyboard-focus]:ring-1 data-[keyboard-focus]:ring-ring", view.scale > 1 ? dragging ? "cursor-grabbing" : "cursor-grab" : "cursor-zoom-in", className)}
onPointerDown={onPointerDown} onPointerMove={onPointerMove} onPointerUp={endPointer} onPointerCancel={endPointer} onLostPointerCapture={endPointer}
onDoubleClick={(event) => zoom(viewRef.current.scale > 1 ? 1 : 2, { x: event.clientX, y: event.clientY })}
onKeyDown={(event) => {
+11 -8
View File
@@ -5,6 +5,7 @@ import { cva, type VariantProps } from "class-variance-authority";
import { useTranslation } from "react-i18next";
import { cn } from "@/lib/utils";
import { modalOverlayClassName, sidePanelSurfaceClassName } from "./floating-surface";
const Sheet = DialogPrimitive.Root;
const SheetTrigger = DialogPrimitive.Trigger;
@@ -29,7 +30,7 @@ const SheetOverlay = React.forwardRef<
SheetOverlay.displayName = DialogPrimitive.Overlay.displayName;
const sheetVariants = cva(
"fixed z-50 flex flex-col gap-4 bg-background outline-none transition ease-in-out",
"fixed z-50 flex flex-col gap-4 bg-background outline-none ease-out",
{
variants: {
side: {
@@ -42,12 +43,14 @@ const sheetVariants = cva(
"data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",
),
left: cn(
"inset-y-0 left-0 h-full w-3/4 sm:max-w-sm",
"data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left",
"inset-y-2 left-2 w-3/4 max-w-[calc(100vw-1rem)] sm:max-w-sm",
sidePanelSurfaceClassName,
"data-[state=closed]:slide-out-to-left-4 data-[state=open]:slide-in-from-left-4",
),
right: cn(
"inset-y-0 right-0 h-full w-3/4 sm:max-w-sm",
"data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right",
"inset-y-2 right-2 w-3/4 max-w-[calc(100vw-1rem)] sm:max-w-sm",
sidePanelSurfaceClassName,
"data-[state=closed]:slide-out-to-right-4 data-[state=open]:slide-in-from-right-4",
),
},
},
@@ -83,13 +86,13 @@ const SheetContent = React.forwardRef<
const { t } = useTranslation();
return (
<SheetPortal>
<SheetOverlay className={overlayClassName} />
<SheetOverlay className={cn((side === "right" || side === "left") && modalOverlayClassName, overlayClassName)} />
<DialogPrimitive.Content
ref={ref}
className={cn(
sheetVariants({ side }),
"data-[state=open]:animate-in data-[state=closed]:animate-out",
"duration-300 motion-reduce:transition-none",
"data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 duration-200 motion-reduce:transition-none",
"motion-reduce:data-[state=open]:animate-none motion-reduce:data-[state=closed]:animate-none",
className,
)}
@@ -99,7 +102,7 @@ const SheetContent = React.forwardRef<
{showCloseButton ? (
<DialogPrimitive.Close
className={cn(
"absolute right-4 top-4 rounded-mark opacity-70 ring-offset-background transition-opacity",
"absolute right-2 top-2 grid size-10 place-items-center rounded-full opacity-70 ring-offset-background transition-opacity",
"hover:opacity-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
"disabled:pointer-events-none",
closeButtonClassName,
+68
View File
@@ -0,0 +1,68 @@
import { createContext, forwardRef, useCallback, useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type HTMLAttributes, type ReactNode } from "react";
import { useReducedMotion } from "motion/react";
import { cn } from "@/lib/utils";
interface SidebarPanelProps extends HTMLAttributes<HTMLElement> {
header?: ReactNode;
width: number;
isClosing?: boolean;
open?: boolean;
floating?: boolean;
contentClassName?: string;
}
export const SidebarPanelActionsContext = createContext<HTMLElement | null>(null);
/** Retain the same surface through exit, including an interrupted close. */
export const SidebarPanel = forwardRef<HTMLElement, SidebarPanelProps>(function SidebarPanel({
open = true, isClosing, ...props
}, ref) {
const [present, setPresent] = useState(open);
const reducedMotion = useReducedMotion();
useEffect(() => {
if (open) { setPresent(true); return; }
const timer = window.setTimeout(() => setPresent(false), reducedMotion ? 0 : 300);
return () => window.clearTimeout(timer);
}, [open, reducedMotion]);
return open || present ? <SidebarPanelContent {...props} ref={ref} isClosing={isClosing || !open} /> : null;
});
/** Shared nonmodal side slot. Contents keep their final width while the slot opens. */
const SidebarPanelContent = forwardRef<HTMLElement, SidebarPanelProps>(function SidebarPanelContent({
width, isClosing = false, floating = false, header, contentClassName, className, style, children, ...props
}, forwardedRef) {
const panel = useRef<HTMLElement | null>(null);
const [entered, setEntered] = useState(false);
const [actionsHost, setActionsHost] = useState<HTMLElement | null>(null);
const setPanel = useCallback((node: HTMLElement | null) => {
panel.current = node;
if (typeof forwardedRef === "function") forwardedRef(node);
else if (forwardedRef) forwardedRef.current = node;
}, [forwardedRef]);
useLayoutEffect(() => {
// Commit the outgoing slot width before transitioning to the replacement width.
panel.current?.getBoundingClientRect();
let frame = requestAnimationFrame(() => { frame = requestAnimationFrame(() => setEntered(true)); });
return () => cancelAnimationFrame(frame);
}, []);
return <aside {...props} ref={setPanel} data-closing={isClosing || undefined}
style={{
"--file-preview-width": `${width}px`,
"--file-preview-slot-width": isClosing ? "0px" : !entered ? "var(--sidebar-enter-width, 0px)" : `${width}px`,
"--file-preview-mobile-width": isClosing ? "0px" : !entered ? "var(--sidebar-enter-mobile-width, 0px)" : "100%",
...style,
} as CSSProperties}
className={cn("file-preview-pane z-30 min-h-0 w-[var(--file-preview-mobile-width)] overflow-hidden duration-300 ease-[cubic-bezier(0.2,0,0,1)] motion-reduce:transition-none",
entered ? "transition-[width]" : "transition-none",
floating ? "fixed inset-y-2 right-2 max-w-[420px]" : "absolute inset-y-0 right-0", isClosing && "pointer-events-none", className)}>
<div className={cn("file-preview-content absolute inset-y-2 right-2 flex min-h-0 w-[calc(100cqw-1rem)] flex-col pb-[env(safe-area-inset-bottom)] transition-[opacity,transform] duration-200 ease-out motion-reduce:transition-none",
floating && "w-[calc(min(420px,100vw)-1rem)]",
!entered || isClosing ? "translate-x-2 opacity-0" : "translate-x-0 opacity-100", contentClassName)}>
{header && <div className="flex min-h-10 shrink-0 items-center gap-1 border-b border-border/40 px-2 pt-2">
{header}
<div ref={setActionsHost} className="shrink-0" />
</div>}
<SidebarPanelActionsContext.Provider value={actionsHost}>{children}</SidebarPanelActionsContext.Provider>
</div>
</aside>;
});