Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

gui: coordinate aux-pane + chat resize so they glide together instead of snapping (#34)

Rach Pradhana06ce4edf59e
diff --git a/gui/src/components/workspace-board/AuxiliaryPaneShell.tsx b/gui/src/components/workspace-board/AuxiliaryPaneShell.tsx
index 396ef2e6..a34b0f72 100644
--- a/gui/src/components/workspace-board/AuxiliaryPaneShell.tsx
+++ b/gui/src/components/workspace-board/AuxiliaryPaneShell.tsx
@@ -19,7 +19,7 @@ const EXIT_FALLBACK_MS = 220;
/**
* Wraps an auxiliary dock pane (preview / changes / terminal) so its content
* crossfades in on mount and out on close, while the surrounding panes glide to
- * their new size (see `.cg-animate-layout` in chat-tile-dockview.css). Closing is
+ * their new size (driven from ChatTile via paneResizeAnimation.ts). Closing is
* driven by a window event ({@link PANE_CLOSE_REQUEST_EVENT_NAME}) so the pane can
* fade out before `api.close()` removes it from the layout.
*/
diff --git a/gui/src/components/workspace-board/ChatTile.tsx b/gui/src/components/workspace-board/ChatTile.tsx
index a2acfe8f..78ce4761 100644
--- a/gui/src/components/workspace-board/ChatTile.tsx
+++ b/gui/src/components/workspace-board/ChatTile.tsx
@@ -50,7 +50,10 @@ import {
dispatchTerminalRestartRequest,
INNER_CHAT_COMPONENT,
INNER_PLACEHOLDER_COMPONENT,
+ isTerminalPanelId,
PANE_CLOSE_REQUEST_EVENT_NAME,
+ PREVIEW_PANE_ID,
+ TERMINAL_PANE_ID,
} from "./layout";
import {
addTerminalTab,
@@ -69,6 +72,12 @@ import type {
TerminalPaneParams,
} from "./types/layout";
import type { ChatTileProps } from "./types/workspaceBoard";
+import {
+ animatePaneClose,
+ animatePaneOpen,
+ type PaneResizeTween,
+ type ResizeAxis,
+} from "./paneResizeAnimation";
import { applySavedConversationLayout } from "./utils/savedLayout";
import "./chat-tile-dockview.css";
@@ -122,12 +131,13 @@ export function ChatTile({
// confirmation dialog can warn the user. Closing a single terminal is normal
// toggle behavior; closing 2+ at once (each with its own PTY) is destructive.
const [closeTerminalsCount, setCloseTerminalsCount] = useState(0);
- // Briefly enables a width/position transition on the dock's view containers so
- // chat glides to its new size when a pane opens/closes (see chat-tile-dockview.css).
- // Toggled imperatively (not via state) so the class is in the DOM *before* the
- // synchronous dockview size mutation, otherwise the transition wouldn't fire.
+ // Drives the open/close size glide. When an auxiliary pane opens or closes we
+ // tween its dockview group's grid size (real layout, through dockview's public
+ // API) so the chat — the flexible sibling — reflows to its new size *together*
+ // with the pane instead of snapping in one frame. Held in a ref so a rapid
+ // re-toggle can cancel the in-flight tween. See ./paneResizeAnimation.
const shellRef = useRef<HTMLElement | null>(null);
- const layoutAnimateTimeoutRef = useRef<number | null>(null);
+ const paneTweenRef = useRef<PaneResizeTween | null>(null);
const innerApiRef = useRef<DockviewApi | null>(null);
const innerDisposablesRef = useRef<Array<{ dispose(): void }>>([]);
const fallbackToDefaultLayoutRef = useRef(false);
@@ -183,6 +193,8 @@ export function ChatTile({
window.cancelAnimationFrame(clearProgrammaticMutationRafRef.current);
clearProgrammaticMutationRafRef.current = null;
}
+ paneTweenRef.current?.cancel();
+ paneTweenRef.current = null;
};
}, []);
@@ -190,42 +202,97 @@ export function ChatTile({
schedulePersist(() => innerApiRef.current);
}, [schedulePersist]);
- // Turn on the dock's size transition for one open/close cycle so chat (and any
- // other panes) glide to their new size instead of snapping. The window covers
- // an exit fade (~180ms) plus the size transition (~320ms); re-toggling resets it.
- const runLayoutAnimation = useCallback(() => {
- const dock = shellRef.current?.querySelector(".chat-tile-inner-dock");
- if (dock == null) {
- return;
- }
- dock.classList.add("cg-animate-layout");
- if (layoutAnimateTimeoutRef.current != null) {
- window.clearTimeout(layoutAnimateTimeoutRef.current);
- }
- layoutAnimateTimeoutRef.current = window.setTimeout(() => {
- dock.classList.remove("cg-animate-layout");
- layoutAnimateTimeoutRef.current = null;
- }, 600);
- }, []);
+ // Open a pane and glide chat + the new pane to their final sizes together.
+ // dockview adds the pane and settles its target size synchronously, so we read
+ // that target back, shrink the pane to a sliver, then tween it (and thus chat,
+ // the flexible sibling) up to target. The programmatic-mutation guard is held
+ // for the whole tween so `autoCloseUndersizedSidePanes` doesn't close the pane
+ // while it grows up through the min-width threshold.
+ const runOpenPaneAnimation = useCallback(
+ (api: DockviewApi, kind: "preview" | "terminal" | "changes") => {
+ // A terminal that already exists just gets focused (no new group); only the
+ // first terminal opens a fresh "below" group worth animating.
+ const paneId =
+ kind === "changes"
+ ? CHANGES_PANE_ID
+ : kind === "preview"
+ ? PREVIEW_PANE_ID
+ : TERMINAL_PANE_ID;
+ const wasOpen =
+ kind === "terminal"
+ ? getTerminalPanels(api).length > 0
+ : api.getPanel(paneId) != null;
+
+ paneTweenRef.current?.cancel();
+ isProgrammaticMutationRef.current = true;
+ openChatTilePane(api, binding, kind);
+
+ const group = api.getPanel(paneId)?.group ?? null;
+ if (wasOpen || group == null) {
+ // Nothing newly opened to animate — release the guard on the next frame
+ // (matches withProgrammaticMutation) so the synchronous layout batch is
+ // still suppressed.
+ window.requestAnimationFrame(() => {
+ isProgrammaticMutationRef.current = false;
+ });
+ return;
+ }
+
+ // Preview/Changes open to chat's right (animate width); the first terminal
+ // opens below (animate height).
+ const axis: ResizeAxis = kind === "terminal" ? "height" : "width";
+ paneTweenRef.current = animatePaneOpen(group, axis, () => {
+ paneTweenRef.current = null;
+ // Defer to the next frame: under reduced motion animatePaneOpen calls
+ // this synchronously (no tween), and releasing the guard in the same tick
+ // as the addPanel above would let its synchronous onDidLayoutChange run
+ // autoCloseUndersizedSidePanes and close the pane just opened.
+ window.requestAnimationFrame(() => {
+ isProgrammaticMutationRef.current = false;
+ });
+ });
+ },
+ [binding],
+ );
// Any pane close (toolbar button or a terminal tab's ×) goes through the close
- // request event; animate the resulting reflow for this conversation's panes.
+ // request event. When the close removes the pane's whole group (chat will
+ // reflow to reclaim the space) glide that group down to a sliver so chat
+ // expands smoothly instead of snapping back. The pane's own fade-out
+ // (AuxiliaryPaneShell) runs over the same window and performs the real close;
+ // this only animates the surrounding reflow.
useEffect(() => {
function handleCloseRequest(event: Event) {
const paneId = (event as CustomEvent<{ paneId?: string }>).detail?.paneId;
- if (paneId != null && paneId.startsWith(`${binding.conversationId}:`)) {
- runLayoutAnimation();
+ const prefix = `${binding.conversationId}:`;
+ if (paneId == null || !paneId.startsWith(prefix)) {
+ return;
+ }
+ const api = innerApiRef.current;
+ if (api == null) {
+ return;
+ }
+ const dockviewPanelId = paneId.slice(prefix.length);
+ const panel = api.getPanel(dockviewPanelId);
+ // Only glide when closing the pane collapses its group (a lone changes /
+ // preview / last-terminal pane). Closing one terminal tab among several
+ // leaves the group — and chat's size — unchanged, so there's nothing to
+ // animate.
+ if (panel == null || panel.group.panels.length > 1) {
+ return;
}
+ const axis: ResizeAxis = isTerminalPanelId(dockviewPanelId)
+ ? "height"
+ : "width";
+ paneTweenRef.current?.cancel();
+ paneTweenRef.current = animatePaneClose(api, dockviewPanelId, axis);
}
window.addEventListener(PANE_CLOSE_REQUEST_EVENT_NAME, handleCloseRequest);
return () => {
window.removeEventListener(PANE_CLOSE_REQUEST_EVENT_NAME, handleCloseRequest);
- if (layoutAnimateTimeoutRef.current != null) {
- window.clearTimeout(layoutAnimateTimeoutRef.current);
- }
};
- }, [binding.conversationId, runLayoutAnimation]);
+ }, [binding.conversationId]);
const handleOpenPane = useCallback(
(kind: "preview" | "terminal" | "changes") => {
@@ -234,11 +301,10 @@ export function ChatTile({
return;
}
- runLayoutAnimation();
- withProgrammaticMutation(() => openChatTilePane(api, binding, kind));
+ runOpenPaneAnimation(api, kind);
scheduleInnerLayoutSave();
},
- [binding, runLayoutAnimation, scheduleInnerLayoutSave, withProgrammaticMutation],
+ [binding, runOpenPaneAnimation, scheduleInnerLayoutSave],
);
// Track which auxiliary panes are open so the header toggles can show an active
@@ -270,10 +336,9 @@ export function ChatTile({
return;
}
- runLayoutAnimation();
- withProgrammaticMutation(() => openChatTilePane(api, binding, "changes"));
+ runOpenPaneAnimation(api, "changes");
scheduleInnerLayoutSave();
- }, [binding, runLayoutAnimation, scheduleInnerLayoutSave, withProgrammaticMutation]);
+ }, [binding, runOpenPaneAnimation, scheduleInnerLayoutSave]);
const handleToggleTerminal = useCallback(() => {
const api = innerApiRef.current;
@@ -293,10 +358,9 @@ export function ChatTile({
return;
}
- runLayoutAnimation();
- withProgrammaticMutation(() => openChatTilePane(api, binding, "terminal"));
+ runOpenPaneAnimation(api, "terminal");
scheduleInnerLayoutSave();
- }, [binding, runLayoutAnimation, scheduleInnerLayoutSave, withProgrammaticMutation]);
+ }, [binding, runOpenPaneAnimation, scheduleInnerLayoutSave]);
const handleCloseAllTerminalsConfirm = useCallback(() => {
const api = innerApiRef.current;
diff --git a/gui/src/components/workspace-board/chat-tile-dockview.css b/gui/src/components/workspace-board/chat-tile-dockview.css
index a5117594..d24806b2 100644
--- a/gui/src/components/workspace-board/chat-tile-dockview.css
+++ b/gui/src/components/workspace-board/chat-tile-dockview.css
@@ -2,26 +2,12 @@
background: var(--pane-surface);
}
-/* When an auxiliary pane opens/closes, briefly animate the splitview view
- containers so the chat (and other panes) glide to their new size/position in
- sync with the pane's own fade/slide — otherwise the chat snaps instantly while
- only the new pane animates, which reads as a jump. The class is only present
- for a short window around programmatic open/close (toggled from ChatTile), so
- it never interferes with 1:1 sash dragging. */
-.chat-tile-inner-dock.cg-animate-layout .dv-view {
- transition:
- left 320ms cubic-bezier(0.16, 1, 0.3, 1),
- top 320ms cubic-bezier(0.16, 1, 0.3, 1),
- width 320ms cubic-bezier(0.16, 1, 0.3, 1),
- height 320ms cubic-bezier(0.16, 1, 0.3, 1);
-}
-
-@media (prefers-reduced-motion: reduce) {
- .chat-tile-inner-dock.cg-animate-layout .dv-view {
- transition: none;
- }
-}
-
+/* The open/close size glide is driven imperatively from ChatTile via dockview's
+ group `setSize` API (see ./paneResizeAnimation.ts), tweening the real grid
+ layout per frame so chat and the new pane reach their final sizes together.
+ A CSS transition on `.dv-view` is intentionally NOT used: dockview frequently
+ recreates those view elements on layout changes (so there is no baseline to
+ transition from), and a transition would also fight the per-frame size writes. */
.chat-tile-inner-dock {
--chat-tile-header-height: 2.375rem;
--chat-tile-header-padding-x: 0.375rem;
diff --git a/gui/src/components/workspace-board/paneResizeAnimation.ts b/gui/src/components/workspace-board/paneResizeAnimation.ts
new file mode 100644
index 00000000..33faca52
--- /dev/null
+++ b/gui/src/components/workspace-board/paneResizeAnimation.ts
@@ -0,0 +1,178 @@
+import type { DockviewApi, DockviewGroupPanel } from "dockview-react";
+
+// easeOutExpo — fast start, soft settle. Matches the chat-tile fade easings
+// (cubic-bezier(0.16, 1, 0.3, 1)) so the pane fade and the size glide feel like
+// one motion.
+function easeOutExpo(t: number): number {
+ return t >= 1 ? 1 : 1 - Math.pow(2, -10 * t);
+}
+
+const OPEN_DURATION_MS = 300;
+// Slightly shorter than the open glide and tuned to land as the pane's exit fade
+// (180ms in index.css) finishes, so the close reads as a single motion.
+const CLOSE_DURATION_MS = 180;
+// Start width/height the opening pane grows *from*. A few px (not 0) keeps the
+// pane's own content mounted/measurable while still reading as "slides open".
+const OPEN_START_PX = 8;
+// Width/height the closing pane shrinks *to* before it is removed. Left non-zero
+// so the splitview keeps a real view to animate instead of collapsing instantly.
+const CLOSE_END_PX = 4;
+
+export type ResizeAxis = "width" | "height";
+
+export interface PaneResizeTween {
+ /** Cancel the in-flight animation frame (does not revert sizes already set). */
+ cancel(): void;
+}
+
+function prefersReducedMotion(): boolean {
+ return (
+ typeof window !== "undefined" &&
+ typeof window.matchMedia === "function" &&
+ window.matchMedia("(prefers-reduced-motion: reduce)").matches
+ );
+}
+
+function setGroupSize(
+ group: DockviewGroupPanel,
+ axis: ResizeAxis,
+ value: number,
+): void {
+ group.api.setSize(
+ axis === "width" ? { width: value } : { height: value },
+ );
+}
+
+function getGroupSize(group: DockviewGroupPanel, axis: ResizeAxis): number {
+ const size = axis === "width" ? group.api.width : group.api.height;
+ return typeof size === "number" ? size : 0;
+}
+
+function noopTween(): PaneResizeTween {
+ return { cancel() {} };
+}
+
+/**
+ * Glide a freshly added pane's group open by tweening its grid size from a small
+ * start value up to the size dockview just settled it at. The chat (the flexible
+ * sibling) reflows to fill the remaining space, so chat and the new pane move to
+ * their final sizes together instead of the chat snapping in one frame.
+ *
+ * Call immediately after the `addPanel` that created `group` — `group.api`'s size
+ * already reflects the target layout at that point.
+ */
+export function animatePaneOpen(
+ group: DockviewGroupPanel,
+ axis: ResizeAxis,
+ onComplete?: () => void,
+): PaneResizeTween {
+ const target = getGroupSize(group, axis);
+ if (prefersReducedMotion() || target <= OPEN_START_PX) {
+ onComplete?.();
+ return noopTween();
+ }
+
+ let frame: number | null = null;
+ let start: number | null = null;
+ let done = false;
+ const finish = () => {
+ if (done) {
+ return;
+ }
+ done = true;
+ onComplete?.();
+ };
+ setGroupSize(group, axis, OPEN_START_PX);
+
+ const step = (now: number) => {
+ if (start == null) {
+ start = now;
+ }
+ const elapsed = now - start;
+ const t = Math.min(1, elapsed / OPEN_DURATION_MS);
+ const value = OPEN_START_PX + (target - OPEN_START_PX) * easeOutExpo(t);
+ setGroupSize(group, axis, value);
+ if (t < 1) {
+ frame = window.requestAnimationFrame(step);
+ } else {
+ frame = null;
+ finish();
+ }
+ };
+
+ frame = window.requestAnimationFrame(step);
+
+ return {
+ cancel() {
+ if (frame != null) {
+ window.cancelAnimationFrame(frame);
+ frame = null;
+ }
+ finish();
+ },
+ };
+}
+
+/**
+ * Glide the closing pane's group down to a sliver so the chat reflows back to
+ * full width/height smoothly instead of snapping back when the pane is removed.
+ * The pane's content fade-out (AuxiliaryPaneShell) runs over the same window and
+ * owns the actual `api.close()`; this only animates the surrounding reflow, so it
+ * never removes the pane itself (avoids double-close races with the shell).
+ *
+ * Each frame re-resolves the group by panel id and bails the moment the pane is
+ * gone, so it is safe even if the shell's `api.close()` lands mid-tween.
+ *
+ * Looks the group up by dockview panel id so the caller only needs the id from
+ * the close-request event.
+ */
+export function animatePaneClose(
+ api: DockviewApi,
+ dockviewPanelId: string,
+ axis: ResizeAxis,
+): PaneResizeTween {
+ const initialGroup = api.getPanel(dockviewPanelId)?.group ?? null;
+ if (initialGroup == null || prefersReducedMotion()) {
+ return noopTween();
+ }
+
+ const start = getGroupSize(initialGroup, axis);
+ if (start <= CLOSE_END_PX) {
+ return noopTween();
+ }
+
+ let frame: number | null = null;
+ let startedAt: number | null = null;
+
+ const step = (now: number) => {
+ const group = api.getPanel(dockviewPanelId)?.group ?? null;
+ if (group == null) {
+ // Pane already removed (shell's fade completed and closed it) — done.
+ frame = null;
+ return;
+ }
+ if (startedAt == null) {
+ startedAt = now;
+ }
+ const elapsed = now - startedAt;
+ const t = Math.min(1, elapsed / CLOSE_DURATION_MS);
+ const value = start + (CLOSE_END_PX - start) * easeOutExpo(t);
+ setGroupSize(group, axis, value);
+ if (t < 1) {
+ frame = window.requestAnimationFrame(step);
+ } else {
+ frame = null;
+ }
+ };
+
+ frame = window.requestAnimationFrame(step);
+
+ return {
+ cancel() {
+ if (frame != null) {
+ window.cancelAnimationFrame(frame);
+ frame = null;
+ }
+ },
+ };
+}
diff --git a/gui/src/styles/index.css b/gui/src/styles/index.css
index 4c35f50f..a79fdd6a 100644
--- a/gui/src/styles/index.css
+++ b/gui/src/styles/index.css
@@ -917,10 +917,10 @@
}
/* --- Auxiliary pane reveal (changes / preview / terminal) ---
- The pane's container is resized smoothly by animating the dockview view
- containers (see chat-tile-dockview.css `.cg-animate-layout`); the pane's own
- content just crossfades so the appearing/disappearing content reads cleanly
- against the surrounding panes gliding to their new size. */
+ The pane's container is resized smoothly by tweening its dockview group size
+ (see workspace-board/paneResizeAnimation.ts); the pane's own content just
+ crossfades so the appearing/disappearing content reads cleanly against the
+ surrounding panes gliding to their new size. */
@keyframes cg-pane-fade-in {
from {
opacity: 0;