first pass of merging in warp (doesn't build)

This commit is contained in:
Ryan Ward
2026-07-01 16:08:58 -05:00
parent 2f64909469
commit 4770ac06b5
3662 changed files with 414574 additions and 89772 deletions
+26
View File
@@ -3,13 +3,39 @@
//! This module provides common functionality for processing images before they are
//! sent to the AI agent, whether attached by the user or read via the read_files tool.
use std::path::Path;
use image::{GenericImageView, ImageError};
use mime_guess::from_path;
/// Max image size is 3.75 MB.
/// The max size of an image we will send is 5MB. However, due to the 33% inflation of Base64, this means
/// the largest size a user can attach is actually ~3.75MB.
pub const MAX_IMAGE_SIZE_BYTES: usize = 3750 * 1000;
/// Cap on individual image bytes when relaying a dropped/pasted image to a
/// CLI agent (Claude Code etc.) via the system clipboard. CLI agents handle
/// their own compression, so this limit only exists to keep us from loading
/// arbitrarily large files into memory.
pub const MAX_IMAGE_SIZE_BYTES_FOR_CLI_AGENT: usize = 500 * 1_000_000;
/// How many leading bytes of a file are enough for `infer_mime_type` to
/// match a magic-number signature. Callers that already have the full bytes
/// in memory should pass only the first `MIME_SNIFF_BYTES` to avoid handing
/// arbitrarily large slices to the sniffer.
pub const MIME_SNIFF_BYTES: usize = 8 * 1024;
/// Returns the MIME type for `path`, preferring magic-byte detection from
/// `file_bytes` and falling back to the path's extension when the magic
/// bytes don't yield a confident match. Falls all the way back to
/// `application/octet-stream`. `file_bytes` only needs to contain the first
/// `MIME_SNIFF_BYTES` of the file for the magic-number check.
pub fn infer_mime_type(path: &Path, file_bytes: &[u8]) -> String {
infer::get(file_bytes)
.map(|kind| kind.mime_type().to_string())
.unwrap_or_else(|| from_path(path).first_or_octet_stream().to_string())
}
/// 1.15 Megapixels
pub const MAX_IMAGE_PIXELS: f64 = 1150. * 1000.;