graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix(native): stop the thinking trace twitching while the model reasons
justrach062cb183356a
diff --git a/apps/native/components/primitives/ThinkingState.tsx b/apps/native/components/primitives/ThinkingState.tsxindex 13ff247c..67f3e771 100644--- a/apps/native/components/primitives/ThinkingState.tsx+++ b/apps/native/components/primitives/ThinkingState.tsx@@ -138,9 +138,28 @@ export default function ThinkingState({const traceRef = useRef<HTMLDivElement>(null);const [lineHeight, setLineHeight] = useState(0);useLayoutEffect(() => {- if (traceRef.current) setLineHeight(traceRef.current.offsetHeight);+ const el = traceRef.current;+ if (!el) return;+ setLineHeight(el.offsetHeight);+ // A live reasoning row grows as it streams (wrapping to new lines without+ // adding a row), so the guide line has to track the trace's real height,+ // not just the row count.+ if (typeof ResizeObserver === "undefined") return;+ const ro = new ResizeObserver(() => setLineHeight(el.offsetHeight));+ ro.observe(el);+ return () => ro.disconnect();}, [visible, expanded, variant, stage]);+ /* Live rows are keyed by position and only the rows that were not there on+ * the previous render get the entrance animation. Keying by text replayed+ * fade-up on the last row every time a token extended it — the trace+ * twitched for the whole think. */+ const animatedRef = useRef(0);+ const firstNewRow = live ? animatedRef.current : 0;+ useEffect(() => {+ animatedRef.current = visible;+ }, [visible]);+/* let embedders sequence content after the trace settles */const settledRef = useRef(false);useEffect(() => {@@ -277,12 +296,16 @@ export default function ThinkingState({</>);const rowClass = "flex min-h-7 w-full items-center gap-2 rounded-[6px] px-1.5 py-0.5 text-left";- const animation = { animation: `fade-up 320ms cubic-bezier(0.23,1,0.32,1) ${i * 120}ms both` };+ const key = live ? i : row.primary;+ const animation =+ i >= firstNewRow+ ? { animation: `fade-up 320ms cubic-bezier(0.23,1,0.32,1) ${live ? 0 : i * 120}ms both` }+ : undefined;if (variant === "Search") {return (<a- key={row.primary}+ key={key}href={row.href}target="_blank"rel="noreferrer"@@ -298,7 +321,7 @@ export default function ThinkingState({const selected = selectedTool === row.primary;return (<button- key={row.primary}+ key={key}type="button"aria-pressed={selected}onClick={() => setSelectedTool(selected ? null : row.primary)}@@ -311,7 +334,7 @@ export default function ThinkingState({}return (- <div key={row.primary} className={rowClass} style={animation}>+ <div key={key} className={rowClass} style={animation}>{content}</div>);diff --git a/apps/native/components/site/GraffHarness.tsx b/apps/native/components/site/GraffHarness.tsxindex a5d51c29..25f4404e 100644--- a/apps/native/components/site/GraffHarness.tsx+++ b/apps/native/components/site/GraffHarness.tsx@@ -157,7 +157,10 @@ function AssistantBody({return (<article ref={articleRef} className="min-w-0" style={{ animation: "fade-up 450ms cubic-bezier(0.23,1,0.32,1) both" }}>- {(thinking || reasoningRows.length > 0) && (+ {/* Keep the header once the model has actually thought (streamed+ * reasoning, or a think long enough to notice): unmounting it when the+ * think ends made the answer jump up into the space it left. */}+ {(thinking || reasoningRows.length > 0 || (turn.thoughtMs ?? 0) >= 1500) && (<ThinkingStatevariant="Reasoning"rows={reasoningRows.length ? reasoningRows : [{ primary: "Waiting on the model…", shimmer: true }]}@@ -615,11 +618,23 @@ export default function GraffHarness() {void openStored(id);};+ // A new message glides the thread to the bottom; streaming growth (reasoning,+ // text, tool rows) follows instantly and only while the reader is already at+ // the tail. Re-issuing a *smooth* scroll on every chunk restarted the scroll+ // animation each token — the whole thread juddered while the model thought.+ const messageCount = chatThread.messages.length;useEffect(() => {if (!active) return;const el = scrollRef.current;if (el) el.scrollTo({ top: el.scrollHeight, behavior: "smooth" });- }, [chatThread.messages, active, lastAssistant?.turn.text, lastAssistant?.turn.tools.length]);+ }, [messageCount, activeId, active]);+ useEffect(() => {+ if (!active) return;+ const el = scrollRef.current;+ if (!el) return;+ const fromBottom = el.scrollHeight - el.scrollTop - el.clientHeight;+ if (fromBottom < 160) el.scrollTop = el.scrollHeight;+ }, [active, lastAssistant?.turn.text, lastAssistant?.turn.reasoning, lastAssistant?.turn.tools.length]);// The sidebar is graff's session directory, newest first, bucketed by day.const now = Date.now();