graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
feat(native): Edit button on user prompts
justrachfd3a67e69778
diff --git a/apps/native/components/primitives/PromptBar.tsx b/apps/native/components/primitives/PromptBar.tsxindex 735d547c..c514cf8d 100644--- a/apps/native/components/primitives/PromptBar.tsx+++ b/apps/native/components/primitives/PromptBar.tsx@@ -48,6 +48,7 @@ export default function PromptBar({history,root,contextMeter,+ inject,}: {variant?: string;/** the self-running walkthrough; turn off when embedding in a real surface */@@ -75,10 +76,17 @@ export default function PromptBar({* picked file is mentioned by its path relative to it. */root?: string;contextMeter?: import("@/lib/context-meter").ContextMeter;+ /** Load this text into the draft when `key` changes (edit-prompt). */+ inject?: { key: number; text: string } | null;}) {const pill = variant === "Pill";const catalog = models && models.length > 0 ? models : MODELS;const { draft, setDraft, attachments, setAttachments, uploads, setUploads, attachError, setAttachError } = useComposerDraft();+ useEffect(() => {+ if (!inject) return;+ setDraft(inject.text);+ setHistoryIndex(-1);+ }, [inject?.key]);/* Recall cursor: -1 is the live draft. Whatever was being typed is kept* aside so ArrowDown past the newest entry hands it back untouched. */const [historyIndex, setHistoryIndex] = useState(-1);diff --git a/apps/native/components/site/ChatBubbles.tsx b/apps/native/components/site/ChatBubbles.tsxindex 4892322c..64bd65b4 100644--- a/apps/native/components/site/ChatBubbles.tsx+++ b/apps/native/components/site/ChatBubbles.tsx@@ -58,20 +58,24 @@ function PastedImage({ name }: { name: string }) {);}-export const UserBubble = memo(function UserBubble({ text }: { text: string }) {+export const UserBubble = memo(function UserBubble({ text, onEdit }: { text: string; onEdit?: () => void }) {const parts = splitImageMarkers(text);const images = parts.filter((_, index) => index % 2 === 1);const words = parts.filter((_, index) => index % 2 === 0).join("");return (- <div data-user-bubble className="flex justify-end pl-10 sm:pl-24" style={{ animation: "fade-up 300ms cubic-bezier(0.23,1,0.32,1) both" }}>+ <div data-user-bubble className="group flex justify-end pl-10 sm:pl-24" style={{ animation: "fade-up 300ms cubic-bezier(0.23,1,0.32,1) both" }}><div className="flex min-w-0 max-w-full flex-col items-end gap-2">{images.length > 0 && <div aria-label="Attached images" className="flex max-w-full flex-wrap justify-end gap-2">{images.map((part, index) => <PastedImage key={`${index}-${part}`} name={markerName(part)} />)}</div>}- {words.trim() && <div- className="min-w-0 max-w-full whitespace-pre-wrap break-words rounded-xl px-3.5 py-2 text-[13px] leading-relaxed text-ink shadow-hairline [overflow-wrap:anywhere]"- style={{ background: "color-mix(in oklab, var(--accent) 12%, var(--surface))" }}- >{words}</div>}+ {words.trim() && <div className="flex max-w-full items-end gap-1">+ {onEdit && <button type="button" data-edit-prompt aria-label="Edit prompt" onClick={onEdit}+ className="mb-1 rounded-md px-1.5 py-0.5 text-[10px] text-ink-3 opacity-0 hover:text-ink group-hover:opacity-100">Edit</button>}+ <div+ className="min-w-0 max-w-full whitespace-pre-wrap break-words rounded-xl px-3.5 py-2 text-[13px] leading-relaxed text-ink shadow-hairline [overflow-wrap:anywhere]"+ style={{ background: "color-mix(in oklab, var(--accent) 12%, var(--surface))" }}+ >{words}</div>+ </div>}</div></div>);diff --git a/apps/native/components/site/ChatColumn.tsx b/apps/native/components/site/ChatColumn.tsxindex 6ba40eec..b01e5d28 100644--- a/apps/native/components/site/ChatColumn.tsx+++ b/apps/native/components/site/ChatColumn.tsx@@ -9,12 +9,12 @@ import PromptQueue from "./PromptQueue";import SavedSnapshot from "./SavedSnapshot";import type { Chat } from "./harness-types";-export default function ChatColumn({ thread, compact, following, register, onOpenPath, onReview,+export default function ChatColumn({ thread, compact, following, register, onOpenPath, onReview, onEditPrompt,prompt, queue, pins, onShowPins, onClearPins, health, onOpenProject, onProjects, onConversations,onRefresh, onContinue }: {thread: Chat; compact: boolean; following: boolean;register: (element: HTMLDivElement | null) => void;- onOpenPath: (path: string) => void; onReview: () => void;+ onOpenPath: (path: string) => void; onReview: () => void; onEditPrompt?: (n: number, text: string) => void;prompt: ComponentProps<typeof PromptBar> & Required<Pick<ComponentProps<typeof PromptBar>, "onSend" | "models" | "onModelChange">>;queue: ComponentProps<typeof PromptQueue>;pins: number; onShowPins: () => void; onClearPins: () => void;@@ -31,7 +31,7 @@ export default function ChatColumn({ thread, compact, following, register, onOpe</div>;return <div className="flex min-h-0 flex-1 flex-col"><ChatTranscript messages={thread.messages} register={register} following={following}- onOpenPath={onOpenPath} onReview={onReview} snapshot={thread.snapshot} />+ onOpenPath={onOpenPath} onReview={onReview} snapshot={thread.snapshot} onEditPrompt={onEditPrompt} /><div data-chat-composer className={`shrink-0 bg-page px-4 ${compact ? "py-2" : "pt-3 pb-6 sm:px-8"}`}><div className="mx-auto max-w-[720px]">{thread.snapshot && thread.session ? <SavedSnapshot name={thread.session} cwd={thread.cwd} model={prompt.modelKey}diff --git a/apps/native/components/site/ChatTranscript.tsx b/apps/native/components/site/ChatTranscript.tsxindex e15500e1..e0e08808 100644--- a/apps/native/components/site/ChatTranscript.tsx+++ b/apps/native/components/site/ChatTranscript.tsx@@ -6,9 +6,10 @@ import type { Msg } from "./harness-types";import { pinScrollerTail } from "@/lib/follow-scroll";import { transcriptPageStart } from "@/lib/transcript-window";-export default memo(function ChatTranscript({ messages, register, following, onOpenPath, onReview, snapshot }: {+export default memo(function ChatTranscript({ messages, register, following, onOpenPath, onReview, snapshot, onEditPrompt }: {messages: Msg[]; register: (element: HTMLDivElement | null) => void; following: boolean;onOpenPath: (path: string) => void; onReview: () => void; snapshot?: boolean;+ onEditPrompt?: (n: number, text: string) => void;}) {const scroller = useRef<HTMLDivElement>(null);const registerScroller = useCallback((element: HTMLDivElement | null) => {@@ -61,7 +62,10 @@ export default memo(function ChatTranscript({ messages, register, following, onO{messages.slice(start).map((message, index) => message.role === "user"? message.origin === "notification"? <SessionNotice key={message.id} text={message.text} />- : <UserBubble key={message.id} text={message.text} />+ : <UserBubble key={message.id} text={message.text} onEdit={snapshot || !onEditPrompt ? undefined : () => {+ const n = messages.slice(0, start + index + 1).filter(m => m.role === "user" && m.origin !== "notification").length;+ onEditPrompt(n, message.text);+ }} />: <AssistantBody key={message.id} turn={message.turn} onOpenPath={onOpenPath} onReview={onReview}scroller={scroller} following={following && start + index === messages.length - 1} snapshot={snapshot} />)}</div>diff --git a/apps/native/components/site/GraffHarness.tsx b/apps/native/components/site/GraffHarness.tsxindex ea39f17f..9c58ea77 100644--- a/apps/native/components/site/GraffHarness.tsx+++ b/apps/native/components/site/GraffHarness.tsx@@ -96,6 +96,8 @@ export default function GraffHarness() {// Shell-style prompt recall (ArrowUp in the composer), kept per browser so// a new tab or a reload still has the last prompts under the cursor.const [history, setHistory] = useState<string[]>([]);+ const [editInject, setEditInject] = useState<{ chat: number; key: number; n: number; text: string } | null>(null);+ const editKeyRef = useRef(0);useEffect(() => {setHistory(loadHistory(window.localStorage));}, []);@@ -230,7 +232,9 @@ export default function GraffHarness() {setQueue(chatId, enqueuePrompt(queuesRef.current[chatId] ?? [], trimmed, (queueIdRef.current += 1)));return;}- await runPrompt(chatId, trimmed);+ const editing = editInject?.chat === chatId ? editInject.n : undefined;+ if (editing) setEditInject(null);+ await runPrompt(chatId, trimmed, editing ? { edit: editing } : undefined);};const openChat = (id: number) => {@@ -444,6 +448,7 @@ export default function GraffHarness() {const columnBody = (thread: Chat) => <ChatColumn key={thread.id} thread={thread}compact={columnIds.length > 1 || navigation.focusedMode || filesOpen || browserOpen || agentsOpen || reviewsOpen || !!(fileRequest?.changes)} following={tailing[thread.id] ?? true} register={paneRef(thread.id)}onOpenPath={openPath} onReview={openChanges}+ onEditPrompt={(n, text) => { setEditInject({ chat: thread.id, key: ++editKeyRef.current, n, text }); requestPromptFocus(thread.id); }}onRefresh={loaded => {const messages: Msg[] = loaded.messages.map(m => ({ id: ++msgIdRef.current, ...m }));setChats(current => current.map(c => c.id === thread.id && c.snapshot ? { ...c, messages } : c));@@ -455,6 +460,7 @@ export default function GraffHarness() {prompt={{ demo: false, models, commands: commands[thread.id] ?? catalogCommands,root: cwdOf(thread), modelKey: thread.model ?? model ?? undefined,onModelChange: key => changeModel(key, thread.id), onSend: text => void send(text, thread.id),+ inject: editInject?.chat === thread.id ? { key: editInject.key, text: editInject.text } : null,onSetting: text => settings.change(thread.id, text),onSteerQueued: queues[thread.id]?.length ? () => {const next = queuesRef.current[thread.id]?.[0];diff --git a/apps/native/components/site/harness-prompt-runner.ts b/apps/native/components/site/harness-prompt-runner.tsindex b3960515..2c1b8acb 100644--- a/apps/native/components/site/harness-prompt-runner.ts+++ b/apps/native/components/site/harness-prompt-runner.ts@@ -36,7 +36,7 @@ export function createPromptRunner({onStarted, onCompleted, runningRef, steerer,);};- const runPrompt = async (chatId: number, trimmed: string) => {+ const runPrompt = async (chatId: number, trimmed: string, opts?: { edit?: number }) => {setCancelError(current => { const next = { ...current }; delete next[chatId]; return next; });runningRef.current.add(chatId);onStarted(chatId);@@ -49,21 +49,27 @@ export function createPromptRunner({onStarted, onCompleted, runningRef, steerer,const title = thread?.title ?? (trimmed.length > 30 ? `${trimmed.slice(0, 30).trimEnd()}…` : trimmed);// The first prompt of a tab names it, in the model's words.if (!thread?.title) nameChat(chatId, trimmed, thread?.cwd);+ const editN = opts?.edit;setChats((current) =>- current.map((c) =>- c.id !== chatId- ? c- : {- ...c,- title,- snapshot: undefined,- messages: [- ...c.messages,- { id: userId, role: "user", text: trimmed },- { id: asstId, role: "assistant", turn: { ...emptyTurn(), model: spawnModel, startedAt: Date.now() } },- ],- },- ),+ current.map((c) => {+ if (c.id !== chatId) return c;+ if (editN) {+ let seen = 0;+ const keep = [];+ for (const message of c.messages) {+ if (message.role === "user" && message.origin !== "notification") {+ seen += 1;+ if (seen === editN) { keep.push({ ...message, text: trimmed }); break; }+ }+ keep.push(message);+ }+ return { ...c, title, snapshot: undefined, messages: [...keep, { id: asstId, role: "assistant", turn: { ...emptyTurn(), model: spawnModel, startedAt: Date.now() } }] };+ }+ return {+ ...c, title, snapshot: undefined,+ messages: [...c.messages, { id: userId, role: "user", text: trimmed }, { id: asstId, role: "assistant", turn: { ...emptyTurn(), model: spawnModel, startedAt: Date.now() } }],+ };+ }),);setBusyFor(chatId, true);setHistory((current) => {@@ -86,6 +92,9 @@ export function createPromptRunner({onStarted, onCompleted, runningRef, steerer,const startedAt = Date.now();try {const id = await requireSession(chatId);+ if (editN) {+ for await (const _ of prompt(handleOf(chatId), id, `/edit ${editN} ${trimmed}`)) { /* rewind only */ }+ }turn = { ...turn, connected: true, lastUpdateAt: Date.now() };painter.update(turn);for await (const update of prompt(handleOf(chatId), id, wire)) {