graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
merge: origin/release/v0.0.285 (#727, #732, follow-tail, queue) with Streamdown and prompt recall
justrach70c710f05e29
diff --cc apps/native/components/site/ChatEmpty.tsxindex 00000000,754c6587..c11dc4abmode 000000,100644..100644--- a/apps/native/components/site/ChatEmpty.tsx+++ b/apps/native/components/site/ChatEmpty.tsx@@@ -1,0 -1,123 +1,127 @@@+ "use client";++ import { useEffect, useState, type CSSProperties } from "react";+ import PromptBar, { type PromptModel } from "@/components/primitives/PromptBar";+ import { STARTER_PROMPTS, type Health } from "@/lib/acp-client";++ function greeting(): string {+ const hour = new Date().getHours();+ if (hour < 5) return "Up late";+ if (hour < 12) return "Good morning";+ if (hour < 18) return "Good afternoon";+ return "Good evening";+ }++ const HOME_REVEAL = {+ offsetY: 23,+ blur: 17,+ duration: 800,+ easing: "cubic-bezier(0.16, 1, 0.3, 1)",+ };++ function homeRevealStyle(visible: boolean): CSSProperties {+ return {+ opacity: visible ? 1 : 0,+ transform: visible ? "translate3d(0, 0, 0)" : `translate3d(0, ${HOME_REVEAL.offsetY}px, 0)`,+ filter: visible ? "blur(0px)" : `blur(${HOME_REVEAL.blur}px)`,+ transition: ["opacity", "transform", "filter"]+ .map((property) => `${property} ${HOME_REVEAL.duration}ms ${HOME_REVEAL.easing}`)+ .join(", "),+ };+ }++ export default function EmptyState({+ onSend,+ health,+ offset,+ shuffle,+ models,+ modelKey,+ onModelChange,++ history,+ }: {+ onSend: (text: string) => void;+ health: Health | null;+ offset: number;+ shuffle: () => void;+ models: PromptModel[];+ modelKey?: string;+ onModelChange: (key: string) => void;++ /** Earlier prompts for ArrowUp recall in the composer. */++ history?: readonly string[];+ }) {+ const shown = [0, 1, 2].map((i) => STARTER_PROMPTS[(offset + i) % STARTER_PROMPTS.length]);+ const [stage, setStage] = useState(0);+ useEffect(() => {+ const timers = [+ setTimeout(() => setStage(1), 170),+ setTimeout(() => setStage(2), 330),+ setTimeout(() => setStage(3), 400),+ setTimeout(() => setStage(4), 550),+ ];+ return () => timers.forEach(clearTimeout);+ }, []);++ return (+ <div className="mx-auto flex min-h-full max-w-[720px] flex-col justify-center px-4 py-10 sm:px-8">+ <h1 className="text-[26px] font-normal tracking-[-0.02em] text-ink">+ <span className="home-reveal block text-ink-3" style={homeRevealStyle(stage >= 1)}>+ {greeting()}+ </span>+ <span className="home-reveal block" style={homeRevealStyle(stage >= 2)}>+ What should graff work on?+ </span>+ </h1>++ <div className="home-reveal relative mt-7" style={homeRevealStyle(stage >= 3)}>+ <PromptBar+ demo={false}+ tall+ placeholder="Ask graff to read, edit, or review this workspace…"+ models={models}+ modelKey={modelKey}+ onModelChange={onModelChange}+ onSend={onSend}+ disabled={health !== null && !health.ok}++ history={history}+ />+ {health && !health.ok && (+ <p className="mt-3 text-[12.5px] text-orange">+ graff acp is not reachable. From the repo root run{" "}+ <span className="font-mono text-ink">zig build</span>+ {health.detail ? ` — ${health.detail}` : ""}.+ </p>+ )}+ </div>++ <div className="home-reveal mt-6 flex flex-col" style={homeRevealStyle(stage >= 4)}>+ {shown.map((item) => (+ <button+ key={item.id}+ type="button"+ onClick={() => onSend(item.prompt)}+ className="-mx-2 flex items-center gap-3 rounded-control px-2 py-2.5 text-left text-[14px] text-ink transition-colors duration-150 hover:bg-hover"+ >+ <span className="text-ink-3">+ <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round" strokeLinejoin="round" aria-hidden>+ <path d="M8 6l-5 6 5 6M16 6l5 6-5 6" />+ </svg>+ </span>+ <span className="min-w-0 truncate">{item.label}</span>+ </button>+ ))}+ <div className="mt-1 flex items-center gap-5 pl-0.5 text-[13px] text-ink-3">+ <span className="flex items-center gap-2 py-1" title={health?.cwd}>+ <span className={`size-1.5 rounded-full ${health?.ok ? "bg-green" : "bg-orange"}`} />+ {health?.ok+ ? `Connected · ${health.cwd ? (health.cwd.split("/").pop() ?? health.cwd) : "over ACP"}`+ : "Waiting for graff acp"}+ </span>+ <button type="button" onClick={shuffle} className="flex items-center gap-2 py-1 transition-colors duration-150 hover:text-ink">+ Shuffle suggestions+ </button>+ </div>+ </div>+ </div>+ );+ }diff --cc apps/native/components/site/GraffHarness.tsxindex 88890dda,10ffde5b..42a763b3--- a/apps/native/components/site/GraffHarness.tsx+++ b/apps/native/components/site/GraffHarness.tsx@@@ -1,7 -1,6 +1,6 @@@"use client";- import { memo, useCallback, useEffect, useMemo, useRef, useState, type CSSProperties } from "react";- import Markdown from "@/components/primitives/Markdown";-import { useCallback, useEffect, useRef, useState } from "react";++import { useCallback, useEffect, useMemo, useRef, useState } from "react";import PromptBar, { type PromptModel } from "@/components/primitives/PromptBar";import SidebarNav from "@/components/primitives/SidebarNav";import FilesPane from "@/components/site/FilesPane";@@@ -24,220 -23,10 +23,11 @@@ importtype Health,} from "@/lib/acp-client";import { applyAcpUpdate, emptyTurn, finishAcpTurn, type AssistantTurn } from "@/lib/acp";+ import { isFollowingTail, pinScrollerTail } from "@/lib/follow-scroll";+ import { dropQueuedPrompt, enqueuePrompt, shiftQueuedPrompt, type QueuedPrompt } from "@/lib/prompt-queue";import { dateGroup, listSessions, loadSession, relativeTime, type StoredSession } from "@/lib/sessions";+import { loadHistory, mergeHistory, pushHistory, saveHistory } from "@/lib/prompt-history";- const NAME = "there";-- function greeting(): string {- const hour = new Date().getHours();- if (hour < 5) return "Up late";- if (hour < 12) return "Good morning";- if (hour < 18) return "Good afternoon";- return "Good evening";- }-- /** Typewriter reveal over the ACP text, the way every AI app streams: a- * readable base rate with gentle backlog catch-up (capped so a one-shot- * final answer still visibly types out), and the drain keeps playing after- * the turn's result lands — done-state chrome waits for the last word.- * Mounted mid-history it starts caught-up, so old messages never replay. */- function useSmoothStream(target: string): string {- const [shown, setShown] = useState(target);- const shownRef = useRef(target);- useEffect(() => {- if (!target.startsWith(shownRef.current)) {- shownRef.current = target;- setShown(target);- return;- }- if (target === shownRef.current) return;- let raf = 0;- let last = performance.now();- const tick = (now: number) => {- const dt = Math.min(now - last, 100);- last = now;- const behind = target.length - shownRef.current.length;- if (behind <= 0) return;- const rate = Math.min(160 + behind * 1.2, 2400); // chars/second- const step = Math.max(1, Math.round((rate * dt) / 1000));- shownRef.current = target.slice(0, shownRef.current.length + step);- setShown(shownRef.current);- if (shownRef.current.length < target.length) raf = requestAnimationFrame(tick);- };- raf = requestAnimationFrame(tick);- return () => cancelAnimationFrame(raf);- }, [target]);- return shown;- }-- const HOME_REVEAL = {- offsetY: 23,- blur: 17,- duration: 800,- easing: "cubic-bezier(0.16, 1, 0.3, 1)",- };-- function homeRevealStyle(visible: boolean): CSSProperties {- return {- opacity: visible ? 1 : 0,- transform: visible ? "translate3d(0, 0, 0)" : `translate3d(0, ${HOME_REVEAL.offsetY}px, 0)`,- filter: visible ? "blur(0px)" : `blur(${HOME_REVEAL.blur}px)`,- transition: ["opacity", "transform", "filter"]- .map((property) => `${property} ${HOME_REVEAL.duration}ms ${HOME_REVEAL.easing}`)- .join(", "),- };- }-- /* Rows are memoized: a chunk landing in the live turn replaces that one- * message's `turn`, and every other row keeps its props — without memo the- * whole thread re-rendered (and re-parsed its markdown) per ACP update. */- const UserBubble = memo(function UserBubble({ text }: { text: string }) {- return (- <div className="flex justify-end pl-10 sm:pl-24" style={{ animation: "fade-up 300ms cubic-bezier(0.23,1,0.32,1) both" }}>- <div- className="rounded-xl px-3.5 py-2 text-[13px] leading-relaxed text-ink shadow-hairline"- style={{ background: "color-mix(in oklab, var(--accent) 12%, var(--surface))" }}- >- {text}- </div>- </div>- );- });-- const AssistantBody = memo(function AssistantBody({- turn,- onOpenPath,- onReview,- }: {- turn: AssistantTurn;- onOpenPath?: (path: string) => void;- /** Open the workspace changes review (the Codex "Changed N files" bar). */- onReview?: () => void;- }) {- const thinking = turn.status === "thinking";- const smoothText = useSmoothStream(turn.text);- const draining = smoothText.length < turn.text.length;- // "Thought for Ns": the harness stamps `thoughtMs` on the turn as it streams- // (ACP updates carry no timestamps); a live turn without one yet is timed here.- const startRef = useRef(Date.now());- const [thoughtSecs, setThoughtSecs] = useState<number | null>(- turn.thoughtMs !== undefined ? Math.max(1, Math.round(turn.thoughtMs / 1000)) : null,- );- useEffect(() => {- if (thinking) return;- setThoughtSecs((current) => {- if (current !== null) return current;- const ms = turn.thoughtMs ?? Date.now() - startRef.current;- return Math.max(1, Math.round(ms / 1000));- });- }, [thinking, turn.thoughtMs]);- const reasoningRows = turn.reasoning- ? turn.reasoning- .split(/\n+/)- .map((line) => line.trim())- .filter(Boolean)- .map((primary) => ({ primary }))- : [];- const toolRows = turn.tools.map((tool) => ({- id: tool.id,- icon: tool.icon,- label: tool.name,- chip: tool.chip,- mono: tool.icon === "run" || tool.icon === "write" || tool.icon === "read",- detailMono: tool.icon === "run" || tool.icon === "write",- detail: tool.detail,- path: tool.path,- status: tool.status,- startedAt: tool.startedAt,- elapsedMs: tool.elapsedMs,- }));-- return (- <article className="min-w-0" style={{ animation: "fade-up 450ms cubic-bezier(0.23,1,0.32,1) both" }}>- {/* 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) && (- <ThinkingState- variant="Reasoning"- rows={reasoningRows.length ? reasoningRows : [{ primary: "Waiting on the model…", shimmer: true }]}- activeLabel={turn.model ? `Thinking · ${turn.model}` : "Thinking"}- doneLabel={thoughtSecs ? `Thought for ${thoughtSecs}s` : "Thought"}- working={thinking}- />- )}- {toolRows.length > 0 && (- <div className="mt-4">- <ToolChips rows={toolRows} diffs={turn.diffs} onOpenPath={onOpenPath} />- </div>- )}- {turn.status === "streaming" && !turn.text ? (- /* Between the last tool and the first text token nothing streams —- * a lone caret here read as "stuck". Shimmer like the thinking- * header, and say which phase the agent is actually in. */- <div className="mt-4">- <span- className="bg-clip-text text-[13px] font-medium whitespace-nowrap text-transparent"- style={{- backgroundImage: "linear-gradient(90deg, var(--ink-3) 35%, var(--ink) 50%, var(--ink-3) 65%)",- backgroundSize: "200% 100%",- animation: "shimmer-text 1.4s linear infinite",- }}- >- {turn.tools.some((tool) => tool.status === "running") ? "Running tools…" : "Writing…"}- </span>- </div>- ) : (- turn.text && (- <div className="mt-4 max-w-[630px]">- <Markdown- text={smoothText}- streaming={draining || turn.status === "streaming" || turn.status === "thinking"}- onOpenPath={onOpenPath}- />- </div>- )- )}- {turn.error && (- <p className="mt-4 max-w-[620px] text-[13.5px] leading-[1.65] text-red">{turn.error}</p>- )}- {turn.recap && turn.status === "done" && !draining && (- <p className="mt-3 text-[12px] text-ink-3">{turn.recap}</p>- )}- {turn.costUsd !== undefined && turn.status === "done" && !draining && (- <p className="mt-1 font-mono text-[11px] text-ink-3">${turn.costUsd.toFixed(4)}</p>- )}- {turn.status === "done" && !draining && turn.diffs.length > 0 && onReview && (- <button- type="button"- onClick={onReview}- className="mt-4 flex h-9 w-full max-w-[630px] items-center gap-2 rounded-[10px] bg-surface px-3 text-left shadow-btn transition-colors duration-100 hover:bg-hover"- style={{ animation: "fade-up 300ms cubic-bezier(0.23,1,0.32,1) both" }}- >- <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="shrink-0 text-ink-3" aria-hidden>- <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />- <path d="M14 2v6h6" />- </svg>- <span className="text-[12.5px] font-medium text-ink">- Changed {turn.diffs.length} file{turn.diffs.length === 1 ? "" : "s"}- </span>- <span className="font-mono text-[11.5px] tabular-nums">- <span className="text-green">+{turn.diffs.reduce((n, d) => n + d.add, 0)}</span>{" "}- <span className="text-red">−{turn.diffs.reduce((n, d) => n + d.del, 0)}</span>- </span>- <span className="ml-auto flex items-center gap-0.5 text-[12.5px] font-medium text-ink-2">- Review- <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" aria-hidden>- <path d="M9 18l6-6-6-6" />- </svg>- </span>- </button>- )}- </article>- );- });-type Msg =| { id: number; role: "user"; text: string }| { id: number; role: "assistant"; turn: AssistantTurn };@@@ -426,12 -96,10 +103,16 @@@ export default function GraffHarness()const setChatModel = (chatId: number, key: string) =>setChats((current) => current.map((c) => (c.id === chatId ? { ...c, model: key } : c)));const lastAssistant = [...chatThread.messages].reverse().find((m): m is Extract<Msg, { role: "assistant" }> => m.role === "assistant");+ // A resumed session's prompts came from its file, not this browser; fold+ // them in so ArrowUp walks the conversation on screen first.+ const composerHistory = useMemo(+ () => mergeHistory(history, chatThread.messages.flatMap((m) => (m.role === "user" ? [m.text] : []))),+ [history, chatThread.messages],+ );+ const setQueue = (chatId: number, list: QueuedPrompt[]) => {+ queuesRef.current = { ...queuesRef.current, [chatId]: list };+ setQueues(queuesRef.current);+ };const adoptCatalog = async (chatId: number) => {// What did the agent actually resolve? The picker should show graff's@@@ -568,16 -236,15 +249,20 @@@),);setBusyFor(chatId, true);+ setHistory((current) => {+ const next = pushHistory(current, trimmed);+ saveHistory(window.localStorage, next);+ return next;+ });- let turn: AssistantTurn = { ...emptyTurn(), model: chatModel };+ let turn: AssistantTurn = { ...emptyTurn(), model: spawnModel };const startedAt = Date.now();- const frames = frameCoalescer<AssistantTurn>((next) => patchAssistant(chatId, asstId, next));try {const id = await requireSession(chatId);+ // Paint at most once per frame. ACP text/tool events can arrive dozens+ // of times per 16ms; each setChats used to re-parse every settled+ // markdown block in the thread.+ let paint = 0;+ const turnRef = { current: turn };for await (const update of prompt(handleOf(chatId), id, trimmed)) {turn = applyAcpUpdate(turn, update);if (turn.thoughtMs === undefined && turn.status !== "thinking") turn = { ...turn, thoughtMs: Date.now() - startedAt };@@@ -825,8 -518,6 +536,7 @@@modelKey={chatModel}onModelChange={changeModel}onSend={send}- disabled={busy}+ history={composerHistory}busy={busy}onStop={() => {const live = sessionsRef.current.get(chatThread.id);diff --cc apps/native/package.jsonindex 53d05f11,d890249a..bbd7075c--- a/apps/native/package.json+++ b/apps/native/package.json@@@ -10,10 -10,9 +10,10 @@@"start": "NEXT_TELEMETRY_DISABLED=1 next start --port 3000","mock-serve": "node scripts/mock-serve.mjs","lint": "next lint",- "test": "node --experimental-strip-types --test lib/graff-events.test.ts lib/acp.test.ts lib/sessions.test.ts lib/prompt-history.test.ts"- "test": "node --experimental-strip-types --test lib/graff-events.test.ts lib/acp.test.ts lib/sessions.test.ts lib/follow-scroll.test.ts lib/prompt-queue.test.ts"++ "test": "node --experimental-strip-types --test lib/graff-events.test.ts lib/acp.test.ts lib/sessions.test.ts lib/follow-scroll.test.ts lib/prompt-queue.test.ts lib/prompt-history.test.ts"},"dependencies": {+ "@streamdown/code": "^1.1.1","glimm": "^0.3.0","iconoir-react": "^7.11.1","liveline": "^0.0.7",