refactor: compose BaseMetaPlugin in remaining meta plugins
Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
use std::process;
|
||||
use crate::meta_plugin::{MetaPlugin, MetaPluginType};
|
||||
use crate::meta_plugin::{MetaPlugin, MetaPluginType, BaseMetaPlugin};
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct KeepPidMetaPlugin {
|
||||
is_finalized: bool,
|
||||
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
options: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
base: BaseMetaPlugin,
|
||||
}
|
||||
|
||||
impl KeepPidMetaPlugin {
|
||||
@@ -23,30 +22,15 @@ impl KeepPidMetaPlugin {
|
||||
_options: Option<std::collections::HashMap<String, serde_yaml::Value>>,
|
||||
outputs: Option<std::collections::HashMap<String, serde_yaml::Value>>,
|
||||
) -> KeepPidMetaPlugin {
|
||||
// Start with default options
|
||||
let mut final_options = std::collections::HashMap::new();
|
||||
if let Some(opts) = _options {
|
||||
for (key, value) in opts {
|
||||
final_options.insert(key, value);
|
||||
}
|
||||
}
|
||||
let mut base = BaseMetaPlugin::new();
|
||||
|
||||
// Start with default outputs
|
||||
let mut final_outputs = std::collections::HashMap::new();
|
||||
let default_outputs = Self::default().default_outputs();
|
||||
for output_name in default_outputs {
|
||||
final_outputs.insert(output_name.clone(), serde_yaml::Value::String(output_name));
|
||||
}
|
||||
if let Some(outs) = outputs {
|
||||
for (key, value) in outs {
|
||||
final_outputs.insert(key, value);
|
||||
}
|
||||
}
|
||||
// Set default outputs
|
||||
let default_outputs = &["keep_pid"];
|
||||
base.initialize_plugin(default_outputs, _options, outputs);
|
||||
|
||||
KeepPidMetaPlugin {
|
||||
is_finalized: false,
|
||||
outputs: final_outputs,
|
||||
options: final_options,
|
||||
base,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,13 +111,51 @@ impl MetaPlugin for KeepPidMetaPlugin {
|
||||
MetaPluginType::KeepPid
|
||||
}
|
||||
|
||||
/// Initializes the plugin and captures the process PID.
|
||||
///
|
||||
/// Retrieves the current process ID and adds it to metadata.
|
||||
/// Marks the plugin as finalized after one run.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `MetaPluginResponse` - Response with PID metadata and finalized state.
|
||||
fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
||||
// If already finalized, don't process again
|
||||
if self.is_finalized {
|
||||
return crate::meta_plugin::MetaPluginResponse {
|
||||
metadata: Vec::new(),
|
||||
is_finalized: true,
|
||||
};
|
||||
}
|
||||
|
||||
let mut metadata = Vec::new();
|
||||
let pid = process::id().to_string();
|
||||
|
||||
// Use process_metadata_outputs to handle output mapping
|
||||
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
|
||||
"keep_pid",
|
||||
serde_yaml::Value::String(pid),
|
||||
self.base.outputs()
|
||||
) {
|
||||
metadata.push(meta_data);
|
||||
}
|
||||
|
||||
// Mark as finalized since this plugin only needs to run once
|
||||
self.is_finalized = true;
|
||||
|
||||
crate::meta_plugin::MetaPluginResponse {
|
||||
metadata,
|
||||
is_finalized: true,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a reference to the outputs mapping.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// A reference to the `HashMap` of outputs.
|
||||
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&self.outputs
|
||||
self.base.outputs()
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the outputs mapping.
|
||||
@@ -142,10 +164,17 @@ impl MetaPlugin for KeepPidMetaPlugin {
|
||||
///
|
||||
/// A mutable reference to the `HashMap` of outputs.
|
||||
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&mut self.outputs
|
||||
self.base.outputs_mut()
|
||||
}
|
||||
|
||||
|
||||
/// Returns the default output names for this plugin.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Vector containing "keep_pid".
|
||||
fn default_outputs(&self) -> Vec<String> {
|
||||
vec!["keep_pid".to_string()]
|
||||
}
|
||||
|
||||
/// Returns a reference to the options mapping.
|
||||
///
|
||||
@@ -153,7 +182,7 @@ impl MetaPlugin for KeepPidMetaPlugin {
|
||||
///
|
||||
/// A reference to the `HashMap` of options.
|
||||
fn options(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&self.options
|
||||
self.base.options()
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the options mapping.
|
||||
@@ -162,7 +191,7 @@ impl MetaPlugin for KeepPidMetaPlugin {
|
||||
///
|
||||
/// A mutable reference to the `HashMap` of options.
|
||||
fn options_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&mut self.options
|
||||
self.base.options_mut()
|
||||
}
|
||||
}
|
||||
use crate::meta_plugin::register_meta_plugin;
|
||||
|
||||
Reference in New Issue
Block a user