graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
GUI: paste images into the composer with Cmd/Ctrl+V (native vision)
Rach Pradhanccb6b587dfa0
diff --git a/gui/src-tauri/src/commands.rs b/gui/src-tauri/src/commands.rsindex 4ebc1f58..7effa14a 100644--- a/gui/src-tauri/src/commands.rs+++ b/gui/src-tauri/src/commands.rs@@ -249,6 +249,25 @@ pub(crate) async fn set_fast(.map_err(map_command_error)}+/// Persists a clipboard-pasted image to a temp file and returns its path, so it+/// can flow through the same attachment pipeline as drag-dropped files (the+/// harness reads image attachments by path). Used by Cmd/Ctrl+V in the composer.+#[tauri::command]+pub(crate) async fn save_pasted_image(data: Vec<u8>, ext: String) -> Result<String, String> {+ use std::sync::atomic::{AtomicU64, Ordering};+ static COUNTER: AtomicU64 = AtomicU64::new(0);+ let n = COUNTER.fetch_add(1, Ordering::Relaxed);+ let safe_ext = match ext.to_lowercase().as_str() {+ "png" | "jpg" | "jpeg" | "gif" | "webp" | "bmp" | "avif" => ext.to_lowercase(),+ _ => "png".to_string(),+ };+ let dir = std::env::temp_dir().join("codegraff-pasted");+ std::fs::create_dir_all(&dir).map_err(|error| error.to_string())?;+ let path = dir.join(format!("paste-{}-{n}.{safe_ext}", std::process::id()));+ std::fs::write(&path, &data).map_err(|error| error.to_string())?;+ Ok(path.to_string_lossy().into_owned())+}+#[tauri::command]pub(crate) async fn set_active_agent(agent_id: String,diff --git a/gui/src-tauri/src/lib.rs b/gui/src-tauri/src/lib.rsindex 138fd3ae..0b9f49be 100644--- a/gui/src-tauri/src/lib.rs+++ b/gui/src-tauri/src/lib.rs@@ -35,7 +35,7 @@ use commands::{pick_directory, pick_workspace, push_git_branch, quick_start_project, reload_mcp_servers,remove_mcp_server, remove_provider, rename_saved_workspace, rename_workspace, respond_followup,run_slash_command, save_conversation_layout, select_conversation, send_prompt,- set_active_agent, set_effort, set_fast, start_new_chat, start_provider_auth, stop_prompt, terminal_close,+ save_pasted_image, set_active_agent, set_effort, set_fast, start_new_chat, start_provider_auth, stop_prompt, terminal_close,terminal_open, terminal_resize, terminal_write, update_prompt_settings,update_saved_workspace_layout, workspace_query, workspace_sync,};@@ -103,6 +103,7 @@ pub fn run() {set_active_agent,set_effort,set_fast,+ save_pasted_image,list_mcp_servers,import_mcp_config,remove_mcp_server,diff --git a/gui/src/components/PromptInputCard.tsx b/gui/src/components/PromptInputCard.tsxindex f82c73f6..4601cbc7 100644--- a/gui/src/components/PromptInputCard.tsx+++ b/gui/src/components/PromptInputCard.tsx@@ -37,7 +37,7 @@ import { useAttachments } from "@/hooks/useSession";import { useCommandAutocomplete } from "@/hooks/useCommandAutocomplete";import { useDropZone } from "@/hooks/useFileDrop";import { usePromptModelPicker } from "@/hooks/usePromptModelPicker";-import { setFast } from "@/services/desktop/client";+import { savePastedImage, setFast } from "@/services/desktop/client";import { cn } from "@/utils/cn";import {formatPlanningThinkingLabel,@@ -162,6 +162,39 @@ export function PromptInputCard({setPlanningMode(!isPlanningMode);}+ // Cmd/Ctrl+V of an image: persist the clipboard bytes to a temp file and add+ // it through the same attachment pipeline as a drag-dropped file.+ async function handlePaste(+ event: React.ClipboardEvent<HTMLTextAreaElement>,+ ) {+ const items = event.clipboardData?.items;+ if (!items) {+ return;+ }+ for (const item of items) {+ if (item.kind !== "file" || !item.type.startsWith("image/")) {+ continue;+ }+ const file = item.getAsFile();+ if (!file) {+ continue;+ }+ event.preventDefault();+ try {+ const bytes = Array.from(new Uint8Array(await file.arrayBuffer()));+ const ext = item.type.split("/")[1] ?? "png";+ const path = await savePastedImage(bytes, ext);+ const attachment = classifyPath(path);+ if (attachment) {+ addAttachments([attachment]);+ }+ } catch (error) {+ console.error("Failed to attach pasted image", error);+ }+ return;+ }+ }+return (<div ref={dropZoneRef} className="relative mx-auto w-full max-w-3xl">{isDropActive ? <DropOverlay /> : null}@@ -214,6 +247,7 @@ export function PromptInputCard({placeholder={placeholder}value={promptDraft}onChange={(event) => setPromptDraft(event.target.value)}+ onPaste={handlePaste}onKeyDown={(event) => {// The command menu consumes Enter/Tab/arrows while open, so a// command is completed rather than sent.diff --git a/gui/src/services/desktop/client.ts b/gui/src/services/desktop/client.tsindex d30750ac..0db5541b 100644--- a/gui/src/services/desktop/client.ts+++ b/gui/src/services/desktop/client.ts@@ -483,6 +483,14 @@ export function setFast(});}+/** Writes a clipboard-pasted image to a temp file and returns its path. */+export function savePastedImage(+ data: number[],+ ext: string,+): Promise<string> {+ return invokeCommand("save_pasted_image", { data, ext });+}+export function listMcpServers(workspacePath?: string | null,): Promise<McpSettingsPayload> {diff --git a/src/main.zig b/src/main.zigindex 28ff4c92..f0d80227 100644--- a/src/main.zig+++ b/src/main.zig@@ -4192,6 +4192,10 @@ pub fn main(init: std.process.Init) !void {\\gate will deny them. The user toggles execution back on with /plan.], .{base_msg});+ // Promote a GUI `@[image]` attachment to a native vision block when the+ // model can see (otherwise it only gets the path and resorts to OCR).+ stageGuiImageAttachment(&root, msg);+// "ultracode" codeword: opt this turn into multi-agent workflow mode.if (std.ascii.indexOfIgnoreCase(msg, "ultracode") != null) {if (!json_mode) {@@ -9443,6 +9447,26 @@ fn stageImagePath(root: *Agent, path: []const u8) StageResult {return .ok;}+/// GUI image attachments arrive inline as `@[path]` markers in the prompt text+/// (see the desktop AttachmentTray / appendAttachmentsToPrompt). Stage the first+/// image one as a real vision block so a vision model sees it natively instead+/// of receiving only a path to OCR. The marker is left in the text — harmless+/// once the image is visible — so non-image `@[path]` entries the agent should+/// open with its tools are untouched. No-op for non-vision providers, when an+/// image is already staged (e.g. via /image), or when no image marker is found.+fn stageGuiImageAttachment(root: *Agent, msg: []const u8) void {+ if (root.pending_image != null) return;+ if (!visionCapable(root.provider)) return;+ var search: usize = 0;+ while (std.mem.indexOfPos(u8, msg, search, "@[")) |open| {+ const rest = msg[open + 2 ..];+ const close = std.mem.indexOfScalar(u8, rest, ']') orelse break;+ const path = rest[0..close];+ if (isImagePath(path) and stageImagePath(root, path) == .ok) return;+ search = open + 2 + close + 1;+ }+}+/// macOS: dump the clipboard image (if any) to a temp PNG via osascript and/// return its path; null if the clipboard holds no image (or not macOS)./// (A terminal can't receive clipboard image bytes over stdin, so we ask the OS.)