Skip to content

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

Python

feat(native): edit a user bubble in place and resend

justrachb16e94387945
diff --git a/apps/native/components/site/ChatBubbles.tsx b/apps/native/components/site/ChatBubbles.tsx
index 64bd65b4..5e75ed96 100644
--- a/apps/native/components/site/ChatBubbles.tsx
+++ b/apps/native/components/site/ChatBubbles.tsx
@@ -58,10 +58,18 @@ function PastedImage({ name }: { name: string }) {
);
}
-export const UserBubble = memo(function UserBubble({ text, onEdit }: { text: string; onEdit?: () => void }) {
+export const UserBubble = memo(function UserBubble({ text, onEdit }: { text: string; onEdit?: (next: string) => void }) {
const parts = splitImageMarkers(text);
const images = parts.filter((_, index) => index % 2 === 1);
const words = parts.filter((_, index) => index % 2 === 0).join("");
+ const [editing, setEditing] = useState(false);
+ const [draft, setDraft] = useState(words);
+ const save = () => {
+ const next = draft.trim();
+ setEditing(false);
+ if (!next || next === words.trim() || !onEdit) return;
+ onEdit(next);
+ };
return (
<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">
@@ -69,12 +77,22 @@ export const UserBubble = memo(function UserBubble({ text, onEdit }: { text: str
{images.map((part, index) => <PastedImage key={`${index}-${part}`} name={markerName(part)} />)}
</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}
+ {onEdit && !editing && <button type="button" data-edit-prompt aria-label="Edit prompt" onClick={() => { setDraft(words); setEditing(true); }}
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
+ {editing ? <div className="flex min-w-[12rem] max-w-full flex-col items-end gap-1">
+ <textarea data-edit-prompt-draft value={draft} autoFocus rows={Math.min(8, Math.max(2, draft.split("\n").length))}
+ onChange={e => setDraft(e.target.value)}
+ onKeyDown={e => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); save(); } if (e.key === "Escape") setEditing(false); }}
+ className="min-w-0 w-full resize-y rounded-xl px-3.5 py-2 text-[13px] leading-relaxed text-ink shadow-hairline outline-none"
+ style={{ background: "color-mix(in oklab, var(--accent) 12%, var(--surface))" }} />
+ <div className="flex gap-1 text-[10px] text-ink-3">
+ <button type="button" onClick={() => setEditing(false)} className="rounded px-1.5 py-0.5 hover:text-ink">Cancel</button>
+ <button type="button" onClick={save} className="rounded px-1.5 py-0.5 text-ink hover:text-ink">Send</button>
+ </div>
+ </div> : <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}</div>}
</div>}
</div>
</div>
diff --git a/apps/native/components/site/ChatTranscript.tsx b/apps/native/components/site/ChatTranscript.tsx
index e0e08808..8cb31f38 100644
--- a/apps/native/components/site/ChatTranscript.tsx
+++ b/apps/native/components/site/ChatTranscript.tsx
@@ -9,7 +9,7 @@ import { transcriptPageStart } from "@/lib/transcript-window";
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;
+ onEditPrompt?: (n: number, text: string) => void; // n is 1-based user prompt index; text is the replacement
}) {
const scroller = useRef<HTMLDivElement>(null);
const registerScroller = useCallback((element: HTMLDivElement | null) => {
@@ -62,9 +62,9 @@ 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} onEdit={snapshot || !onEditPrompt ? undefined : () => {
+ : <UserBubble key={message.id} text={message.text} onEdit={snapshot || !onEditPrompt ? undefined : (next) => {
const n = messages.slice(0, start + index + 1).filter(m => m.role === "user" && m.origin !== "notification").length;
- onEditPrompt(n, message.text);
+ onEditPrompt(n, next);
}} />
: <AssistantBody key={message.id} turn={message.turn} onOpenPath={onOpenPath} onReview={onReview}
scroller={scroller} following={following && start + index === messages.length - 1} snapshot={snapshot} />)}
diff --git a/apps/native/components/site/GraffHarness.tsx b/apps/native/components/site/GraffHarness.tsx
index 9c58ea77..46e022f3 100644
--- a/apps/native/components/site/GraffHarness.tsx
+++ b/apps/native/components/site/GraffHarness.tsx
@@ -96,8 +96,6 @@ 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));
}, []);
@@ -232,9 +230,7 @@ export default function GraffHarness() {
setQueue(chatId, enqueuePrompt(queuesRef.current[chatId] ?? [], trimmed, (queueIdRef.current += 1)));
return;
}
- const editing = editInject?.chat === chatId ? editInject.n : undefined;
- if (editing) setEditInject(null);
- await runPrompt(chatId, trimmed, editing ? { edit: editing } : undefined);
+ await runPrompt(chatId, trimmed);
};
const openChat = (id: number) => {
@@ -448,7 +444,12 @@ 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); }}
+ onEditPrompt={(n, text) => {
+ const live = sessionsRef.current.get(thread.id);
+ if (live) void cancel(handleOf(thread.id), live).catch(() => undefined);
+ runningRef.current.delete(thread.id);
+ void runPrompt(thread.id, text, { edit: n });
+ }}
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));
@@ -460,7 +461,6 @@ 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];