fix: update process_metadata_outputs to handle serde_yaml::Value

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-27 17:47:48 -03:00
parent cb685d4329
commit 97fb35b5f0
4 changed files with 37 additions and 16 deletions

View File

@@ -169,7 +169,7 @@ impl MetaPlugin for DigestMetaPlugin {
// Add the selected hash output
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
output_name,
hash_value,
serde_yaml::Value::String(hash_value),
&self.outputs
) {
metadata.push(meta_data);

View File

@@ -223,7 +223,7 @@ impl MetaPlugin for HostnameMetaPlugin {
if hostname_enabled {
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"hostname",
hostname_value,
serde_yaml::Value::String(hostname_value),
&self.outputs
) {
metadata.push(meta_data);
@@ -234,7 +234,7 @@ impl MetaPlugin for HostnameMetaPlugin {
if hostname_full_enabled {
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"hostname_full",
full_hostname.clone(),
serde_yaml::Value::String(full_hostname.clone()),
&self.outputs
) {
metadata.push(meta_data);
@@ -245,7 +245,7 @@ impl MetaPlugin for HostnameMetaPlugin {
if hostname_short_enabled {
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"hostname_short",
short_hostname,
serde_yaml::Value::String(short_hostname),
&self.outputs
) {
metadata.push(meta_data);

View File

@@ -141,7 +141,7 @@ pub enum MetaPluginType {
/// Central function to handle metadata output with name mapping
/// outputs: HashMap where key is internal name, value is either custom name or "false" to disable
pub fn process_metadata_outputs(internal_name: &str, value: String, outputs: &std::collections::HashMap<String, serde_yaml::Value>) -> Option<MetaData> {
pub fn process_metadata_outputs(internal_name: &str, value: serde_yaml::Value, outputs: &std::collections::HashMap<String, serde_yaml::Value>) -> Option<MetaData> {
// Check if this output is disabled
if let Some(mapping) = outputs.get(internal_name) {
if let Some(false_val) = mapping.as_bool() {
@@ -151,19 +151,40 @@ pub fn process_metadata_outputs(internal_name: &str, value: String, outputs: &st
}
}
if let Some(custom_name) = mapping.as_str() {
debug!("META: Processing metadata: internal_name={}, custom_name={}, value={}", internal_name, custom_name, value);
// Convert the value to a string representation
let value_str = match &value {
serde_yaml::Value::Null => "null".to_string(),
serde_yaml::Value::Bool(b) => b.to_string(),
serde_yaml::Value::Number(n) => n.to_string(),
serde_yaml::Value::String(s) => s.clone(),
serde_yaml::Value::Sequence(_) => serde_yaml::to_string(&value).unwrap_or_else(|_| "".to_string()),
serde_yaml::Value::Mapping(_) => serde_yaml::to_string(&value).unwrap_or_else(|_| "".to_string()),
serde_yaml::Value::Tagged(_) => serde_yaml::to_string(&value).unwrap_or_else(|_| "".to_string()),
};
debug!("META: Processing metadata: internal_name={}, custom_name={}, value={}", internal_name, custom_name, value_str);
return Some(MetaData {
name: custom_name.to_string(),
value,
value: value_str,
});
}
}
// Convert the value to a string representation
let value_str = match &value {
serde_yaml::Value::Null => "null".to_string(),
serde_yaml::Value::Bool(b) => b.to_string(),
serde_yaml::Value::Number(n) => n.to_string(),
serde_yaml::Value::String(s) => s.clone(),
serde_yaml::Value::Sequence(_) => serde_yaml::to_string(&value).unwrap_or_else(|_| "".to_string()),
serde_yaml::Value::Mapping(_) => serde_yaml::to_string(&value).unwrap_or_else(|_| "".to_string()),
serde_yaml::Value::Tagged(_) => serde_yaml::to_string(&value).unwrap_or_else(|_| "".to_string()),
};
// Default: use internal name as output name
debug!("META: Processing metadata: name={}, value={}", internal_name, value);
debug!("META: Processing metadata: name={}, value={}", internal_name, value_str);
Some(MetaData {
name: internal_name.to_string(),
value,
value: value_str,
})
}

View File

@@ -209,7 +209,7 @@ impl TextMetaPlugin {
// Use process_metadata_outputs to handle output mapping
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"text",
text_value,
serde_yaml::Value::String(text_value),
self.base.outputs()
) {
metadata.push(meta_data);
@@ -217,7 +217,7 @@ impl TextMetaPlugin {
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"binary",
binary_value,
serde_yaml::Value::String(binary_value),
self.base.outputs()
) {
metadata.push(meta_data);
@@ -277,7 +277,7 @@ impl TextMetaPlugin {
if self.track_word_count {
crate::meta_plugin::process_metadata_outputs(
"text_word_count",
self.word_count.to_string(),
serde_yaml::Value::String(self.word_count.to_string()),
self.base.outputs()
)
} else {
@@ -290,7 +290,7 @@ impl TextMetaPlugin {
if self.track_line_count {
crate::meta_plugin::process_metadata_outputs(
"text_line_count",
self.line_count.to_string(),
serde_yaml::Value::String(self.line_count.to_string()),
self.base.outputs()
)
} else {
@@ -303,7 +303,7 @@ impl TextMetaPlugin {
if self.output_line_max_len && self.line_count_for_stats > 0 {
crate::meta_plugin::process_metadata_outputs(
"text_line_max_len",
self.max_line_length.to_string(),
serde_yaml::Value::String(self.max_line_length.to_string()),
self.base.outputs()
)
} else {
@@ -319,7 +319,7 @@ impl TextMetaPlugin {
let mean_len_int = mean_len.round() as usize;
crate::meta_plugin::process_metadata_outputs(
"text_line_mean_len",
mean_len_int.to_string(),
serde_yaml::Value::String(mean_len_int.to_string()),
self.base.outputs()
)
} else {
@@ -342,7 +342,7 @@ impl TextMetaPlugin {
return crate::meta_plugin::process_metadata_outputs(
"text_line_median_len",
median_len.to_string(),
serde_yaml::Value::String(median_len.to_string()),
self.base.outputs()
);
}