feat: replace binary detection with text metadata check

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-28 13:09:00 -03:00
parent 9e3df98e79
commit f6220eb16e
4 changed files with 14 additions and 14 deletions

View File

@@ -43,10 +43,10 @@ pub fn mode_get(
if detect_binary {
let meta_map = item_with_meta.meta_as_map();
if let Some(binary_val) = meta_map.get("binary") {
if binary_val == "false" {
if let Some(text_val) = meta_map.get("text") {
if text_val == "true" {
detect_binary = false;
} else if binary_val == "true" {
} else if text_val == "false" {
return Err(anyhow!(
"Refusing to output binary data to TTY, use --force to override"
));

View File

@@ -258,10 +258,10 @@ async fn stream_item_content_response_with_metadata(
// Check if content is binary when allow_binary is false
if !allow_binary {
let is_binary = if let Some(binary_val) = metadata.get("binary") {
binary_val == "true"
let is_binary = if let Some(text_val) = metadata.get("text") {
text_val == "false"
} else {
// If binary metadata isn't set, we need to check the content using streaming approach
// If text metadata isn't set, we need to check the content using streaming approach
match item_service.get_item_content_info_streaming(item_id).await {
Ok((_, _, is_binary)) => is_binary,
Err(e) => {

View File

@@ -97,8 +97,8 @@ impl AsyncItemService {
.map(|s| s.to_string())
.unwrap_or_else(|| "application/octet-stream".to_string());
let is_binary = if let Some(binary_val) = metadata.get("binary") {
binary_val == "true"
let is_binary = if let Some(text_val) = metadata.get("text") {
text_val == "false"
} else {
crate::common::is_binary::is_binary(&content_clone)
};
@@ -154,8 +154,8 @@ impl AsyncItemService {
// Check if content is binary when allow_binary is false
if !allow_binary {
let is_binary = if let Some(binary_val) = metadata.get("binary") {
binary_val == "true"
let is_binary = if let Some(text_val) = metadata.get("text") {
text_val == "false"
} else {
// Get binary status using streaming approach
let (_, _, is_binary) = self.get_item_content_info_streaming(item_id).await?;

View File

@@ -77,8 +77,8 @@ impl ItemService {
.unwrap_or_else(|| "application/octet-stream".to_string());
// Check if content is binary
let is_binary = if let Some(binary_val) = metadata.get("binary") {
binary_val == "true"
let is_binary = if let Some(text_val) = metadata.get("text") {
text_val == "false"
} else {
crate::common::is_binary::is_binary(&item_with_content.content)
};
@@ -110,8 +110,8 @@ impl ItemService {
.unwrap_or_else(|| "application/octet-stream".to_string());
// Check if content is binary using only the first 8192 bytes
let is_binary = if let Some(binary_val) = metadata.get("binary") {
binary_val == "true"
let is_binary = if let Some(text_val) = metadata.get("text") {
text_val == "false"
} else {
// Read only the first 8192 bytes for binary detection
let mut sample_reader = self.compression_service.stream_item_content(