Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(cursor): turn pasted image links into prompt images (#7051)
Wolf Mermelstein770225c3de89
diff --git a/Cargo.lock b/Cargo.lockindex c936336d59..69fbafefb9 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -5643,6 +5643,8 @@ dependencies = ["futures","insta","macro_env_var",+ "macro_tower_layers",+ "nom 8.0.0","reqwest 0.13.4","rootcause","serde",@@ -5655,8 +5657,10 @@ dependencies = ["tokio-util","tracing","tracing-subscriber",+ "url","urlencoding","uuid",+ "wiremock","workspace-hack","zeroize",]diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.mdindex 2e7de8396c..83ab522222 100644--- a/apps/web/AGENTS.md+++ b/apps/web/AGENTS.md@@ -20,6 +20,10 @@ During iterative visual tweaks, use focused browser verification; defer full typAny user-visible change should be exercised in a browser before you call it fixed — type-check, biome, and vitest all pass on code that still has the interaction bug.+Agent image attachments preserve external and inline image URLs; only configured+static-file endpoints receive thumbnail sizing. The backend-free regression is+`bunx playwright test --config src/features/block-agent/browser-test/attachments.playwright.config.ts`.+Split dragging and composer reflow have a backend-free browser regression:`bunx playwright test --config src/lib/core/component/Resize/browser-test/playwright.config.ts`.It exercises the real resize solver, scroll container, and Lexical layout primitive.diff --git a/apps/web/src/features/block-agent/browser-test/attachment-blocks.ts b/apps/web/src/features/block-agent/browser-test/attachment-blocks.tsnew file mode 100644index 0000000000..a710404e80--- /dev/null+++ b/apps/web/src/features/block-agent/browser-test/attachment-blocks.ts@@ -0,0 +1,5 @@+// Only file-icon classification is needed by the image attachment fixture.+export const blockAcceptedFileExtensionSet = new Set(['png', 'jpg']);+export const fileTypeToBlockName = () => 'image' as const;+export const isBlockAlias = () => false;+export const itemToBlockName = () => 'image' as const;diff --git a/apps/web/src/features/block-agent/browser-test/attachments.browser.e2e.ts b/apps/web/src/features/block-agent/browser-test/attachments.browser.e2e.tsnew file mode 100644index 0000000000..1fb4c67a60--- /dev/null+++ b/apps/web/src/features/block-agent/browser-test/attachments.browser.e2e.ts@@ -0,0 +1,42 @@+import { readFileSync } from 'node:fs';+import { expect, test } from '@playwright/test';++const png = readFileSync(+ new URL('../../../../public/macro-email-logo.png', import.meta.url)+);++test('public and inline images load and open the image viewer', async ({+ page,+}) => {+ const requests: string[] = [];+ await page.route('https://cdn.example/**', async (route) => {+ requests.push(route.request().url());+ await route.fulfill({ contentType: 'image/png', body: png });+ });+ await page.goto('/attachments.html');+ const thumbnails = page.locator('[data-attachment-part] img');+ await expect(thumbnails).toHaveCount(3);+ await expect+ .poll(() =>+ thumbnails.evaluateAll((elements) =>+ elements.every(+ (element) =>+ element instanceof HTMLImageElement &&+ element.complete &&+ element.naturalWidth > 0+ )+ )+ )+ .toBe(true);+ expect(requests).toContain(+ 'https://cdn.example/images?thumbnail=1&signature=sample'+ );+ expect(requests).toContain('https://cdn.example/file/photo.png');+ expect(requests.some((url) => url.includes('size=1080'))).toBe(false);+ await page.screenshot({+ path: test.info().outputPath('image-attachments.png'),+ });+ await page.getByRole('button', { name: 'Open image viewer' }).first().click();+ await expect(page.getByRole('dialog')).toBeVisible();+ await page.screenshot({ path: test.info().outputPath('image-viewer.png') });+});diff --git a/apps/web/src/features/block-agent/browser-test/attachments.html b/apps/web/src/features/block-agent/browser-test/attachments.htmlnew file mode 100644index 0000000000..8fc6b9d6fa--- /dev/null+++ b/apps/web/src/features/block-agent/browser-test/attachments.html@@ -0,0 +1,2 @@+<!doctype html>+<html lang="en"><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><title>Agent image attachments</title></head><body><div id="root"></div><script type="module" src="/attachments.tsx"></script></body></html>diff --git a/apps/web/src/features/block-agent/browser-test/attachments.playwright.config.ts b/apps/web/src/features/block-agent/browser-test/attachments.playwright.config.tsnew file mode 100644index 0000000000..db2de78c99--- /dev/null+++ b/apps/web/src/features/block-agent/browser-test/attachments.playwright.config.ts@@ -0,0 +1,18 @@+import { fileURLToPath } from 'node:url';+import { defineConfig } from '@playwright/test';+import base from './playwright.config';++const webDirectory = fileURLToPath(new URL('../../../../', import.meta.url));+const port = Number(process.env.ATTACHMENT_BROWSER_PORT ?? 3071);+export default defineConfig({+ ...base,+ testMatch: 'attachments.browser.e2e.ts',+ testIgnore: [],+ use: { ...base.use, baseURL: `http://127.0.0.1:${port}` },+ webServer: {+ command: `bunx vite --config src/features/block-agent/browser-test/attachments.vite.config.ts --port ${port}`,+ cwd: webDirectory,+ url: `http://127.0.0.1:${port}`,+ reuseExistingServer: false,+ },+});diff --git a/apps/web/src/features/block-agent/browser-test/attachments.tsx b/apps/web/src/features/block-agent/browser-test/attachments.tsxnew file mode 100644index 0000000000..6f85ad0bd3--- /dev/null+++ b/apps/web/src/features/block-agent/browser-test/attachments.tsx@@ -0,0 +1,35 @@+import { isTouchDevice } from '@core/mobile/isTouchDevice';+import { For } from 'solid-js';+import { render } from 'solid-js/web';+import { AttachmentPart } from '../component/parts/AttachmentPart';+import '../../../index.css';++document.documentElement.dataset.touchDevice = String(isTouchDevice());+const root = document.getElementById('root');+if (!root) throw new Error('Fixture root missing');+const images = [+ 'https://cdn.example/images?thumbnail=1&signature=sample',+ 'https://cdn.example/file/photo.png',+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jRZkAAAAASUVORK5CYII=',+];+render(+ () => (+ <main class="mx-auto max-w-xl p-4">+ <p>Look at these images</p>+ <For each={images}>+ {(uri) => (+ <AttachmentPart+ part={{+ kind: 'attachment',+ uri,+ name: 'image.png',+ mimeType: 'image/png',+ size: null,+ }}+ />+ )}+ </For>+ </main>+ ),+ root+);diff --git a/apps/web/src/features/block-agent/browser-test/attachments.vite.config.ts b/apps/web/src/features/block-agent/browser-test/attachments.vite.config.tsnew file mode 100644index 0000000000..2cbd13198a--- /dev/null+++ b/apps/web/src/features/block-agent/browser-test/attachments.vite.config.ts@@ -0,0 +1,21 @@+import { fileURLToPath } from 'node:url';+import { mergeConfig } from 'vite';+import base from './vite.config';++const directory = fileURLToPath(new URL('.', import.meta.url));+export default mergeConfig(base, {+ resolve: {+ alias: [+ // Exercise real media components without eagerly loading every app block.+ {+ find: '@core/constant/allBlocks',+ replacement: `${directory}/attachment-blocks.ts`,+ },+ { find: 'loro-crdt', replacement: 'loro-crdt/base64' },+ ],+ },+ optimizeDeps: {+ entries: ['attachments.html'],+ esbuildOptions: { target: 'esnext' },+ },+});diff --git a/apps/web/src/features/block-agent/browser-test/playwright.config.ts b/apps/web/src/features/block-agent/browser-test/playwright.config.tsindex 5f4325196e..dae57fb910 100644--- a/apps/web/src/features/block-agent/browser-test/playwright.config.ts+++ b/apps/web/src/features/block-agent/browser-test/playwright.config.ts@@ -7,6 +7,7 @@ const port = Number(process.env.NOTIFICATION_BROWSER_PORT ?? 3008);export default defineConfig({testDir: directory,testMatch: '*.browser.e2e.ts',+ testIgnore: 'attachments.browser.e2e.ts',outputDir: `${directory}/test-results`,timeout: 30_000,workers: 1,diff --git a/apps/web/src/features/block-agent/component/parts/AttachmentPart.test.tsx b/apps/web/src/features/block-agent/component/parts/AttachmentPart.test.tsxindex 603a7668bf..f60cad49fe 100644--- a/apps/web/src/features/block-agent/component/parts/AttachmentPart.test.tsx+++ b/apps/web/src/features/block-agent/component/parts/AttachmentPart.test.tsx@@ -6,6 +6,7 @@* that opens the file.*/+import { staticFileIdEndpoint } from '@core/constant/servers';import type { MessagePart } from '@service-agent-fold/generated/types';import { fireEvent, render } from '@solidjs/testing-library';import { describe, expect, it, vi } from 'vitest';@@ -59,7 +60,7 @@ type Attachment = Extract<MessagePart, { kind: 'attachment' }>;const attachment = (over: Partial<Attachment>): Attachment => ({kind: 'attachment',- uri: 'https://static.example/file/1',+ uri: staticFileIdEndpoint('1'),name: 'file.bin',mimeType: null,size: null,@@ -102,7 +103,7 @@ describe('AttachmentPart', () => {/>));expect(getByTestId('media-image').getAttribute('src')).toBe(- 'https://static.example/file/1?size=1080'+ `${staticFileIdEndpoint('1')}?size=1080`);expect(container.querySelector('a')).toBeNull();expect(getByTestId('media-viewer').getAttribute('data-open')).toBe('false');@@ -110,10 +111,46 @@ describe('AttachmentPart', () => {fireEvent.click(getByLabelText('Open image viewer'));expect(getByTestId('media-viewer').getAttribute('data-open')).toBe('true');expect(getByTestId('media-viewer').textContent).toBe(- 'image:https://static.example/file/1'+ `image:${staticFileIdEndpoint('1')}`);});+ it('renders a pasted image link without a static-file size query', () => {+ const uri = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ&s=10';+ const { getByTestId } = render(() => (+ <AttachmentPart+ part={attachment({+ uri,+ name: 'image.jpg',+ mimeType: 'image/jpeg',+ })}+ />+ ));+ expect(getByTestId('media-image').getAttribute('src')).toBe(uri);+ });++ it('keeps external file paths and embedded image bytes unchanged', () => {+ const uri = 'https://cdn.example/file/photo.png';+ const { getByTestId, unmount } = render(() => (+ <AttachmentPart+ part={attachment({ uri, name: 'photo.png', mimeType: 'image/png' })}+ />+ ));+ expect(getByTestId('media-image').getAttribute('src')).toBe(uri);+ unmount();+ const data = 'data:image/png;base64,aW1n';+ const embedded = render(() => (+ <AttachmentPart+ part={attachment({+ uri: data,+ name: 'photo.png',+ mimeType: 'image/png',+ })}+ />+ ));+ expect(embedded.getByTestId('media-image').getAttribute('src')).toBe(data);+ });+it('renders a video as a preview that opens the media viewer', () => {const { getByLabelText, getByTestId, container } = render(() => (<AttachmentPart@@ -121,7 +158,7 @@ describe('AttachmentPart', () => {/>));expect(getByTestId('media-video').getAttribute('src')).toBe(- 'https://static.example/file/1'+ staticFileIdEndpoint('1'));expect(container.querySelector('a')).toBeNull();expect(getByTestId('media-viewer').getAttribute('data-open')).toBe('false');@@ -129,7 +166,7 @@ describe('AttachmentPart', () => {fireEvent.click(getByLabelText('Open video viewer'));expect(getByTestId('media-viewer').getAttribute('data-open')).toBe('true');expect(getByTestId('media-viewer').textContent).toBe(- 'video:https://static.example/file/1'+ `video:${staticFileIdEndpoint('1')}`);});@@ -142,7 +179,7 @@ describe('AttachmentPart', () => {expect(container.textContent).toContain('notes.pdf');expect(getByTestId('entity-icon').getAttribute('data-type')).toBe('pdf');const link = container.querySelector('a');- expect(link?.getAttribute('href')).toBe('https://static.example/file/1');+ expect(link?.getAttribute('href')).toBe(staticFileIdEndpoint('1'));expect(link?.getAttribute('target')).toBe('_blank');});});diff --git a/apps/web/src/features/block-agent/component/parts/AttachmentPart.tsx b/apps/web/src/features/block-agent/component/parts/AttachmentPart.tsxindex 6fd3d0f2a6..2aa2819fdc 100644--- a/apps/web/src/features/block-agent/component/parts/AttachmentPart.tsx+++ b/apps/web/src/features/block-agent/component/parts/AttachmentPart.tsx@@ -1,8 +1,8 @@/*** A file the user attached to their prompt. Images and videos render as the* channel composer's media thumbnails and open the same lightbox; anything- * else is a chip that opens the file. The fold hands over a URL, never bytes,- * so this is a plain fetch from the static file service.+ * else is a chip that opens the file. Images may refer to a static file, a+ * pasted public URL, or an inline data URL.*/import { getAttachmentKindFromFile } from '@channel/Input/utils/file-helpers';@@ -12,7 +12,11 @@ import { MediaViewerDialog } from '@channel/Media/MediaViewerDialog';import type { MediaItem } from '@channel/Media/media-items';import { EntityIcon } from '@core/component/EntityIcon';import { fileTypeToBlockName } from '@core/constant/allBlocks';-import { staticFileSizedUrl } from '@core/constant/servers';+import {+ staticFileIdEndpoint,+ staticFileReferenceEndpoint,+ staticFileSizedUrl,+} from '@core/constant/servers';import type { MessagePart } from '@service-agent-fold/generated/types';import { createSignal, Match, Show, Switch } from 'solid-js';@@ -52,6 +56,27 @@ function staticFileIdFromUri(uri: string): string {}}+/**+ * Static-file thumbnails take a `size` query. Any other image URL — a pasted+ * link, a data URL — is already the bytes to show.+ */+function imageSrc(uri: string): string {+ if (uri.startsWith('data:')) return uri;+ try {+ const url = new URL(uri);+ if (+ (uri.startsWith(staticFileIdEndpoint('')) ||+ uri.startsWith(staticFileReferenceEndpoint(''))) &&+ url.search === ''+ ) {+ return staticFileSizedUrl(uri, 'medium');+ }+ } catch {+ // Not a URL; show it as given.+ }+ return uri;+}+function mediaItemFromAttachment(part: AttachmentPartData): MediaItem | undefined {@@ -59,7 +84,7 @@ function mediaItemFromAttachment(if (kind !== 'image' && kind !== 'video') return undefined;return {id: staticFileIdFromUri(part.uri),- src: kind === 'image' ? staticFileSizedUrl(part.uri, 'medium') : part.uri,+ src: kind === 'image' ? imageSrc(part.uri) : part.uri,fullSrc: part.uri,kind,};@@ -85,7 +110,7 @@ export function AttachmentPart(props: { part: AttachmentPartData }) {><MediaImage.Root><MediaImage.Image- src={staticFileSizedUrl(props.part.uri, 'medium')}+ src={imageSrc(props.part.uri)}class="max-h-64 max-w-full select-none rounded-lg border border-edge object-contain"loading="lazy"fallback={<MediaImage.Fallback square />}diff --git a/crates/agent_harness/AGENTS.md b/crates/agent_harness/AGENTS.mdindex a9bb165e50..3fa1c7a71e 100644--- a/crates/agent_harness/AGENTS.md+++ b/crates/agent_harness/AGENTS.md@@ -16,6 +16,8 @@ between the sandbox and the rest of the product.transport that speaks `agent_runtime_protocol`.- `src/outbound/containers.rs` / `managed_containers.rs`: containerprovisioning.+- `src/outbound/cursor/manager.rs`: compose Cursor sessions, including public+ prompt-image fetching through the `cursor_cloud_agents` image-fetcher port.- `src/domain/trigger_router.rs`: routes an incoming trigger to a session.- `src/inbound/kafka.rs`: trigger ingestion.- `src/domain/mode_choice.rs` + `src/inbound/mode_choice.rs`: the agent@@ -80,7 +82,9 @@ wakes; interrupted quiet batches return to the next real prompt.## Checks-- `cargo test -p agent_harness` (`SQLX_OFFLINE` unset).+- `cargo nextest run -p agent_harness --lib --test-threads=2` (`SQLX_OFFLINE`+ unset). Use CI's process isolation for the full database-backed suite so each+ test has its own process and runtime.## Relateddiff --git a/crates/agent_harness/src/outbound/cursor/manager.rs b/crates/agent_harness/src/outbound/cursor/manager.rsindex 3563b0b69d..de91b35854 100644--- a/crates/agent_harness/src/outbound/cursor/manager.rs+++ b/crates/agent_harness/src/outbound/cursor/manager.rs@@ -475,7 +475,10 @@ where// owner picked for it when they opened it, what they switched it// to since, or - for a session that never picked - the slug this// harness seeded the record with, which resolves to no opinion.- .with_host_model(Some(session.model.clone())),+ .with_host_model(Some(session.model.clone()))+ .with_image_fetcher(Arc::new(+ cursor_cloud_agents::outbound::http_prompt_images::HttpPromptImageFetcher::new(),+ )),);if let Some(restored) = restore {service.restore_session_with_watermark(@@ -804,10 +807,11 @@ whereopen_pull_request: bool,mcp_servers: &[McpServer],model: Option<&ModelChoice>,+ images: &[cursor_cloud_agents::domain::prompt_image::CursorPromptImage],) -> std::result::Result<(CursorAgentId, CursorRunId), rootcause::Report> {let (agent, run) = self.client- .create_agent(prompt, repo, open_pull_request, mcp_servers, model)+ .create_agent(prompt, repo, open_pull_request, mcp_servers, model, images).await?;let summary = self.client@@ -847,8 +851,9 @@ whereagent: &CursorAgentId,prompt: &str,model: Option<&ModelChoice>,+ images: &[cursor_cloud_agents::domain::prompt_image::CursorPromptImage],) -> std::result::Result<CursorRunId, rootcause::Report> {- self.client.create_run(agent, prompt, model).await+ self.client.create_run(agent, prompt, model, images).await}async fn list_models(&self) -> std::result::Result<Vec<CursorModel>, rootcause::Report> {diff --git a/crates/cursor_cloud_agents/AGENTS.md b/crates/cursor_cloud_agents/AGENTS.mdindex 44427d5a80..a2cb289f77 100644--- a/crates/cursor_cloud_agents/AGENTS.md+++ b/crates/cursor_cloud_agents/AGENTS.md@@ -14,6 +14,8 @@ notifications as it arrives.- `src/domain/translate.rs`: the Cursor→ACP event translation state machine(`TranslateMachine`), mirroring `agent_fold`'s `FoldMachine`.- `src/domain/service.rs`: ties a prompt to a run.+- `src/domain/prompt_image.rs` + `src/outbound/http_prompt_images.rs`: convert+ pasted public raster-image links and ACP images into Cursor prompt images.- `src/api.rs` (`src/api/`): the Cursor cloud REST + SSE client.- `src/inbound/acp.rs`: newline-delimited JSON-RPC ACP adapter (stdio orin-process duplex pipe).@@ -55,6 +57,13 @@ notifications as it arrives.## Gotchas+Prompt image resolution preserves the prompt text, tries up to eight unique links+within a ten-second budget, and sends at most five images of 15 MiB each.+HTTP resolution disables proxies, validates literal addresses and connection-time+DNS answers, and checks each redirect. Stop cancels resolution and journals the prompt as aborted+without creating remote work. Fetch failures leave links as text; never log link URLs+or image bytes. Images are journaled as ACP image blocks for live display and replay.+- `REPLAY.md`'s migration-rollout section documents a one-time consolidationof four old migrations into `20260906060601_cursor_session_replay`; don'treset or DOWN-migrate a database that already has journal history withoutdiff --git a/crates/cursor_cloud_agents/Cargo.toml b/crates/cursor_cloud_agents/Cargo.tomlindex a3d0b6ec98..b0d8a29aa1 100644--- a/crates/cursor_cloud_agents/Cargo.toml+++ b/crates/cursor_cloud_agents/Cargo.toml@@ -15,6 +15,8 @@ test-utils = []name = "cursor_cloud_agents"[dependencies]+nom = { workspace = true }+url = { workspace = true }urlencoding = { workspace = true }agent_session = { path = "../agent_session", optional = true }agent_runtime_protocol = { path = "../agent_runtime_protocol", default-features = false }@@ -26,6 +28,7 @@ base64 = { workspace = true }bytes = { workspace = true }static_file_service_client = { path = "../static_file_service_client" }futures = { workspace = true }+macro_tower_layers = { path = "../macro_tower_layers" }macro_env_var = { path = "../macro_env_var" }# `stream` on top of the workspace features: the run stream is consumed as# `bytes_stream`, which reqwest gates behind it.@@ -41,13 +44,14 @@ thiserror = { workspace = true }# `compat` bridges tokio streams to the futures traits the ACP SDK's# `ByteStreams` transport takes.tokio-util = { workspace = true, features = ["compat"] }-tokio = { workspace = true, features = ["io-std", "io-util", "sync", "time"] }+tokio = { workspace = true, features = ["io-std", "io-util", "net", "sync", "time"] }tracing = { workspace = true }tracing-subscriber = { workspace = true }workspace-hack = { version = "0.1", path = "../workspace-hack" }zeroize = { workspace = true }[dev-dependencies]+wiremock = { workspace = true }agent_fold = { path = "../folds/agent_fold", default-features = false, features = ["test-utils"] }insta = { version = "1.48.0", features = ["glob", "json"] }tokio = { workspace = true, features = ["io-std", "io-util", "sync", "time", "test-util"] }diff --git a/crates/cursor_cloud_agents/src/api.rs b/crates/cursor_cloud_agents/src/api.rsindex 6df44f4ac4..0f1e1d2383 100644--- a/crates/cursor_cloud_agents/src/api.rs+++ b/crates/cursor_cloud_agents/src/api.rs@@ -29,7 +29,7 @@ use crate::api::wire::{AgentSummary, ArchiveAgentResponse, ArtifactDownloadResponse, ConversationResponse,CreateAgentRequest, CreateAgentResponse, CreateRunRequest, CreateRunResponse,ListAgentsResponse, ListArtifactsResponse, ListModelsResponse, ListRunsResponse,- McpServerSelection, MeResponse, ModelSelection, PromptBody, RepoSelection,+ McpServerSelection, MeResponse, ModelSelection, PromptBody, PromptImage, RepoSelection,};use crate::domain::artifact::{ArtifactListing, FetchedArtifact};use crate::domain::model::{@@ -39,6 +39,7 @@ use crate::domain::model::{use crate::domain::ports::{ConnectedStream, CursorAgents, CursorArtifacts, RunStream, StreamConnectError,};+use crate::domain::prompt_image::CursorPromptImage;use futures::Stream;use std::num::NonZeroUsize;@@ -63,6 +64,19 @@ pub(crate) const MAX_SSE_PAYLOAD: NonZeroUsize = match NonZeroUsize::new(16 * 10None => panic!("the payload limit is a non-zero literal"),};+fn prompt_body(text: &str, images: &[CursorPromptImage]) -> PromptBody {+ PromptBody {+ text: text.to_owned(),+ images: images+ .iter()+ .map(|image| PromptImage {+ data: image.data.clone(),+ mime_type: image.mime_type.clone(),+ })+ .collect(),+ }+}+/// The one real base url. A [`CursorConfig`] still names its own, because a/// test points at a stand-in server, but there is nothing for a deployment to/// choose between.@@ -665,11 +679,10 @@ impl CursorAgents for CursorClient {open_pull_request: bool,mcp_servers: &[McpServer],model: Option<&ModelChoice>,+ images: &[CursorPromptImage],) -> Result<(CursorAgentId, CursorRunId), rootcause::Report> {let request = CreateAgentRequest {- prompt: PromptBody {- text: prompt.to_owned(),- },+ prompt: prompt_body(prompt, images),repos: repo.map(|repo| {vec![RepoSelection {@@ -733,11 +746,10 @@ impl CursorAgents for CursorClient {agent: &CursorAgentId,prompt: &str,model: Option<&ModelChoice>,+ images: &[CursorPromptImage],) -> Result<CursorRunId, rootcause::Report> {let request = CreateRunRequest {- prompt: PromptBody {- text: prompt.to_owned(),- },+ prompt: prompt_body(prompt, images),model: model.map(ModelSelection::from),};let path = format!("/v1/agents/{agent}/runs");diff --git a/crates/cursor_cloud_agents/src/api/test.rs b/crates/cursor_cloud_agents/src/api/test.rsindex dbe8dc8236..5f7fe08334 100644--- a/crates/cursor_cloud_agents/src/api/test.rs+++ b/crates/cursor_cloud_agents/src/api/test.rs@@ -180,7 +180,7 @@ async fn a_repository_rejection_is_typed_with_the_repository() {r#"{"error":{"code":"repository_access","message":"Repository not accessible"}}"#,);let error = client_against(base_url)- .create_agent("prompt", Some(&repo()), true, &[], None)+ .create_agent("prompt", Some(&repo()), true, &[], None, &[]).await.expect_err("the stand-in rejects every create");let unavailable = error@@ -216,7 +216,7 @@ async fn a_branch_cursor_could_not_verify_is_retried() {("200 OK".to_owned(), CREATED_BODY),]);let (agent, run) = client_with_instant_retries(base_url, 2)- .create_agent("prompt", Some(&repo()), true, &[], None)+ .create_agent("prompt", Some(&repo()), true, &[], None, &[]).await.expect("the third answer is a created agent");assert_eq!(agent.as_str(), "bc-00000000-0000-0000-0000-000000000001");@@ -242,7 +242,7 @@ async fn a_branch_still_unverifiable_after_retrying_is_typed_with_the_branch() {("400 Bad Request".to_owned(), BRANCH_UNVERIFIABLE_BODY),]);let error = client_with_instant_retries(base_url, 1)- .create_agent("prompt", Some(&repo()), true, &[], None)+ .create_agent("prompt", Some(&repo()), true, &[], None, &[]).await.expect_err("the stand-in never relents");let unavailable = error@@ -316,7 +316,7 @@ async fn a_rate_limited_create_is_asked_again() {("200 OK".to_owned(), CREATED_BODY),]);let (agent, _) = client_with_instant_turn_retries(base_url, 3)- .create_agent("prompt", Some(&repo()), true, &[], None)+ .create_agent("prompt", Some(&repo()), true, &[], None, &[]).await.expect("the second answer is a created agent");assert_eq!(agent.as_str(), "bc-00000000-0000-0000-0000-000000000001");@@ -332,7 +332,7 @@ async fn a_failing_gateway_is_asked_again() {("200 OK".to_owned(), CREATED_BODY),]);let (agent, _) = client_with_instant_turn_retries(base_url, 3)- .create_agent("prompt", Some(&repo()), true, &[], None)+ .create_agent("prompt", Some(&repo()), true, &[], None, &[]).await.expect("the second answer is a created agent");assert_eq!(agent.as_str(), "bc-00000000-0000-0000-0000-000000000001");@@ -355,6 +355,7 @@ async fn a_rate_limited_follow_up_run_is_asked_again() {&CursorAgentId::new("bc-00000000-0000-0000-0000-000000000001".to_owned()),"prompt",None,+ &[],).await.expect("the second answer is a run");@@ -371,7 +372,7 @@ async fn a_transient_that_outlasts_the_budget_fails_as_it_always_did() {("429 Too Many Requests".to_owned(), RATE_LIMITED_BODY),]);let error = client_with_instant_turn_retries(base_url, 1)- .create_agent("prompt", Some(&repo()), true, &[], None)+ .create_agent("prompt", Some(&repo()), true, &[], None, &[]).await.expect_err("the stand-in never relents");assert!(@@ -392,7 +393,7 @@ async fn a_rejection_is_never_asked_again() {r#"{"error":{"code":"validation_error","message":"Model 'nope' does not match a known variant"}}"#,)]);client_with_instant_turn_retries(base_url, 3)- .create_agent("prompt", Some(&repo()), true, &[], None)+ .create_agent("prompt", Some(&repo()), true, &[], None, &[]).await.expect_err("the stand-in rejects the create");assert_eq!(requests.try_iter().count(), 1, "asked exactly once");@@ -407,7 +408,7 @@ async fn other_validation_errors_are_not_retried() {r#"{"error":{"code":"validation_error","message":"Model 'nope' does not match a known variant"}}"#,)]);let error = client_with_instant_retries(base_url, 2)- .create_agent("prompt", Some(&repo()), true, &[], None)+ .create_agent("prompt", Some(&repo()), true, &[], None, &[]).await.expect_err("the stand-in rejects the create");assert!(@@ -429,7 +430,7 @@ async fn an_unrelated_client_error_is_still_a_plain_rejection() {r#"{"error":{"code":"validation_error","message":"Model 'nope' does not match a known variant"}}"#,);let error = client_against(base_url)- .create_agent("prompt", Some(&repo()), true, &[], None)+ .create_agent("prompt", Some(&repo()), true, &[], None, &[]).await.expect_err("the stand-in rejects every create");assert!(@@ -459,7 +460,7 @@ const USAGE_LIMIT_BODY: &str = r#"{"error":{"code":"usage_limit_exceeded","messaasync fn an_exhausted_usage_limit_is_typed_with_a_notice() {let base_url = stand_in_server("400 Bad Request", USAGE_LIMIT_BODY);let error = client_against(base_url)- .create_agent("prompt", Some(&repo()), true, &[], None)+ .create_agent("prompt", Some(&repo()), true, &[], None, &[]).await.expect_err("the stand-in rejects every create");let exceeded = error@@ -490,7 +491,7 @@ async fn an_exhausted_usage_limit_is_typed_with_a_notice() {async fn an_exhausted_usage_limit_on_a_follow_up_run_is_typed_too() {let base_url = stand_in_server("400 Bad Request", USAGE_LIMIT_BODY);let error = client_against(base_url)- .create_run(&agent(), "prompt", None)+ .create_run(&agent(), "prompt", None, &[]).await.expect_err("the stand-in rejects every run");assert!(@@ -511,7 +512,7 @@ async fn a_usage_limit_is_matched_on_the_code_not_the_message() {r#"{"error":{"code":"validation_error","message":"You need to increase your hard limit."}}"#,);let error = client_against(base_url)- .create_agent("prompt", Some(&repo()), true, &[], None)+ .create_agent("prompt", Some(&repo()), true, &[], None, &[]).await.expect_err("the stand-in rejects every create");assert!(@@ -625,3 +626,48 @@ async fn an_expired_presigned_url_fails_with_its_status() {assert!(printed.contains("403"), "got {printed}");assert!(printed.contains("Request has expired"), "got {printed}");}++#[tokio::test]+async fn both_initial_and_followup_requests_include_prompt_images() {+ use wiremock::{+ Mock, MockServer, ResponseTemplate,+ matchers::{body_partial_json, method, path},+ };+ let server = MockServer::start().await;+ let body = serde_json::json!({"prompt": {"text": "look", "images": [{"data": "aW1n", "mimeType": "image/png"}]}});+ Mock::given(method("POST"))+ .and(path("/v1/agents"))+ .and(body_partial_json(body.clone()))+ .respond_with(ResponseTemplate::new(200).set_body_string(CREATED_BODY))+ .expect(1)+ .mount(&server)+ .await;+ Mock::given(method("POST"))+ .and(path("/v1/agents/bc-test/runs"))+ .and(body_partial_json(body))+ .respond_with(+ ResponseTemplate::new(200).set_body_json(serde_json::json!({"id":"run-test"})),+ )+ .expect(1)+ .mount(&server)+ .await;+ let client = client_against(server.uri());+ let images = [CursorPromptImage {+ data: "aW1n".into(),+ mime_type: "image/png".into(),+ source_url: Some("https://cdn.example/pic".into()),+ }];+ client+ .create_agent("look", None, false, &[], None, &images)+ .await+ .expect("create agent");+ client+ .create_run(+ &CursorAgentId::new("bc-test".to_owned()),+ "look",+ None,+ &images,+ )+ .await+ .expect("followup run");+}diff --git a/crates/cursor_cloud_agents/src/api/wire.rs b/crates/cursor_cloud_agents/src/api/wire.rsindex 624eb41dd0..6c077e4715 100644--- a/crates/cursor_cloud_agents/src/api/wire.rs+++ b/crates/cursor_cloud_agents/src/api/wire.rs@@ -16,6 +16,22 @@ use std::collections::BTreeMap;pub struct PromptBody {/// The prompt text.pub text: String,+ /// Raster images. Omitted when empty so a text prompt is unchanged.+ #[serde(skip_serializing_if = "Vec::is_empty")]+ pub images: Vec<PromptImage>,+}++/// One `prompt.images` entry: base64 bytes and the type Cursor requires with them.+///+/// `url` is the other shape Cursor documents. We send bytes because the link+/// was already fetched to learn that it is an image.+#[derive(Debug, Serialize)]+pub struct PromptImage {+ /// Standard base64, no `data:` prefix.+ pub data: String,+ /// `image/png`, `image/jpeg`, `image/gif`, or `image/webp`.+ #[serde(rename = "mimeType")]+ pub mime_type: String,}/// One repository for a new agent to clone.diff --git a/crates/cursor_cloud_agents/src/api/wire/test.rs b/crates/cursor_cloud_agents/src/api/wire/test.rsindex c1a038f6f6..4da8e123ff 100644--- a/crates/cursor_cloud_agents/src/api/wire/test.rs+++ b/crates/cursor_cloud_agents/src/api/wire/test.rs@@ -54,6 +54,7 @@ fn no_mcp_servers_means_no_field() {let request = CreateAgentRequest {prompt: PromptBody {text: "hi".to_owned(),+ images: Vec::new(),},repos: Vec::new(),model: None,@@ -71,6 +72,7 @@ fn a_repo_agent_asks_for_a_pull_request() {let request = CreateAgentRequest {prompt: PromptBody {text: "hi".to_owned(),+ images: Vec::new(),},repos: vec![RepoSelection {url: "https://github.com/macro-inc/macro".to_owned(),@@ -84,6 +86,37 @@ fn a_repo_agent_asks_for_a_pull_request() {assert_eq!(body.get("autoCreatePR"), Some(&serde_json::json!(true)));}+/// Prompt images go out as base64 `data` plus `mimeType`, which is the shape+/// Cursor requires when the bytes are already in hand.+#[test]+fn prompt_images_serialize_as_data_and_mime_type() {+ let body = PromptBody {+ text: "look".to_owned(),+ images: vec![PromptImage {+ data: "aW1n".to_owned(),+ mime_type: "image/png".to_owned(),+ }],+ };+ assert_eq!(+ serde_json::to_value(body).expect("serializes"),+ serde_json::json!({+ "text": "look",+ "images": [{ "data": "aW1n", "mimeType": "image/png" }]+ })+ );+}++/// An empty image list is omitted, so a text prompt sends no `images` key.+#[test]+fn a_text_prompt_omits_images() {+ let body = PromptBody {+ text: "look".to_owned(),+ images: Vec::new(),+ };+ let value = serde_json::to_value(body).expect("serializes");+ assert!(value.get("images").is_none(), "got {value}");+}+/// A repo-less agent has nothing to open a pull request against, so the field/// is omitted rather than sent as false.#[test]@@ -91,6 +124,7 @@ fn a_repoless_agent_omits_the_pull_request_flag() {let request = CreateAgentRequest {prompt: PromptBody {text: "hi".to_owned(),+ images: Vec::new(),},repos: Vec::new(),model: None,diff --git a/crates/cursor_cloud_agents/src/bin/cursor_cloud_agents.rs b/crates/cursor_cloud_agents/src/bin/cursor_cloud_agents.rsindex 4cdb4e433c..75b3a4fe52 100644--- a/crates/cursor_cloud_agents/src/bin/cursor_cloud_agents.rs+++ b/crates/cursor_cloud_agents/src/bin/cursor_cloud_agents.rs@@ -145,7 +145,10 @@ async fn main() -> ExitCode {Arc::new(cursor_cloud_agents::outbound::memory_journal::MemoryJournal::default()),cursor_cloud_agents::domain::ports::NoArtifactStore,)- .with_default_model(configured_model),+ .with_default_model(configured_model)+ .with_image_fetcher(Arc::new(+ cursor_cloud_agents::outbound::http_prompt_images::HttpPromptImageFetcher::new(),+ )),);match serve(service, notifier, tokio::io::stdin(), tokio::io::stdout()).await {Ok(()) => ExitCode::SUCCESS,diff --git a/crates/cursor_cloud_agents/src/domain/mod.rs b/crates/cursor_cloud_agents/src/domain/mod.rsindex 0a90fa25e3..605c3190bc 100644--- a/crates/cursor_cloud_agents/src/domain/mod.rs+++ b/crates/cursor_cloud_agents/src/domain/mod.rs@@ -23,6 +23,9 @@ pub mod slash_commands;/// The capabilities the domain requires from the outside.pub mod ports;+/// Pasted links resolved into Cursor prompt images.+pub mod prompt_image;+/// The session service: prompts in, translated updates out.pub mod service;diff --git a/crates/cursor_cloud_agents/src/domain/ports.rs b/crates/cursor_cloud_agents/src/domain/ports.rsindex 17c42746b4..7415351fa1 100644--- a/crates/cursor_cloud_agents/src/domain/ports.rs+++ b/crates/cursor_cloud_agents/src/domain/ports.rs@@ -14,6 +14,7 @@ use crate::domain::model::{ConversationLine, CursorAgentId, CursorModel, CursorRunId, McpServer, ModelChoice, RepoUrl,RunListing,};+use crate::domain::prompt_image::CursorPromptImage;use agent_client_protocol::schema::v1::{SessionId, SessionUpdate};use futures::Stream;@@ -43,6 +44,9 @@ pub trait CursorAgents: Sync {/// `open_pull_request` asks Cursor to push its work to a generated branch/// and open a pull request against the starting ref. It is a caller's/// decision and has no effect without a repository.+ ///+ /// `images` are raster pictures for `prompt.images`. Empty leaves the+ /// prompt as text.fn create_agent(&self,prompt: &str,@@ -50,6 +54,7 @@ pub trait CursorAgents: Sync {open_pull_request: bool,mcp_servers: &[McpServer],model: Option<&ModelChoice>,+ images: &[CursorPromptImage],) -> impl Future<Output = Result<(CursorAgentId, CursorRunId), rootcause::Report>> + Send;/// Send a follow-up prompt to an existing agent, opening a new run.@@ -57,11 +62,14 @@ pub trait CursorAgents: Sync {/// `model` is honoured per run, which is what makes a mid-session model/// change possible: the field is undocumented on this endpoint but/// validated by it, and absent means the agent's own model stands.+ ///+ /// `images` are the same raster pictures as on [`Self::create_agent`].fn create_run(&self,agent: &CursorAgentId,prompt: &str,model: Option<&ModelChoice>,+ images: &[CursorPromptImage],) -> impl Future<Output = Result<CursorRunId, rootcause::Report>> + Send;/// The models this account may choose from, with the variants each accepts.@@ -165,6 +173,31 @@ pub trait ArtifactStore: Send + Sync {) -> impl Future<Output = Result<String, rootcause::Report>> + Send;}+/// Fetch a link pasted into a prompt when it might be an image.+///+/// `None` means the link is not an image we can hand to Cursor — a page, a+/// private address, a failure — and the prompt continues as text.+pub trait PromptImageFetcher: Send + Sync + std::fmt::Debug {+ /// Fetch `url` and return an image when the response is one.+ fn fetch_image<'a>(+ &'a self,+ url: &'a str,+ ) -> futures::future::BoxFuture<'a, Option<CursorPromptImage>>;+}++/// A fetcher that never fetches. Prompts stay text.+#[derive(Debug, Clone, Copy, Default)]+pub struct NoPromptImageFetcher;++impl PromptImageFetcher for NoPromptImageFetcher {+ fn fetch_image<'a>(+ &'a self,+ _url: &'a str,+ ) -> futures::future::BoxFuture<'a, Option<CursorPromptImage>> {+ Box::pin(async { None })+ }+}+/// The store for a deployment that has nowhere to put artifacts.////// Reports itself unavailable, so a session built with it never lists andiff --git a/crates/cursor_cloud_agents/src/domain/prompt_image.rs b/crates/cursor_cloud_agents/src/domain/prompt_image.rsnew file mode 100644index 0000000000..ef2fb0876d--- /dev/null+++ b/crates/cursor_cloud_agents/src/domain/prompt_image.rs@@ -0,0 +1,225 @@+//! Pasted links that turn out to be images, as Cursor's prompt images and as+//! ACP image frames.+//!+//! A prompt is text. A URL in that text does not say what it points at, so+//! the bytes are fetched and kept only when they are a raster image Cursor+//! accepts. The same bytes go to Cursor as `prompt.images` and into the+//! transcript as an ACP image content block.++#[cfg(test)]+mod test;++use agent_client_protocol::schema::v1::{ContentBlock, ImageContent};+use nom::{+ IResult, Parser,+ branch::alt,+ bytes::complete::{tag, take_till, take_until},+ combinator::recognize,+};+use std::collections::HashSet;++/// How many images one prompt may carry. Cursor rejects more than this.+pub const MAX_PROMPT_IMAGES: usize = 5;++/// How many links one prompt will try. Most links are not images; the cap+/// stops a message full of URLs from fetching all of them.+const MAX_LINK_FETCHES: usize = 8;++/// Decoded image size Cursor accepts on `prompt.images`.+pub const MAX_IMAGE_BYTES: usize = 15 * 1024 * 1024;++/// One image to send as Cursor `prompt.images` data.+#[derive(Debug, Clone, PartialEq, Eq)]+pub struct CursorPromptImage {+ /// Standard base64, no `data:` prefix.+ pub data: String,+ /// `image/png`, `image/jpeg`, `image/gif`, or `image/webp`.+ pub mime_type: String,+ /// Where the bytes were fetched from, when they came from a link.+ pub source_url: Option<String>,+}++impl CursorPromptImage {+ /// The ACP image frame for this picture. `uri` is the source link when+ /// there is one, so a reader can show the image without keeping the bytes.+ #[must_use]+ pub fn to_content_block(&self) -> ContentBlock {+ let mut image = ImageContent::new(self.data.clone(), self.mime_type.clone());+ if let Some(url) = &self.source_url {+ image = image.uri(url.clone());+ }+ ContentBlock::Image(image)+ }+}++/// `image/jpg` and parameter suffixes become the type Cursor wants.+#[must_use]+pub fn canonical_mime(mime: &str) -> Option<&'static str> {+ match media_type(mime) {+ "image/png" => Some("image/png"),+ "image/jpeg" | "image/jpg" => Some("image/jpeg"),+ "image/gif" => Some("image/gif"),+ "image/webp" => Some("image/webp"),+ _ => None,+ }+}++/// The media type, without parameters (`image/png; charset=binary`).+fn media_type(mime: &str) -> &str {+ mime.split(';').next().unwrap_or(mime).trim()+}++/// A type worth reading the body for: a supported image, or no type at all.+#[must_use]+pub fn worth_fetching(mime: Option<&str>) -> bool {+ match mime.map(media_type) {+ None | Some("") | Some("application/octet-stream") | Some("binary/octet-stream") => true,+ Some(mime) => canonical_mime(mime).is_some(),+ }+}++/// Image type from a `Content-Type` header, else from the leading bytes.+#[must_use]+pub fn detect_mime(content_type: Option<&str>, bytes: &[u8]) -> Option<&'static str> {+ if !worth_fetching(content_type) {+ return None;+ }+ sniff(bytes)+}++fn sniff(bytes: &[u8]) -> Option<&'static str> {+ if bytes.starts_with(&[0x89, b'P', b'N', b'G', 0x0D, 0x0A, 0x1A, 0x0A]) {+ return Some("image/png");+ }+ if bytes.starts_with(&[0xFF, 0xD8, 0xFF]) {+ return Some("image/jpeg");+ }+ if bytes.starts_with(b"GIF87a") || bytes.starts_with(b"GIF89a") {+ return Some("image/gif");+ }+ if bytes.len() >= 12 && bytes.starts_with(b"RIFF") && &bytes[8..12] == b"WEBP" {+ return Some("image/webp");+ }+ None+}++/// Links in `blocks` that might be images, in order, without duplicates.+///+/// A link that is already an ACP image is skipped: its bytes are taken from+/// the block, and fetching it again would attach the picture twice.+#[must_use]+pub fn linked_image_urls(blocks: &[ContentBlock]) -> Vec<String> {+ let mut seen = HashSet::new();+ for block in blocks {+ if let ContentBlock::Image(image) = block+ && let Some(uri) = &image.uri+ {+ seen.insert(uri.clone());+ }+ }+ let mut urls = Vec::new();+ for block in blocks {+ match block {+ ContentBlock::Text(text) => collect_urls(&text.text, &mut urls, &mut seen),+ ContentBlock::ResourceLink(link) if worth_fetching(link.mime_type.as_deref()) => {+ push_url(link.uri.trim(), &mut urls, &mut seen);+ }+ _ => {}+ }+ if urls.len() >= MAX_LINK_FETCHES {+ break;+ }+ }+ urls.truncate(MAX_LINK_FETCHES);+ urls+}++/// ACP image blocks already on the prompt, in order, within Cursor's cap.+#[must_use]+pub fn images_in_blocks(blocks: &[ContentBlock]) -> Vec<CursorPromptImage> {+ let mut images = Vec::new();+ for block in blocks {+ let ContentBlock::Image(image) = block else {+ continue;+ };+ let Some(mime_type) = canonical_mime(&image.mime_type) else {+ continue;+ };+ if image.data.is_empty() || estimated_bytes(&image.data) > MAX_IMAGE_BYTES {+ continue;+ }+ images.push(CursorPromptImage {+ data: image.data.clone(),+ mime_type: mime_type.to_owned(),+ source_url: image.uri.clone(),+ });+ if images.len() == MAX_PROMPT_IMAGES {+ break;+ }+ }+ images+}++fn estimated_bytes(base64: &str) -> usize {+ base64.len().saturating_mul(3) / 4+}++fn collect_urls(text: &str, urls: &mut Vec<String>, seen: &mut HashSet<String>) {+ let mut rest = text;+ while urls.len() < MAX_LINK_FETCHES {+ let Ok((tail, raw)) = next_url(rest) else {+ break;+ };+ push_url(trim_trailing(raw), urls, seen);+ rest = tail;+ }+}++fn next_url(mut input: &str) -> IResult<&str, &str> {+ loop {+ let (rest, _) = take_until("http")(input)?;+ let parsed: IResult<&str, &str> = recognize((+ alt((tag("https://"), tag("http://"))),+ take_till(|ch: char| ch.is_whitespace() || matches!(ch, '<' | '>' | '"' | '\'' | '`')),+ ))+ .parse(rest);+ match parsed {+ Ok(found) => return Ok(found),+ Err(_) => {+ input = tag("http")(rest)?.0;+ }+ }+ }+}++fn push_url(raw: &str, urls: &mut Vec<String>, seen: &mut HashSet<String>) {+ if urls.len() >= MAX_LINK_FETCHES || raw.len() < "http://a".len() {+ return;+ }+ if !raw.starts_with("http://") && !raw.starts_with("https://") {+ return;+ }+ if seen.insert(raw.to_owned()) {+ urls.push(raw.to_owned());+ }+}++fn trim_trailing(url: &str) -> &str {+ let mut url = url;+ loop {+ let Some(last) = url.chars().last() else {+ break;+ };+ let strip = match last {+ ',' | '.' | ';' | '!' | '?' | ':' => true,+ ')' => url.matches('(').count() < url.matches(')').count(),+ ']' => url.matches('[').count() < url.matches(']').count(),+ _ => false,+ };+ if !strip {+ break;+ }+ url = &url[..url.len() - last.len_utf8()];+ }+ url+}diff --git a/crates/cursor_cloud_agents/src/domain/prompt_image/test.rs b/crates/cursor_cloud_agents/src/domain/prompt_image/test.rsnew file mode 100644index 0000000000..1da3db2dc4--- /dev/null+++ b/crates/cursor_cloud_agents/src/domain/prompt_image/test.rs@@ -0,0 +1,119 @@+use super::*;+use agent_client_protocol::schema::v1::{ResourceLink, TextContent};++fn text(value: &str) -> ContentBlock {+ ContentBlock::Text(TextContent::new(value))+}++#[test]+fn a_pasted_image_link_is_taken_whole() {+ let url = "https://cdn.example/images?q=thumbnail&size=10";+ let blocks = vec![text(&format!("look at {url} please"))];+ assert_eq!(linked_image_urls(&blocks), vec![url.to_owned()]);+}++#[test]+fn surrounding_punctuation_is_not_part_of_the_link() {+ let blocks = vec![text("see (https://cdn.example/a.png).")];+ assert_eq!(+ linked_image_urls(&blocks),+ vec!["https://cdn.example/a.png".to_owned()]+ );+}++#[test]+fn https_is_not_read_as_a_later_http_link() {+ let blocks = vec![text(+ "https://cdn.example/a.png and then http://cdn.example/b.jpg",+ )];+ assert_eq!(+ linked_image_urls(&blocks),+ vec![+ "https://cdn.example/a.png".to_owned(),+ "http://cdn.example/b.jpg".to_owned(),+ ]+ );+}++#[test]+fn a_link_already_carried_as_an_image_is_not_fetched_again() {+ let image = CursorPromptImage {+ data: "aW1n".to_owned(),+ mime_type: "image/png".to_owned(),+ source_url: Some("https://cdn.example/a.png".to_owned()),+ };+ let blocks = vec![text("https://cdn.example/a.png"), image.to_content_block()];+ assert!(linked_image_urls(&blocks).is_empty());+}++#[test]+fn an_svg_resource_link_is_not_fetched() {+ let blocks = vec![ContentBlock::ResourceLink(+ ResourceLink::new("icon.svg", "https://cdn.example/icon.svg").mime_type("image/svg+xml"),+ )];+ assert!(linked_image_urls(&blocks).is_empty());+}++#[test]+fn a_png_resource_link_is_fetched() {+ let blocks = vec![ContentBlock::ResourceLink(+ ResourceLink::new("shot.png", "https://cdn.example/shot.png").mime_type("image/png"),+ )];+ assert_eq!(+ linked_image_urls(&blocks),+ vec!["https://cdn.example/shot.png".to_owned()]+ );+}++#[test]+fn magic_bytes_name_the_image_when_the_type_does_not() {+ assert_eq!(+ detect_mime(+ Some("application/octet-stream"),+ &[0x89, b'P', b'N', b'G', 0x0D, 0x0A, 0x1A, 0x0A]+ ),+ Some("image/png")+ );+ assert_eq!(+ detect_mime(Some("image/jpeg"), &[0xFF, 0xD8, 0xFF, 0x00]),+ Some("image/jpeg")+ );+ assert_eq!(detect_mime(Some("text/html"), b"<html>"), None);+ assert_eq!(detect_mime(Some("image/jpg"), b""), None);+ assert_eq!(detect_mime(Some("image/png"), b"<svg>"), None);+ assert_eq!(detect_mime(Some("image/svg+xml"), b"<svg>"), None);+}++#[test]+fn a_fetched_image_is_an_acp_image_frame_named_by_its_url() {+ let image = CursorPromptImage {+ data: "aW1n".to_owned(),+ mime_type: "image/png".to_owned(),+ source_url: Some("https://cdn.example/a.png".to_owned()),+ };+ let ContentBlock::Image(frame) = image.to_content_block() else {+ panic!("an image frame");+ };+ assert_eq!(frame.data, "aW1n");+ assert_eq!(frame.mime_type, "image/png");+ assert_eq!(frame.uri.as_deref(), Some("https://cdn.example/a.png"));+}++#[test]+fn plain_http_word_does_not_hide_a_later_url() {+ assert_eq!(+ linked_image_urls(&[text("use http with https://cdn.example/pic")]),+ vec!["https://cdn.example/pic"]+ );+}++#[test]+fn duplicate_links_and_fetch_count_are_bounded() {+ let blocks = vec![text(+ "https://cdn.example/0 https://cdn.example/0 https://cdn.example/1 https://cdn.example/2 https://cdn.example/3 https://cdn.example/4 https://cdn.example/5 https://cdn.example/6 https://cdn.example/7 https://cdn.example/8",+ )];+ let urls = linked_image_urls(&blocks);+ assert_eq!(urls.len(), MAX_LINK_FETCHES);+ assert_eq!(urls[0], "https://cdn.example/0");+ assert_eq!(urls[7], "https://cdn.example/7");+}diff --git a/crates/cursor_cloud_agents/src/domain/service.rs b/crates/cursor_cloud_agents/src/domain/service.rsindex 238ca5473c..cd87dbc4aa 100644--- a/crates/cursor_cloud_agents/src/domain/service.rs+++ b/crates/cursor_cloud_agents/src/domain/service.rs@@ -47,9 +47,10 @@ use crate::domain::model::{ModelChoice, RepoUrl, RunStatus,};use crate::domain::ports::{- ArtifactStore, CursorAgents, CursorArtifacts, RepositoryChooser, RunStream, SessionIntent,- SessionNotifier, StreamConnectError,+ ArtifactStore, CursorAgents, CursorArtifacts, NoPromptImageFetcher, PromptImageFetcher,+ RepositoryChooser, RunStream, SessionIntent, SessionNotifier, StreamConnectError,};+use crate::domain::prompt_image::{self, CursorPromptImage};use agent_client_protocol::schema::v1::{ContentBlock, SessionId, SessionUpdate, StopReason, TextContent,};@@ -407,6 +408,18 @@ fn explain_rejection(error: SessionError) -> SessionError {error}+/// A user chunk that restates the prompt the client already sent.+///+/// An image frame does not: it was fetched from a pasted link, and the live+/// transcript learns the picture from this update.+fn restates_the_prompt(update: &SessionUpdate) -> bool {+ matches!(+ update,+ SessionUpdate::UserMessageChunk(chunk)+ if !matches!(chunk.content, ContentBlock::Image(_))+ )+}+/// Whether a failed create is a definite refusal — the prompt never ran, so/// it is journalled as aborted rather than left as an accepted turn.fn is_prompt_rejection(error: &SessionError) -> bool {@@ -433,9 +446,9 @@ struct RejectedPrompt {/// The prompt that finally mints an agent, carrying the ones Cursor refused/// before it so the agent reads the whole conversation the person had.///-/// Plain text rather than structure because that is all `create_agent`-/// takes; the framing tells the agent which message is current and that the-/// earlier ones were never acted on, so it neither re-does nor ignores them.+/// The framing tells the agent which message is current and that the earlier+/// ones were never acted on, so it neither re-does nor ignores them. Images+/// travel beside this text, on the prompt that is actually sent.fn prompt_with_rejected(rejected: &[RejectedPrompt], prompt: &str) -> String {if rejected.is_empty() {return prompt.to_owned();@@ -627,6 +640,8 @@ pub struct CursorSessionService<Cursor, Notifier, Chooser, Store> {/// `GET /v1/models`, fetched once. The table is static for the life of a/// process and every `session/new` would otherwise re-fetch it.models: tokio::sync::Mutex<Option<Vec<CursorModel>>>,+ /// Resolves pasted links into prompt images. Absent means links stay text.+ images: Arc<dyn PromptImageFetcher>,}impl<Cursor, Notifier, Chooser, Store> CursorSessionService<Cursor, Notifier, Chooser, Store>@@ -655,8 +670,16 @@ wheredefault_model_id: None,host_model_id: None,models: tokio::sync::Mutex::new(None),+ images: Arc::new(NoPromptImageFetcher),}}++ /// Fetch pasted links and attach the ones that are images.+ #[must_use]+ pub fn with_image_fetcher(mut self, images: Arc<dyn PromptImageFetcher>) -> Self {+ self.images = images;+ self+ }/// Pin the model every new session starts on, by id.////// The id alone, because a caller configuring this has only ever had an id@@ -1015,6 +1038,47 @@ whereoutcome}+ /// Fetch links in `blocks` and keep the ones that are images.+ ///+ /// Returns new ACP image frames to append to the original blocks and all+ /// images to send to Cursor. A failed fetch leaves the link as text.+ #[tracing::instrument(name = "cursor.prompt_images.resolve", skip_all, fields(image.count = tracing::field::Empty))]+ async fn resolve_prompt_images(+ &self,+ blocks: &[ContentBlock],+ ) -> (Vec<ContentBlock>, Vec<CursorPromptImage>) {+ let mut images = prompt_image::images_in_blocks(blocks);+ if images.len() == prompt_image::MAX_PROMPT_IMAGES {+ return (Vec::new(), images);+ }+ let mut fetched = Vec::new();+ let deadline = tokio::time::Instant::now() + std::time::Duration::from_secs(10);+ let urls = prompt_image::linked_image_urls(blocks);+ let fetcher = Arc::clone(&self.images);+ let fetches = futures::stream::iter(urls)+ .map(move |url| {+ let fetcher = Arc::clone(&fetcher);+ async move { fetcher.fetch_image(&url).await }+ })+ .buffered(prompt_image::MAX_PROMPT_IMAGES);+ futures::pin_mut!(fetches);+ while images.len() + fetched.len() < prompt_image::MAX_PROMPT_IMAGES {+ let Ok(Some(image)) = tokio::time::timeout_at(deadline, fetches.next()).await else {+ break;+ };+ if let Some(image) = image {+ fetched.push(image);+ }+ }+ tracing::Span::current().record("image.count", images.len() + fetched.len());+ let blocks = fetched+ .iter()+ .map(CursorPromptImage::to_content_block)+ .collect();+ images.extend(fetched);+ (blocks, images)+ }+async fn run_turn(&self,session_id: &SessionId,@@ -1131,6 +1195,15 @@ whereself.backfill_foreign_runs(session_id, &session, agent, None, &cancel, Emit::Silent).await?;}+ // Links are fetched before the prompt is journaled, so the record+ // holds the image frames and not only the URLs they came from.+ let (fetched, images) = tokio::select! {+ biased;+ () = cancel.cancelled() => (Vec::new(), Vec::new()),+ resolved = self.resolve_prompt_images(&blocks) => resolved,+ };+ let mut blocks = blocks;+ blocks.extend(fetched);// Preserve original content before the provider creates remote work.self.capture(session_id,@@ -1167,9 +1240,16 @@ whereSome(agent) => {// Queue behind any run still going (the same agent advances// from cursor.com too) instead of failing the prompt.- self.create_run_when_free(&session, &agent, prompt, model.as_ref(), &cancel)- .await- .map(|run| (agent, run))+ self.create_run_when_free(+ &session,+ &agent,+ prompt,+ model.as_ref(),+ &images,+ &cancel,+ )+ .await+ .map(|run| (agent, run))}None => {// Snapshotted out of the lock: `create_agent` is a network@@ -1218,6 +1298,7 @@ whereintent.open_pull_request,&mcp_servers,model.as_ref(),+ &images,).await.map_err(SessionError::from)@@ -2278,6 +2359,7 @@ whereagent: &CursorAgentId,prompt: &str,model: Option<&ModelChoice>,+ images: &[CursorPromptImage],cancel: &tokio_util::sync::CancellationToken,) -> Result<CursorRunId, SessionError> {let mut released = false;@@ -2290,7 +2372,7 @@ where.into_dynamic(),));}- match self.cursor.create_run(agent, prompt, model).await {+ match self.cursor.create_run(agent, prompt, model, images).await {Ok(run) => return Ok(run),Err(error) if error.to_string().contains("agent_busy") => {// A run this session already gave up on still holds the@@ -2943,7 +3025,7 @@ where})});for update in updates {- if local_prompt && matches!(update, SessionUpdate::UserMessageChunk(_)) {+ if local_prompt && restates_the_prompt(&update) {continue;}self.notifier.notify(id, update).await.map_err(|error| {diff --git a/crates/cursor_cloud_agents/src/domain/service/test.rs b/crates/cursor_cloud_agents/src/domain/service/test.rsindex 3c12f5ac7a..88a31b43c3 100644--- a/crates/cursor_cloud_agents/src/domain/service/test.rs+++ b/crates/cursor_cloud_agents/src/domain/service/test.rs@@ -8,9 +8,11 @@ use crate::domain::model::{ConversationLine, ConversationSpeaker, McpHeader, McpServer, McpTransport, RepoUrl, RunListing,RunOutcome, RunStatus,};-use crate::domain::ports::{NoArtifactStore, StreamConnectError};+use crate::domain::ports::{NoArtifactStore, PromptImageFetcher, StreamConnectError};+use crate::domain::prompt_image::CursorPromptImage;use crate::testing::{CursorCall, FakeCursor, FixedChooser, RecordingNotifier};-use agent_client_protocol::schema::v1::{SessionUpdate, StopReason, ToolCallStatus};+use agent_client_protocol::schema::v1::{ContentBlock, SessionUpdate, StopReason, ToolCallStatus};+use futures::future::BoxFuture;use std::path::Path;type Service = CursorSessionService<FakeCursor, RecordingNotifier, FixedChooser, NoArtifactStore>;@@ -160,7 +162,8 @@ async fn first_prompt_creates_the_agent_with_the_session_repo() {Some(repo),true,Vec::new(),- None+ None,+ Vec::new(),)]);let updates = notifier.updates();@@ -168,6 +171,67 @@ async fn first_prompt_creates_the_agent_with_the_session_repo() {assert!(matches!(updates[0].1, SessionUpdate::AgentMessageChunk(_)));}+/// A link pasted into the prompt is fetched, and when it is an image it goes+/// to Cursor as `prompt.images` and to the transcript as an ACP image frame.+#[tokio::test]+async fn a_pasted_image_link_is_sent_as_a_cursor_image() {+ let cursor = FakeCursor::new();+ let notifier = RecordingNotifier::new();+ let service = CursorSessionService::new(+ cursor.clone(),+ notifier.clone(),+ FixedChooser(None, false),+ Arc::new(crate::outbound::memory_journal::MemoryJournal::default()),+ NoArtifactStore,+ )+ .with_image_fetcher(Arc::new(ScriptedImage));+ let session = service.new_session(Path::new(""), Vec::new());+ let url = "https://cdn.example/images?q=thumbnail&size=10";++ let events = cursor.script_stream();+ events.send(finished("run-fake-1")).expect("stream open");+ events.send(CursorEvent::Done).expect("stream open");+ service+ .prompt(&session, &format!("look at {url}"))+ .await+ .expect("prompt runs");++ let calls = cursor.calls();+ let CursorCall::CreateAgent(prompt, _, _, _, _, images) = &calls[0] else {+ panic!("expected one create_agent, got {calls:?}");+ };+ assert!(prompt.contains(url), "the link stays in the prompt text");+ assert_eq!(images.len(), 1);+ assert_eq!(images[0].mime_type, "image/png");+ assert_eq!(images[0].data, "aW1n");+ assert_eq!(images[0].source_url.as_deref(), Some(url));+ assert!(+ notifier.updates().iter().any(|(_, update)| {+ matches!(+ update,+ SessionUpdate::UserMessageChunk(chunk)+ if matches!(&chunk.content, ContentBlock::Image(image)+ if image.uri.as_deref() == Some(url) && image.mime_type == "image/png")+ )+ }),+ "the transcript gets an ACP image frame"+ );+}++#[derive(Debug)]+struct ScriptedImage;++impl PromptImageFetcher for ScriptedImage {+ fn fetch_image<'a>(&'a self, url: &'a str) -> BoxFuture<'a, Option<CursorPromptImage>> {+ let image = url.contains("cdn.example").then(|| CursorPromptImage {+ data: "aW1n".to_owned(),+ mime_type: "image/png".to_owned(),+ source_url: Some(url.to_owned()),+ });+ Box::pin(async move { image })+ }+}+#[tokio::test]async fn second_prompt_follows_up_on_the_same_agent() {let (service, cursor, _notifier) = service(None);@@ -832,7 +896,8 @@ async fn session_mcp_servers_reach_agent_creation() {None,false,servers,- None+ None,+ Vec::new(),)]);}@@ -856,7 +921,8 @@ async fn a_session_without_mcp_servers_forwards_none() {None,false,Vec::new(),- None+ None,+ Vec::new(),)]);}@@ -892,7 +958,8 @@ async fn a_restored_session_prompts_its_existing_agent() {vec![CursorCall::CreateRun(CursorAgentId::new("bc-restored"),"continue".to_owned(),- None+ None,+ Vec::new(),)]);}@@ -1875,7 +1942,7 @@ async fn durable_multiturn_load_replays_full_history_and_supports_continuation()tx.send(CursorEvent::Done).unwrap();restored.prompt(&id, "continue").await.unwrap();assert!(- matches!(cursor.calls().last(), Some(CursorCall::CreateRun(_, prompt, _)) if prompt == "continue")+ matches!(cursor.calls().last(), Some(CursorCall::CreateRun(_, prompt, ..)) if prompt == "continue"));}@@ -4543,3 +4610,118 @@ async fn a_prompt_gives_up_on_the_turn_gate_after_the_busy_budget() {mirror.abort();let _ = mirror.await;}++#[derive(Debug)]+struct WaitingImage(tokio::sync::Notify);++impl PromptImageFetcher for WaitingImage {+ fn fetch_image<'a>(&'a self, _url: &'a str) -> BoxFuture<'a, Option<CursorPromptImage>> {+ Box::pin(async move {+ self.0.notify_one();+ futures::future::pending().await+ })+ }+}++#[tokio::test]+async fn stopping_during_image_resolution_never_creates_a_run() {+ let cursor = FakeCursor::new();+ let fetcher = Arc::new(WaitingImage(tokio::sync::Notify::new()));+ let service = CursorSessionService::new(+ cursor.clone(),+ RecordingNotifier::new(),+ FixedChooser(None, false),+ Arc::new(crate::outbound::memory_journal::MemoryJournal::default()),+ NoArtifactStore,+ )+ .with_image_fetcher(fetcher.clone());+ let session = service.new_session(Path::new(""), Vec::new());+ let (result, ()) = tokio::join!(service.prompt(&session, "https://cdn.example/pic"), async {+ fetcher.0.notified().await;+ service.cancel(&session).await.expect("cancel");+ },);+ assert_eq!(result.expect("cancelled prompt"), StopReason::Cancelled);+ assert!(cursor.calls().is_empty());+}++#[tokio::test(start_paused = true)]+async fn direct_images_fill_the_cap_without_fetching_links() {+ let cursor = FakeCursor::new();+ let service = CursorSessionService::new(+ cursor,+ RecordingNotifier::new(),+ FixedChooser(None, false),+ Arc::new(crate::outbound::memory_journal::MemoryJournal::default()),+ NoArtifactStore,+ )+ .with_image_fetcher(Arc::new(WaitingImage(tokio::sync::Notify::new())));+ let image = CursorPromptImage {+ data: "aW1n".into(),+ mime_type: "image/png".into(),+ source_url: None,+ };+ let mut blocks = vec![image.to_content_block(); prompt_image::MAX_PROMPT_IMAGES];+ blocks.push(ContentBlock::Text(TextContent::new(+ "https://cdn.example/pic",+ )));+ let started = tokio::time::Instant::now();+ let (_, images) = service.resolve_prompt_images(&blocks).await;+ assert_eq!(images.len(), prompt_image::MAX_PROMPT_IMAGES);+ assert_eq!(started.elapsed(), std::time::Duration::ZERO);+}++#[derive(Debug)]+struct FiveImages;+impl PromptImageFetcher for FiveImages {+ fn fetch_image<'a>(&'a self, url: &'a str) -> BoxFuture<'a, Option<CursorPromptImage>> {+ Box::pin(async move {+ if url.ends_with("/slow") {+ return futures::future::pending().await;+ }+ Some(CursorPromptImage {+ data: "aW1n".into(),+ mime_type: "image/png".into(),+ source_url: Some(url.into()),+ })+ })+ }+}++#[tokio::test(start_paused = true)]+async fn reaching_the_image_cap_does_not_wait_for_an_unused_fetch() {+ let service = CursorSessionService::new(+ FakeCursor::new(),+ RecordingNotifier::new(),+ FixedChooser(None, false),+ Arc::new(crate::outbound::memory_journal::MemoryJournal::default()),+ NoArtifactStore,+ )+ .with_image_fetcher(Arc::new(FiveImages));+ let blocks = vec![ContentBlock::Text(TextContent::new(+ "https://cdn.example/1 https://cdn.example/2 https://cdn.example/3 https://cdn.example/4 https://cdn.example/5 https://cdn.example/slow",+ ))];+ let started = tokio::time::Instant::now();+ let (_, images) = service.resolve_prompt_images(&blocks).await;+ assert_eq!(images.len(), prompt_image::MAX_PROMPT_IMAGES);+ assert_eq!(started.elapsed(), std::time::Duration::ZERO);+}++#[tokio::test(start_paused = true)]+async fn slow_image_links_leave_the_text_prompt_after_the_total_budget() {+ let service = CursorSessionService::new(+ FakeCursor::new(),+ RecordingNotifier::new(),+ FixedChooser(None, false),+ Arc::new(crate::outbound::memory_journal::MemoryJournal::default()),+ NoArtifactStore,+ )+ .with_image_fetcher(Arc::new(WaitingImage(tokio::sync::Notify::new())));+ let blocks = vec![ContentBlock::Text(TextContent::new(+ "https://cdn.example/1 https://cdn.example/2 https://cdn.example/3 https://cdn.example/4 https://cdn.example/5 https://cdn.example/6",+ ))];+ let started = tokio::time::Instant::now();+ let (resolved, images) = service.resolve_prompt_images(&blocks).await;+ assert!(images.is_empty());+ assert!(resolved.is_empty());+ assert_eq!(started.elapsed(), std::time::Duration::from_secs(10));+}diff --git a/crates/cursor_cloud_agents/src/inbound/acp.rs b/crates/cursor_cloud_agents/src/inbound/acp.rsindex 2496593424..90b7818ff1 100644--- a/crates/cursor_cloud_agents/src/inbound/acp.rs+++ b/crates/cursor_cloud_agents/src/inbound/acp.rs@@ -301,8 +301,9 @@ fn forwardable_headers(headers: Vec<HttpHeader>) -> Vec<McpHeader> {/// suppressed context the agent handles fine. HTTP and SSE MCP servers are/// forwarded to Cursor at agent creation, so those are real too — while stdio/// is declined, which is why no capability claims it (see-/// [`forwardable_mcp_servers`]). Cursor's prompt body is text-only as this-/// crate models it, so image and audio stay false.+/// [`forwardable_mcp_servers`]). Pasted links that fetch as images are sent+/// as Cursor prompt images and as ACP image frames, so image is real. Audio+/// is not.////// Nothing here can express the divergence that matters most: this agent/// never sends `session/request_permission`, because Cursor approves tool use@@ -312,7 +313,7 @@ fn forwardable_headers(headers: Vec<HttpHeader>) -> Vec<McpHeader> {/// startup instead — see the binary's docs.fn agent_capabilities() -> AgentCapabilities {AgentCapabilities::default()- .prompt_capabilities(PromptCapabilities::new().embedded_context(true))+ .prompt_capabilities(PromptCapabilities::new().embedded_context(true).image(true)).mcp_capabilities(McpCapabilities::new().http(true).sse(true))// Without this a client resuming a session it persisted never sends// `session/load` — it gives up on the session instead, which for thediff --git a/crates/cursor_cloud_agents/src/inbound/acp/snapshots/cursor_cloud_agents__inbound__acp__test__the_initialize_response_is_pinned_whole.snap b/crates/cursor_cloud_agents/src/inbound/acp/snapshots/cursor_cloud_agents__inbound__acp__test__the_initialize_response_is_pinned_whole.snapindex d6693fc344..b9adc34086 100644--- a/crates/cursor_cloud_agents/src/inbound/acp/snapshots/cursor_cloud_agents__inbound__acp__test__the_initialize_response_is_pinned_whole.snap+++ b/crates/cursor_cloud_agents/src/inbound/acp/snapshots/cursor_cloud_agents__inbound__acp__test__the_initialize_response_is_pinned_whole.snap@@ -1,6 +1,6 @@---source: crates/cursor_cloud_agents/src/inbound/acp/test.rs-assertion_line: 582+assertion_line: 707expression: response---{@@ -8,7 +8,7 @@ expression: response"agentCapabilities": {"loadSession": true,"promptCapabilities": {- "image": false,+ "image": true,"audio": false,"embeddedContext": true},diff --git a/crates/cursor_cloud_agents/src/inbound/acp/test.rs b/crates/cursor_cloud_agents/src/inbound/acp/test.rsindex fa329170e5..c9cf0fba1b 100644--- a/crates/cursor_cloud_agents/src/inbound/acp/test.rs+++ b/crates/cursor_cloud_agents/src/inbound/acp/test.rs@@ -265,8 +265,10 @@ async fn initialize_advertises_the_prompt_capabilities_we_actually_have() {capabilities.embedded_context,"resource links are handled, so embedded context must be advertised");- // Cursor's prompt body is text-only; claiming these would be a lie.- assert!(!capabilities.image);+ assert!(+ capabilities.image,+ "pasted image links are fetched and sent as prompt images"+ );assert!(!capabilities.audio);}@@ -582,7 +584,7 @@ async fn remote_mcp_servers_are_forwarded_to_the_agent() {.expect("prompt runs");let calls = cursor.calls();- let [CursorCall::CreateAgent(_, _, _, servers, _)] = calls.as_slice() else {+ let [CursorCall::CreateAgent(_, _, _, servers, _, _)] = calls.as_slice() else {panic!("expected one create_agent, got {calls:?}");};assert_eq!(@@ -663,7 +665,7 @@ async fn stdio_mcp_servers_are_declined_without_failing_the_session() {.expect("prompt runs");let calls = cursor.calls();- let [CursorCall::CreateAgent(_, _, _, servers, _)] = calls.as_slice() else {+ let [CursorCall::CreateAgent(_, _, _, servers, _, _)] = calls.as_slice() else {panic!("expected one create_agent");};let names: Vec<&str> = servers.iter().map(|server| server.name.as_str()).collect();@@ -1052,7 +1054,7 @@ async fn setting_the_model_and_effort_changes_what_the_next_run_asks_for() {.calls().into_iter().find_map(|call| match call {- CursorCall::CreateAgent(_, _, _, _, model) => Some(model),+ CursorCall::CreateAgent(_, _, _, _, model, _) => Some(model),_ => None,}).expect("the turn created an agent");@@ -1213,7 +1215,7 @@ async fn a_restored_session_keeps_its_model() {.calls().into_iter().find_map(|call| match call {- CursorCall::CreateRun(_, _, model) => Some(model),+ CursorCall::CreateRun(_, _, model, _) => Some(model),_ => None,}).expect("the restored agent got a follow-up run");@@ -1281,7 +1283,7 @@ async fn a_restored_deployment_slug_falls_back_to_cursors_default() {.calls().into_iter().find_map(|call| match call {- CursorCall::CreateRun(_, _, model) => Some(model),+ CursorCall::CreateRun(_, _, model, _) => Some(model),_ => None,}).expect("the restored agent got a follow-up run");@@ -1339,7 +1341,7 @@ async fn session_load_restores_the_clients_mcp_servers() {.expect("prompt runs");let calls = cursor.calls();- let [CursorCall::CreateAgent(_, _, _, servers, _)] = calls.as_slice() else {+ let [CursorCall::CreateAgent(_, _, _, servers, _, _)] = calls.as_slice() else {panic!("expected one agent creation, got {calls:?}");};assert_eq!(servers.len(), 1);@@ -1409,7 +1411,7 @@ async fn a_session_with_no_choice_rests_the_picker_on_auto() {.calls().into_iter().find_map(|call| match call {- CursorCall::CreateAgent(_, _, _, _, model) => Some(model),+ CursorCall::CreateAgent(_, _, _, _, model, _) => Some(model),_ => None,}).expect("the prompt created an agent");diff --git a/crates/cursor_cloud_agents/src/lib.rs b/crates/cursor_cloud_agents/src/lib.rsindex cc3dc06c63..48934ecc2c 100644--- a/crates/cursor_cloud_agents/src/lib.rs+++ b/crates/cursor_cloud_agents/src/lib.rs@@ -24,7 +24,8 @@//! writes responses and notifications to any writer. Nothing else ever//! touches that writer. Stdio is one instantiation; an in-process client over a//! `tokio::io::duplex` pipe is another.-//! - [`outbound`] holds journal storage. Standalone sessions leave the+//! - [`outbound`] holds journal storage, artifact storage, and public prompt-image+//! fetching. Standalone sessions leave the//! repository unset; hosted sessions use the harness repository chooser.//!//! The translation is deliberately a state machinediff --git a/crates/cursor_cloud_agents/src/outbound/http_prompt_images.rs b/crates/cursor_cloud_agents/src/outbound/http_prompt_images.rsnew file mode 100644index 0000000000..c974250138--- /dev/null+++ b/crates/cursor_cloud_agents/src/outbound/http_prompt_images.rs@@ -0,0 +1,262 @@+//! Fetches a pasted link and keeps it when the response is a raster image.+//!+//! Cursor can be handed a URL and fetch it itself. We fetch first because the+//! link does not say that it is an image, and because the bytes are what the+//! ACP image frame and `prompt.images.data` both need.++#[cfg(test)]+mod test;++use crate::domain::ports::PromptImageFetcher;+use crate::domain::prompt_image::{self, CursorPromptImage};+use base64::Engine as _;+use futures::StreamExt as _;+use futures::future::BoxFuture;+use reqwest::Url;+use reqwest::dns::{Addrs, Name, Resolve, Resolving};+use reqwest::header::{CONTENT_TYPE, LOCATION};+use std::net::{IpAddr, SocketAddr};+use std::sync::Arc;+use std::time::Duration;++/// How long one link may take, redirects included.+const FETCH_TIMEOUT: Duration = Duration::from_secs(10);++/// Redirects followed before giving up on the link.+const MAX_REDIRECTS: usize = 5;++/// Fetches prompt images over HTTP.+#[derive(Debug, Clone)]+pub struct HttpPromptImageFetcher {+ http: reqwest::Client,+ /// Loopback is a test stand-in. Production leaves it blocked.+ allow_loopback: bool,+}++impl HttpPromptImageFetcher {+ /// A fetcher that refuses private and loopback addresses.+ #[must_use]+ pub fn new() -> Self {+ Self::build(false)+ }++ fn build(allow_loopback: bool) -> Self {+ let http = reqwest::Client::builder()+ .redirect(reqwest::redirect::Policy::none())+ .no_proxy()+ .dns_resolver(Arc::new(PublicResolver { allow_loopback }))+ .timeout(FETCH_TIMEOUT)+ .user_agent("macro-cursor-acp")+ .build()+ .expect("the prompt image client uses a valid static TLS configuration");+ Self {+ http,+ allow_loopback,+ }+ }+}++impl Default for HttpPromptImageFetcher {+ fn default() -> Self {+ Self::new()+ }+}++#[cfg(test)]+impl HttpPromptImageFetcher {+ /// Lets a test stand-in on loopback answer. Production construction does+ /// not.+ fn allowing_loopback() -> Self {+ Self::build(true)+ }+}++impl PromptImageFetcher for HttpPromptImageFetcher {+ fn fetch_image<'a>(&'a self, url: &'a str) -> BoxFuture<'a, Option<CursorPromptImage>> {+ Box::pin(async move {+ tokio::time::timeout(FETCH_TIMEOUT, self.fetch(url))+ .await+ .ok()+ .flatten()+ })+ }+}++impl HttpPromptImageFetcher {+ #[tracing::instrument(name = "cursor.prompt_image.fetch", skip_all, fields(image.bytes = tracing::field::Empty))]+ async fn fetch(&self, url: &str) -> Option<CursorPromptImage> {+ let mut current = url.to_owned();+ for redirects in 0..=MAX_REDIRECTS {+ if !self.is_public(¤t) {+ tracing::debug!("skipping a non-public prompt link");+ return None;+ }+ let mut headers = reqwest::header::HeaderMap::new();+ macro_tower_layers::inject_trace_headers(&mut headers);+ let response = match self.http.get(¤t).headers(headers).send().await {+ Ok(response) => response,+ Err(error) => {+ tracing::debug!(+ timeout = error.is_timeout(),+ connect = error.is_connect(),+ "prompt link could not be fetched"+ );+ return None;+ }+ };+ if response.status().is_redirection() {+ if redirects == MAX_REDIRECTS {+ return None;+ }+ let next = response+ .headers()+ .get(LOCATION)+ .and_then(|value| value.to_str().ok())+ .and_then(|location| resolve_redirect(¤t, location))?;+ current = next;+ continue;+ }+ if !response.status().is_success() {+ tracing::debug!(status = %response.status(), "prompt link was not an image");+ return None;+ }+ let content_type = response+ .headers()+ .get(CONTENT_TYPE)+ .and_then(|value| value.to_str().ok())+ .map(str::to_owned);+ if !prompt_image::worth_fetching(content_type.as_deref()) {+ return None;+ }+ if response+ .content_length()+ .is_some_and(|len| len > prompt_image::MAX_IMAGE_BYTES as u64)+ {+ tracing::debug!("prompt image exceeds the size cap");+ return None;+ }+ let bytes = read_capped(response).await?;+ let mime = prompt_image::detect_mime(content_type.as_deref(), &bytes)?;+ if bytes.is_empty() || bytes.len() > prompt_image::MAX_IMAGE_BYTES {+ return None;+ }+ tracing::Span::current().record("image.bytes", bytes.len());+ return Some(CursorPromptImage {+ data: base64::engine::general_purpose::STANDARD.encode(&bytes),+ mime_type: mime.to_owned(),+ source_url: Some(url.to_owned()),+ });+ }+ None+ }++ fn is_public(&self, raw: &str) -> bool {+ let Ok(url) = Url::parse(raw) else {+ return false;+ };+ if !matches!(url.scheme(), "http" | "https")+ || !url.username().is_empty()+ || url.password().is_some()+ {+ return false;+ }+ match url.host() {+ Some(url::Host::Ipv4(ip)) => ip_allowed(IpAddr::V4(ip), self.allow_loopback),+ Some(url::Host::Ipv6(ip)) => ip_allowed(IpAddr::V6(ip), self.allow_loopback),+ Some(url::Host::Domain(host)) => !is_blocked_name(host),+ None => false,+ }+ }+}++fn is_blocked_name(host: &str) -> bool {+ let host = host.trim_end_matches('.').to_ascii_lowercase();+ host == "localhost"+ || host.ends_with(".localhost")+ || host.ends_with(".local")+ || host.ends_with(".internal")+ || host == "metadata.google.internal"+}++// Resolve and validate the very addresses reqwest connects to, rather than+// validating a separate DNS lookup which can change before the connection.+struct PublicResolver {+ allow_loopback: bool,+}++impl Resolve for PublicResolver {+ fn resolve(&self, name: Name) -> Resolving {+ let allow_loopback = self.allow_loopback;+ Box::pin(async move {+ let addresses: Vec<SocketAddr> =+ tokio::net::lookup_host((name.as_str(), 0)).await?.collect();+ if addresses.is_empty()+ || addresses+ .iter()+ .any(|addr| !ip_allowed(addr.ip(), allow_loopback))+ {+ return Err(std::io::Error::new(+ std::io::ErrorKind::PermissionDenied,+ "non-public image address",+ )+ .into());+ }+ Ok(Box::new(addresses.into_iter()) as Addrs)+ })+ }+}++fn ip_allowed(ip: IpAddr, allow_loopback: bool) -> bool {+ if allow_loopback && ip.is_loopback() {+ return true;+ }+ !is_private_ip(ip)+}++fn is_private_ip(ip: IpAddr) -> bool {+ match ip {+ IpAddr::V4(v4) => {+ v4.is_loopback()+ || v4.is_private()+ || v4.is_link_local()+ || v4.is_unspecified()+ || v4.is_broadcast()+ || v4.is_multicast()+ || v4.is_documentation()+ || v4.octets()[0] == 0+ || v4.octets()[0] >= 240+ || (v4.octets()[0] == 100 && (64..=127).contains(&v4.octets()[1]))+ || (v4.octets()[0] == 198 && matches!(v4.octets()[1], 18 | 19))+ }+ IpAddr::V6(v6) => {+ if let Some(mapped) = v6.to_ipv4_mapped() {+ return is_private_ip(IpAddr::V4(mapped));+ }+ v6.is_loopback()+ || v6.is_unspecified()+ || v6.is_unique_local()+ || v6.is_unicast_link_local()+ || v6.is_multicast()+ || (v6.segments()[0] & 0xe000) != 0x2000+ || (v6.segments()[0] == 0x2001 && v6.segments()[1] == 0x0db8)+ }+ }+}++fn resolve_redirect(current: &str, location: &str) -> Option<String> {+ let base = Url::parse(current).ok()?;+ base.join(location).ok().map(|url| url.to_string())+}++async fn read_capped(response: reqwest::Response) -> Option<Vec<u8>> {+ let mut body = Vec::new();+ let mut stream = response.bytes_stream();+ while let Some(chunk) = stream.next().await {+ let chunk = chunk.ok()?;+ if body.len().saturating_add(chunk.len()) > prompt_image::MAX_IMAGE_BYTES {+ return None;+ }+ body.extend_from_slice(&chunk);+ }+ Some(body)+}diff --git a/crates/cursor_cloud_agents/src/outbound/http_prompt_images/test.rs b/crates/cursor_cloud_agents/src/outbound/http_prompt_images/test.rsnew file mode 100644index 0000000000..2d025232d3--- /dev/null+++ b/crates/cursor_cloud_agents/src/outbound/http_prompt_images/test.rs@@ -0,0 +1,138 @@+use super::*;+use wiremock::{Mock, MockServer, ResponseTemplate, matchers::path};++const PNG: &[u8] = &[0x89, b'P', b'N', b'G', 0x0D, 0x0A, 0x1A, 0x0A, 0x00];++#[tokio::test]+async fn a_png_response_becomes_a_prompt_image() {+ let server = MockServer::start().await;+ Mock::given(path("/pic"))+ .respond_with(ResponseTemplate::new(200).set_body_raw(PNG, "image/png"))+ .expect(1)+ .mount(&server)+ .await;+ let url = format!("{}/pic", server.uri());+ let image = HttpPromptImageFetcher::allowing_loopback()+ .fetch(&url)+ .await+ .expect("png");+ assert_eq!(image.mime_type, "image/png");+ assert_eq!(image.source_url.as_deref(), Some(url.as_str()));+ assert_eq!(+ base64::engine::general_purpose::STANDARD+ .decode(image.data)+ .expect("base64"),+ PNG+ );+}++#[tokio::test]+async fn an_html_page_is_not_an_image() {+ let server = MockServer::start().await;+ Mock::given(path("/page"))+ .respond_with(+ ResponseTemplate::new(200).set_body_raw(b"<html>not a picture</html>", "text/html"),+ )+ .mount(&server)+ .await;+ assert!(+ HttpPromptImageFetcher::allowing_loopback()+ .fetch(&format!("{}/page", server.uri()))+ .await+ .is_none()+ );+}++#[tokio::test]+async fn a_redirect_cannot_reach_a_private_address() {+ let server = MockServer::start().await;+ Mock::given(path("/redirect"))+ .respond_with(+ ResponseTemplate::new(302)+ .insert_header("location", "http://169.254.169.254/latest/meta-data"),+ )+ .expect(1)+ .mount(&server)+ .await;+ assert!(+ HttpPromptImageFetcher::allowing_loopback()+ .fetch(&format!("{}/redirect", server.uri()))+ .await+ .is_none()+ );+}++#[tokio::test]+async fn relative_redirects_preserve_the_original_source_url() {+ let server = MockServer::start().await;+ Mock::given(path("/redirect"))+ .respond_with(ResponseTemplate::new(302).insert_header("location", "/pic"))+ .expect(1)+ .mount(&server)+ .await;+ Mock::given(path("/pic"))+ .respond_with(ResponseTemplate::new(200).set_body_raw(PNG, "image/png"))+ .expect(1)+ .mount(&server)+ .await;+ let url = format!("{}/redirect", server.uri());+ let image = HttpPromptImageFetcher::allowing_loopback()+ .fetch(&url)+ .await+ .expect("png");+ assert_eq!(image.source_url.as_deref(), Some(url.as_str()));+}++#[test]+fn non_public_urls_are_rejected_before_connecting() {+ let fetcher = HttpPromptImageFetcher::new();+ for url in [+ "http://127.0.0.1/pic",+ "http://10.0.0.1/pic",+ "http://169.254.169.254/pic",+ "http://100.100.100.200/pic",+ "http://0.0.0.0/pic",+ "http://224.0.0.1/pic",+ "http://[::1]/pic",+ "http://[::ffff:127.0.0.1]/pic",+ "http://[fc00::1]/pic",+ "http://[fe80::1]/pic",+ "http://localhost/pic",+ "http://service.internal/pic",+ "file:///pic",+ "https://user:[email protected]/pic",+ ] {+ assert!(!fetcher.is_public(url), "{url}");+ }+}++#[tokio::test]+async fn connection_dns_refuses_loopback() {+ let resolver = PublicResolver {+ allow_loopback: false,+ };+ assert!(+ resolver+ .resolve("localhost".parse().expect("DNS name"))+ .await+ .is_err()+ );+}++#[tokio::test]+async fn oversized_content_length_is_rejected() {+ let server = MockServer::start().await;+ Mock::given(path("/pic"))+ .respond_with(+ ResponseTemplate::new(200)+ .set_body_raw(vec![0u8; prompt_image::MAX_IMAGE_BYTES + 1], "image/png"),+ )+ .mount(&server)+ .await;+ assert!(+ HttpPromptImageFetcher::allowing_loopback()+ .fetch(&format!("{}/pic", server.uri()))+ .await+ .is_none()+ );+}diff --git a/crates/cursor_cloud_agents/src/outbound/mod.rs b/crates/cursor_cloud_agents/src/outbound/mod.rsindex 37f6d4149a..3479e7ba0f 100644--- a/crates/cursor_cloud_agents/src/outbound/mod.rs+++ b/crates/cursor_cloud_agents/src/outbound/mod.rs@@ -1,5 +1,7 @@//! Driven adapters other than the Cursor API client.+/// Fetches pasted links that turn out to be images.+pub mod http_prompt_images;/// Process-local journal for standalone agents and tests.pub mod memory_journal;/// Fenced durable journal for hosted sessions.diff --git a/crates/cursor_cloud_agents/src/testing.rs b/crates/cursor_cloud_agents/src/testing.rsindex 8b264de245..3302454649 100644--- a/crates/cursor_cloud_agents/src/testing.rs+++ b/crates/cursor_cloud_agents/src/testing.rs@@ -143,16 +143,22 @@ impl ScriptSender {/// What a [`FakeCursor`] was asked to do.#[derive(Debug, Clone, PartialEq)]pub enum CursorCall {- /// `create_agent(prompt, repo, open_pull_request, mcp_servers, model)`.+ /// `create_agent(prompt, repo, open_pull_request, mcp_servers, model, images)`.CreateAgent(String,Option<RepoUrl>,bool,Vec<McpServer>,Option<ModelChoice>,+ Vec<crate::domain::prompt_image::CursorPromptImage>,+ ),+ /// `create_run(agent, prompt, model, images)`.+ CreateRun(+ CursorAgentId,+ String,+ Option<ModelChoice>,+ Vec<crate::domain::prompt_image::CursorPromptImage>,),- /// `create_run(agent, prompt, model)`.- CreateRun(CursorAgentId, String, Option<ModelChoice>),/// `cancel_run(agent, run)`.CancelRun(CursorAgentId, CursorRunId),/// `run_result(agent, run)`.@@ -474,6 +480,7 @@ impl CursorAgents for FakeCursor {open_pull_request: bool,mcp_servers: &[McpServer],model: Option<&ModelChoice>,+ images: &[crate::domain::prompt_image::CursorPromptImage],) -> Result<(CursorAgentId, CursorRunId), rootcause::Report> {self.record(CursorCall::CreateAgent(prompt.to_owned(),@@ -481,6 +488,7 @@ impl CursorAgents for FakeCursor {open_pull_request,mcp_servers.to_vec(),model.cloned(),+ images.to_vec(),));self.await_create_gate().await;let mut state = self.inner.lock().expect("fake cursor poisoned");@@ -518,11 +526,13 @@ impl CursorAgents for FakeCursor {agent: &CursorAgentId,prompt: &str,model: Option<&ModelChoice>,+ images: &[crate::domain::prompt_image::CursorPromptImage],) -> Result<CursorRunId, rootcause::Report> {self.record(CursorCall::CreateRun(agent.clone(),prompt.to_owned(),model.cloned(),+ images.to_vec(),));self.await_create_gate().await;let mut state = self.inner.lock().expect("fake cursor poisoned");diff --git a/crates/folds/agent_fold/AGENTS.md b/crates/folds/agent_fold/AGENTS.mdindex 1b407a4440..3ce65a595d 100644--- a/crates/folds/agent_fold/AGENTS.md+++ b/crates/folds/agent_fold/AGENTS.md@@ -18,6 +18,9 @@ to the browser via `inbound/wasm`.- `src/domain/fold.rs`: the fold itself — read its module doc first; it'stotal by design (see "Why this cannot fail") and never errors on read.+- `src/domain/fold/convert.rs` + `turn.rs`: map image blocks into attachments,+ using source URLs or inline data; attach live image chunks to the user prompt+ and deduplicate attachments by URI during replay.- `src/domain/model/segment/code_execution.rs`: expands internal code receiptsinto SDK activity rows for conversation snapshots, independent of harness.- `src/domain/model.rs`: the renderable vocabulary (`FoldedMessage`,diff --git a/crates/folds/agent_fold/src/domain/fold/convert.rs b/crates/folds/agent_fold/src/domain/fold/convert.rsindex 762199e269..5b78812913 100644--- a/crates/folds/agent_fold/src/domain/fold/convert.rs+++ b/crates/folds/agent_fold/src/domain/fold/convert.rs@@ -1,7 +1,7 @@//! ACP-to-vocabulary conversions and params access shared by the handlers.use agent_client_protocol::RawJsonRpcParams;-use agent_client_protocol::schema::v1::{ContentBlock, ToolKind};+use agent_client_protocol::schema::v1::{ContentBlock, ImageContent, ToolKind};use agent_runtime_protocol::domain::action::PromptAttachment;use crate::domain::model::MessagePart;@@ -10,16 +10,15 @@ use crate::domain::model::MessagePart;pub(super) fn content_block_text(block: ContentBlock) -> Option<String> {match block {ContentBlock::Text(text) => Some(text.text),- // Images, audio, resource links and embedded resources have no text- // to fold. Resource links fold to attachment parts instead - see- // [`user_content_part`]; the rest are not rendered yet.+ // Images fold to attachment parts — see [`user_content_part`]. Audio+ // and embedded resources have nothing this side renders._ => None,}}-/// What a user's content block folds to: prose, or an attachment for the-/// `resource_link` blocks a prompt's files travel as. `None` for the block-/// kinds this side never sends in a prompt.+/// What a user's content block folds to: prose, an attachment for a+/// `resource_link`, or an attachment for an image frame. `None` for the+/// block kinds this side does not render.pub(super) fn user_content_part(block: ContentBlock) -> Option<MessagePart> {if matches!(&block, ContentBlock::Text(text) if text.meta.as_ref().and_then(|meta| meta.get(agent_runtime_protocol::domain::action::INVOCATION_CONTEXT_META)) == Some(&serde_json::Value::Bool(true))){@@ -33,9 +32,53 @@ pub(super) fn user_content_part(block: ContentBlock) -> Option<MessagePart> {size: attachment.size,});}+ if let ContentBlock::Image(image) = block {+ return image_attachment(image);+ }content_block_text(block).map(|text| MessagePart::Text { text })}+/// An image frame as an attachment. The source URL is the picture; the bytes+/// stay on the frame and are not copied into the folded message.+fn image_attachment(image: ImageContent) -> Option<MessagePart> {+ let mime_type = if image.mime_type.is_empty() {+ None+ } else {+ Some(image.mime_type.clone())+ };+ let source = image.uri.filter(|uri| !uri.is_empty());+ let uri = if let Some(uri) = source.clone() {+ uri+ } else if image.data.is_empty() {+ return None;+ } else {+ let mime = mime_type.as_deref().unwrap_or("application/octet-stream");+ format!("data:{mime};base64,{}", image.data)+ };+ let name = image_name(source.as_deref().unwrap_or(&uri), mime_type.as_deref());+ Some(MessagePart::Attachment {+ uri,+ name,+ mime_type,+ size: None,+ })+}++fn image_name(uri: &str, mime: Option<&str>) -> String {+ let path = uri.split(['?', '#']).next().unwrap_or(uri);+ if let Some(name) = path.rsplit('/').next().filter(|name| name.contains('.')) {+ return name.to_owned();+ }+ let ext = match mime {+ Some("image/png") => "png",+ Some("image/jpeg") | Some("image/jpg") => "jpg",+ Some("image/gif") => "gif",+ Some("image/webp") => "webp",+ _ => "img",+ };+ format!("image.{ext}")+}+pub(super) fn tool_kind_name(kind: ToolKind) -> &'static str {match kind {ToolKind::Read => "read",@@ -90,3 +133,8 @@ pub(super) fn deserialize_params<T: serde::de::DeserializeOwned>(RawJsonRpcParams::Array(_) => None,}}++/// Attachment identity shared by live prompts and replayed chunks.+pub(super) fn same_attachment(left: &MessagePart, right: &MessagePart) -> bool {+ matches!((left, right), (MessagePart::Attachment { uri: left, .. }, MessagePart::Attachment { uri: right, .. }) if left == right)+}diff --git a/crates/folds/agent_fold/src/domain/fold/state.rs b/crates/folds/agent_fold/src/domain/fold/state.rsindex 8eccc593da..8a0e1b22e8 100644--- a/crates/folds/agent_fold/src/domain/fold/state.rs+++ b/crates/folds/agent_fold/src/domain/fold/state.rs@@ -11,8 +11,8 @@ use crate::domain::model::{Author, Control, FoldedMessage, SessionMetadata, StopReason, ToolUseId, TurnId, TurnState,};use agent_client_protocol::schema::v1::{- CompleteElicitationNotification, CreateElicitationRequest, PromptRequest, RequestId,- RequestPermissionRequest, Response, SessionNotification, SessionUpdate,+ CompleteElicitationNotification, ContentBlock, CreateElicitationRequest, PromptRequest,+ RequestId, RequestPermissionRequest, Response, SessionNotification, SessionUpdate,};use agent_client_protocol::{JsonRpcMessage, RawJsonRpcMessage, RawJsonRpcParams};use agent_runtime_protocol::domain::action::AgentAction;@@ -491,7 +491,9 @@ impl FoldState {.collect()}// Replay has no original prompt requests: user chunks are its- // authoritative prompts. Outside load, ignore prompt echoes.+ // authoritative prompts. A live turn already has its prompt, so+ // text chunks would echo it; an image frame would not, because+ // the prompt was sent before the link was fetched.SessionUpdate::UserMessageChunk(chunk)if self.replaying|| self@@ -503,7 +505,12 @@ impl FoldState {user_content_part(chunk.content).and_then(|part| self.replay_user_part(part)),)}- SessionUpdate::UserMessageChunk(_) => Vec::new(),+ SessionUpdate::UserMessageChunk(chunk) => StepChange::message(match chunk.content {+ content @ ContentBlock::Image(_) => {+ user_content_part(content).and_then(|part| self.append_prompt_attachment(part))+ }+ _ => None,+ }),SessionUpdate::ToolCall(call) => {let mut changes =StepChange::metadata(self.sniff_harness(&ToolFrame::of_call(&call)));diff --git a/crates/folds/agent_fold/src/domain/fold/turn.rs b/crates/folds/agent_fold/src/domain/fold/turn.rsindex c261eba034..e91f4adc3e 100644--- a/crates/folds/agent_fold/src/domain/fold/turn.rs+++ b/crates/folds/agent_fold/src/domain/fold/turn.rs@@ -9,7 +9,7 @@ use chrono::{DateTime, Utc};use macro_user_id::user_id::MacroUserIdStr;use non_empty::NonEmpty;-use super::convert::{deserialize_params, user_content_part};+use super::convert::{deserialize_params, same_attachment, user_content_part};use super::state::{Changed, FoldState, Turn};impl FoldState {@@ -26,6 +26,13 @@ impl FoldState {&& let Some(message) = self.messages.last_mut()&& matches!(message.author, Author::User { .. }){+ if message+ .parts+ .iter()+ .any(|existing| same_attachment(existing, &part))+ {+ return None;+ }match part {MessagePart::Text { text } => match message.parts.get_mut(0) {Some(MessagePart::Text { text: held }) => held.push_str(&text),@@ -52,6 +59,26 @@ impl FoldState {Some(Changed::new(message))}+ /// Add an image fetched after the prompt was sent onto that prompt.+ ///+ /// The same URI already on the message is left alone: a resource link and+ /// the image frame fetched from it are one picture.+ pub(super) fn append_prompt_attachment(&mut self, part: MessagePart) -> Option<Changed> {+ let turn_id = self.turn.as_ref()?.id;+ let message = self.messages.iter().position(|message| {+ message.id == turn_id && matches!(message.author, Author::User { .. })+ })?;+ if self.messages[message]+ .parts+ .iter()+ .any(|existing| same_attachment(existing, &part))+ {+ return None;+ }+ self.messages[message].parts.push(part);+ Some(Changed::updated(message))+ }+/// Handle a `session/prompt`: emit the user's message, open a turn.pub(super) fn begin_turn(&mut self,@@ -121,7 +148,14 @@ impl FoldState {}match user_content_part(block) {Some(MessagePart::Text { text: chunk }) => text.push_str(&chunk),- Some(part) => attachments.push(part),+ Some(part)+ if !attachments+ .iter()+ .any(|existing| same_attachment(existing, &part)) =>+ {+ attachments.push(part)+ }+ Some(_) => {}None => {}}}diff --git a/crates/folds/agent_fold/src/domain/test/fold.rs b/crates/folds/agent_fold/src/domain/test/fold.rsindex 29ccd7fd69..7210f708a7 100644--- a/crates/folds/agent_fold/src/domain/test/fold.rs+++ b/crates/folds/agent_fold/src/domain/test/fold.rs@@ -960,3 +960,63 @@ fn replayed_user_chunks_keep_attached_files() {}]);}++/// An ACP image frame folds to the picture's URL, not its bytes.+#[test]+fn an_image_frame_folds_to_an_attachment() {+ let log = parse_log(+ r#"{"direction":"to_runtime","user_id":"macro|[email protected]","content":{"type":"acp","jsonrpc":"2.0","id":"p","method":"session/prompt","params":{"sessionId":"s","prompt":[{"type":"text","text":"look"},{"type":"image","data":"aW1n","mimeType":"image/png","uri":"https://cdn.example/cat.png"}]}}}"#,+ );+ let messages = fold(log);+ assert_eq!(+ messages[0].parts.as_slice(),+ &[+ MessagePart::Text {+ text: "look".to_owned()+ },+ MessagePart::Attachment {+ uri: "https://cdn.example/cat.png".to_owned(),+ name: "cat.png".to_owned(),+ mime_type: Some("image/png".to_owned()),+ size: None,+ },+ ]+ );+}++/// A link fetched after the prompt was sent still lands on that prompt.+#[test]+fn an_image_chunk_after_the_prompt_is_part_of_the_prompt() {+ let log = parse_log(concat!(+ r#"{"direction":"to_runtime","user_id":"macro|[email protected]","content":{"type":"acp","jsonrpc":"2.0","id":"p","method":"session/prompt","params":{"sessionId":"s","prompt":[{"type":"text","text":"https://cdn.example/cat.png"}]}}}"#,+ "\n",+ r#"{"direction":"to_server","content":{"type":"acp","jsonrpc":"2.0","method":"session/update","params":{"sessionId":"s","update":{"sessionUpdate":"user_message_chunk","content":{"type":"image","data":"aW1n","mimeType":"image/jpeg","uri":"https://cdn.example/cat.png"}}}}}"#,+ ));+ let messages = fold(log);+ assert_eq!(messages.len(), 1);+ assert_eq!(+ messages[0].parts.as_slice(),+ &[+ MessagePart::Text {+ text: "https://cdn.example/cat.png".to_owned()+ },+ MessagePart::Attachment {+ uri: "https://cdn.example/cat.png".to_owned(),+ name: "cat.png".to_owned(),+ mime_type: Some("image/jpeg".to_owned()),+ size: None,+ },+ ]+ );+}++#[test]+fn replay_deduplicates_a_resource_link_and_its_fetched_image() {+ let frames = vec![+ r#"{"direction":"to_server","content":{"type":"acp","jsonrpc":"2.0","method":"session/update","params":{"sessionId":"s","update":{"sessionUpdate":"user_message_chunk","content":{"type":"resource_link","uri":"https://cdn.example/photo.png","name":"photo.png","mimeType":"image/png"}}}}}"#,+ r#"{"direction":"to_server","content":{"type":"acp","jsonrpc":"2.0","method":"session/update","params":{"sessionId":"s","update":{"sessionUpdate":"user_message_chunk","content":{"type":"image","data":"aW1n","mimeType":"image/png","uri":"https://cdn.example/photo.png"}}}}}"#,+ ];+ let messages = fold(parse_log(&frames.join("\n")));+ assert_eq!(messages.len(), 1);+ assert_eq!(messages[0].parts.len(), 1);+}diff --git a/docs/agent-guide/ai-chat.md b/docs/agent-guide/ai-chat.mdindex e96ce9ef9f..e10d8644cc 100644--- a/docs/agent-guide/ai-chat.md+++ b/docs/agent-guide/ai-chat.md@@ -2056,6 +2056,18 @@ revision stale, the AI reads the latest settings and confirms a fresh proposal.Identical retries reuse the saved link. Old pending booking review requests canbe dismissed so the agent can resume with conversational confirmation.+## Images in Cursor sessions++Paste a public PNG, JPEG, GIF, or WebP URL into a Cursor prompt. After sending,+the URL stays in the message and an image thumbnail appears; click it to open+the media viewer. Extensionless image URLs work too. Reopen the session and+verify the image remains visible. Check desktop and phone layouts.++Images attached as ACP image blocks are also forwarded. Each prompt sends at+most five images of up to 15 MiB each. HTML pages, SVGs, private or loopback+addresses, failed fetches, and oversized images stay as text links. Stop during+image resolution must cancel the prompt without starting a remote run.+## Image attachments and model selectionAttach images using the plus button, paste, or drop. Image-capable models receive