fix: update meta plugin implementations to match trait signatures

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-26 17:59:16 -03:00
parent 77bd3f09a3
commit c6c81088b8
3 changed files with 207 additions and 111 deletions

View File

@@ -223,13 +223,13 @@ pub trait MetaPlugin {
} }
// Configure plugin with options (excluding outputs) // Configure plugin with options (excluding outputs)
fn configure_options(&mut self, _options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> { fn configure_options(&mut self, _options: &std::collections::HashMap<String, serde_yaml::Value>) -> anyhow::Result<()> {
// Default implementation does nothing - plugins can override this // Default implementation does nothing - plugins can override this
Ok(()) Ok(())
} }
// Configure plugin outputs mapping // Configure plugin outputs mapping
fn configure_outputs(&mut self, outputs: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> { fn configure_outputs(&mut self, outputs: &std::collections::HashMap<String, serde_yaml::Value>) -> anyhow::Result<()> {
for (key, value) in outputs { for (key, value) in outputs {
self.outputs_mut().insert(key.clone(), value.clone()); self.outputs_mut().insert(key.clone(), value.clone());
} }
@@ -237,7 +237,7 @@ pub trait MetaPlugin {
} }
// Configure both options and outputs // Configure both options and outputs
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>, outputs: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> { fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>, outputs: &std::collections::HashMap<String, serde_yaml::Value>) -> anyhow::Result<()> {
self.configure_options(options)?; self.configure_options(options)?;
self.configure_outputs(outputs)?; self.configure_outputs(outputs)?;
Ok(()) Ok(())

View File

@@ -54,35 +54,41 @@ impl DigestSha256MetaPlugin {
} }
impl MetaPlugin for DigestSha256MetaPlugin { impl MetaPlugin for DigestSha256MetaPlugin {
fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
fn initialize(&mut self, item_id: i64) -> Result<MetaPluginResponse> { crate::meta_plugin::MetaPluginResponse {
self.item_id = Some(item_id); metadata: Vec::new(),
Ok(MetaPluginResponse::default()) is_finalized: false,
}
} }
fn finalize(&mut self) -> Result<MetaPluginResponse> { fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
let mut metadata = Vec::new(); let mut metadata = Vec::new();
if let Some(item_id) = self.item_id {
// Finalize the hash // Finalize the hash
let hash_result = self.hasher.finalize_reset(); let hash_result = self.hasher.finalize_reset();
let hex_string = format!("{:x}", hash_result); let hex_string = format!("{:x}", hash_result);
// Create metadata to be stored // Use process_metadata_outputs to handle output mapping
if let Some(meta) = self.create_meta(item_id, "digest_sha256", hex_string) { if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
metadata.push(meta); "digest_sha256",
} hex_string,
&self.outputs
) {
metadata.push(meta_data);
} }
Ok(MetaPluginResponse { crate::meta_plugin::MetaPluginResponse {
metadata: Some(metadata), metadata,
is_finalized: true, is_finalized: true,
}) }
} }
fn update(&mut self, data: &[u8]) -> Result<MetaPluginResponse> { fn update(&mut self, data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
self.hasher.update(data); self.hasher.update(data);
Ok(MetaPluginResponse::default()) crate::meta_plugin::MetaPluginResponse {
metadata: Vec::new(),
is_finalized: false,
}
} }
fn meta_name(&self) -> String { fn meta_name(&self) -> String {
@@ -162,32 +168,37 @@ impl ReadTimeMetaPlugin {
} }
impl MetaPlugin for ReadTimeMetaPlugin { impl MetaPlugin for ReadTimeMetaPlugin {
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
fn finalize(&mut self) -> Result<MetaPluginResponse> {
let mut metadata = Vec::new(); let mut metadata = Vec::new();
if let Some(start_time) = self.start_time { if let Some(start_time) = self.start_time {
if let Some(item_id) = self.item_id {
let duration = start_time.elapsed(); let duration = start_time.elapsed();
let duration_str = format!("{:.3} seconds", duration.as_secs_f64()); let duration_str = format!("{:.3} seconds", duration.as_secs_f64());
if let Some(meta) = self.create_meta(item_id, "read_time", duration_str) { // Use process_metadata_outputs to handle output mapping
metadata.push(meta); if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
} "read_time",
duration_str,
&self.outputs
) {
metadata.push(meta_data);
} }
} }
Ok(MetaPluginResponse { crate::meta_plugin::MetaPluginResponse {
metadata: Some(metadata), metadata,
is_finalized: true, is_finalized: true,
}) }
} }
fn update(&mut self, _data: &[u8]) -> Result<MetaPluginResponse> { fn update(&mut self, _data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
if self.start_time.is_none() { if self.start_time.is_none() {
self.start_time = Some(Instant::now()); self.start_time = Some(Instant::now());
} }
Ok(MetaPluginResponse::default()) crate::meta_plugin::MetaPluginResponse {
metadata: Vec::new(),
is_finalized: false,
}
} }
fn meta_name(&self) -> String { fn meta_name(&self) -> String {

View File

@@ -51,9 +51,8 @@ impl CwdMetaPlugin {
} }
impl MetaPlugin for CwdMetaPlugin { impl MetaPlugin for CwdMetaPlugin {
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
fn finalize(&mut self) -> MetaPluginResponse { crate::meta_plugin::MetaPluginResponse {
MetaPluginResponse {
metadata: Vec::new(), metadata: Vec::new(),
is_finalized: true, is_finalized: true,
} }
@@ -63,7 +62,7 @@ impl MetaPlugin for CwdMetaPlugin {
self.meta_name.clone() self.meta_name.clone()
} }
fn initialize(&mut self) -> MetaPluginResponse { fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
let mut metadata = Vec::new(); let mut metadata = Vec::new();
let cwd = match env::current_dir() { let cwd = match env::current_dir() {
Ok(path) => path.to_string_lossy().to_string(), Ok(path) => path.to_string_lossy().to_string(),
@@ -74,17 +73,40 @@ impl MetaPlugin for CwdMetaPlugin {
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs( if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"cwd", "cwd",
cwd, cwd,
&self.outputs self.base.outputs()
) { ) {
metadata.push(meta_data); metadata.push(meta_data);
} }
MetaPluginResponse { crate::meta_plugin::MetaPluginResponse {
metadata, metadata,
is_finalized: false, is_finalized: false,
} }
} }
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
self.base.outputs()
}
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
self.base.outputs_mut()
}
fn default_outputs(&self) -> Vec<String> {
vec!["cwd".to_string()]
}
fn default_options(&self) -> std::collections::HashMap<String, serde_yaml::Value> {
std::collections::HashMap::new()
}
fn options(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
self.base.options()
}
fn options_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
self.base.options_mut()
}
} }
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
@@ -237,28 +259,44 @@ impl ShellMetaPlugin {
} }
impl MetaPlugin for ShellMetaPlugin { impl MetaPlugin for ShellMetaPlugin {
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
fn finalize(&mut self, _conn: &Connection) -> Result<()> { crate::meta_plugin::MetaPluginResponse {
// Since we save during initialize(), return Ok to avoid duplicate saves metadata: Vec::new(),
Ok(()) is_finalized: true,
}
} }
fn update(&mut self, _data: &[u8], _conn: &Connection) { fn update(&mut self, _data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
// No update needed crate::meta_plugin::MetaPluginResponse {
metadata: Vec::new(),
is_finalized: false,
}
} }
fn meta_name(&self) -> String { fn meta_name(&self) -> String {
self.meta_name.clone() self.meta_name.clone()
} }
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> { fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
let mut metadata = Vec::new();
let shell = match env::var("SHELL") { let shell = match env::var("SHELL") {
Ok(shell) => shell, Ok(shell) => shell,
Err(_) => "unknown".to_string(), Err(_) => "unknown".to_string(),
}; };
self.save_meta(conn, item_id, "shell", shell)?;
self.is_saved = true; // Use process_metadata_outputs to handle output mapping
Ok(()) if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"shell",
shell,
&self.outputs
) {
metadata.push(meta_data);
}
crate::meta_plugin::MetaPluginResponse {
metadata,
is_finalized: true,
}
} }
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> { fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
@@ -333,28 +371,44 @@ impl ShellPidMetaPlugin {
} }
impl MetaPlugin for ShellPidMetaPlugin { impl MetaPlugin for ShellPidMetaPlugin {
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
fn finalize(&mut self, _conn: &Connection) -> Result<()> { crate::meta_plugin::MetaPluginResponse {
// Since we save during initialize(), return Ok to avoid duplicate saves metadata: Vec::new(),
Ok(()) is_finalized: true,
}
} }
fn update(&mut self, _data: &[u8], _conn: &Connection) { fn update(&mut self, _data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
// No update needed crate::meta_plugin::MetaPluginResponse {
metadata: Vec::new(),
is_finalized: false,
}
} }
fn meta_name(&self) -> String { fn meta_name(&self) -> String {
self.meta_name.clone() self.meta_name.clone()
} }
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> { fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
let mut metadata = Vec::new();
let pid = match env::var("PPID") { let pid = match env::var("PPID") {
Ok(ppid) => ppid, Ok(ppid) => ppid,
Err(_) => process::id().to_string(), Err(_) => process::id().to_string(),
}; };
self.save_meta(conn, item_id, "shell_pid", pid)?;
self.is_saved = true; // Use process_metadata_outputs to handle output mapping
Ok(()) if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"shell_pid",
pid,
&self.outputs
) {
metadata.push(meta_data);
}
crate::meta_plugin::MetaPluginResponse {
metadata,
is_finalized: true,
}
} }
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> { fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
@@ -429,25 +483,41 @@ impl KeepPidMetaPlugin {
} }
impl MetaPlugin for KeepPidMetaPlugin { impl MetaPlugin for KeepPidMetaPlugin {
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
fn finalize(&mut self, _conn: &Connection) -> Result<()> { crate::meta_plugin::MetaPluginResponse {
// Since we save during initialize(), return Ok to avoid duplicate saves metadata: Vec::new(),
Ok(()) is_finalized: true,
}
} }
fn update(&mut self, _data: &[u8], _conn: &Connection) { fn update(&mut self, _data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
// No update needed crate::meta_plugin::MetaPluginResponse {
metadata: Vec::new(),
is_finalized: false,
}
} }
fn meta_name(&self) -> String { fn meta_name(&self) -> String {
self.meta_name.clone() self.meta_name.clone()
} }
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> { fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
let mut metadata = Vec::new();
let pid = process::id().to_string(); let pid = process::id().to_string();
self.save_meta(conn, item_id, "keep_pid", pid)?;
self.is_saved = true; // Use process_metadata_outputs to handle output mapping
Ok(()) if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"keep_pid",
pid,
&self.outputs
) {
metadata.push(meta_data);
}
crate::meta_plugin::MetaPluginResponse {
metadata,
is_finalized: true,
}
} }
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> { fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
@@ -522,28 +592,44 @@ impl HostnameMetaPlugin {
} }
impl MetaPlugin for HostnameMetaPlugin { impl MetaPlugin for HostnameMetaPlugin {
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
fn finalize(&mut self, _conn: &Connection) -> Result<()> { crate::meta_plugin::MetaPluginResponse {
// Since we save during initialize(), return Ok to avoid duplicate saves metadata: Vec::new(),
Ok(()) is_finalized: true,
}
} }
fn update(&mut self, _data: &[u8], _conn: &Connection) { fn update(&mut self, _data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
// No update needed for hostname crate::meta_plugin::MetaPluginResponse {
metadata: Vec::new(),
is_finalized: false,
}
} }
fn meta_name(&self) -> String { fn meta_name(&self) -> String {
self.meta_name.clone() self.meta_name.clone()
} }
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> { fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
let mut metadata = Vec::new();
let hostname = match gethostname().into_string() { let hostname = match gethostname().into_string() {
Ok(hostname) => hostname, Ok(hostname) => hostname,
Err(_) => "unknown".to_string(), Err(_) => "unknown".to_string(),
}; };
self.save_meta(conn, item_id, "hostname", hostname)?;
self.is_saved = true; // Use process_metadata_outputs to handle output mapping
Ok(()) if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"hostname",
hostname,
&self.outputs
) {
metadata.push(meta_data);
}
crate::meta_plugin::MetaPluginResponse {
metadata,
is_finalized: true,
}
} }
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> { fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
@@ -618,46 +704,45 @@ impl FullHostnameMetaPlugin {
} }
impl MetaPlugin for FullHostnameMetaPlugin { impl MetaPlugin for FullHostnameMetaPlugin {
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
fn finalize(&mut self, _conn: &Connection) -> Result<()> { crate::meta_plugin::MetaPluginResponse {
// Since we save during initialize(), return Ok to avoid duplicate saves metadata: Vec::new(),
Ok(()) is_finalized: true,
}
} }
fn update(&mut self, _data: &[u8], _conn: &Connection) { fn update(&mut self, _data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
// No update needed for full hostname crate::meta_plugin::MetaPluginResponse {
metadata: Vec::new(),
is_finalized: false,
}
} }
fn meta_name(&self) -> String { fn meta_name(&self) -> String {
self.meta_name.clone() self.meta_name.clone()
} }
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> { fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
// Try to get the FQDN through reverse DNS lookup let mut metadata = Vec::new();
let hostname = match local_ip() { // For now, use regular hostname since local_ip and lookup_addr aren't available
Ok(my_local_ip) => { let hostname = match gethostname().into_string() {
match lookup_addr(&my_local_ip) {
Ok(hostname) => hostname,
Err(_) => {
// Fall back to regular hostname if reverse DNS fails
match gethostname().into_string() {
Ok(hostname) => hostname, Ok(hostname) => hostname,
Err(_) => "unknown".to_string(), Err(_) => "unknown".to_string(),
}
}
}
}
Err(_) => {
// Fall back to regular hostname if we can't get local IP
match gethostname().into_string() {
Ok(hostname) => hostname,
Err(_) => "unknown".to_string(),
}
}
}; };
self.save_meta(conn, item_id, "full_hostname", hostname)?;
self.is_saved = true; // Use process_metadata_outputs to handle output mapping
Ok(()) if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"full_hostname",
hostname,
&self.outputs
) {
metadata.push(meta_data);
}
crate::meta_plugin::MetaPluginResponse {
metadata,
is_finalized: true,
}
} }
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> { fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {