refactor: split system plugins into individual files
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
152
src/meta_plugin/system/shell.rs
Normal file
152
src/meta_plugin/system/shell.rs
Normal file
@@ -0,0 +1,152 @@
|
||||
use std::env;
|
||||
use crate::meta_plugin::MetaPlugin;
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ShellMetaPlugin {
|
||||
meta_name: String,
|
||||
is_finalized: bool,
|
||||
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
options: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
}
|
||||
|
||||
impl ShellMetaPlugin {
|
||||
pub fn new(
|
||||
_options: Option<std::collections::HashMap<String, serde_yaml::Value>>,
|
||||
outputs: Option<std::collections::HashMap<String, serde_yaml::Value>>,
|
||||
) -> ShellMetaPlugin {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
ShellMetaPlugin {
|
||||
meta_name: "shell".to_string(),
|
||||
is_finalized: false,
|
||||
outputs: final_outputs,
|
||||
options: final_options,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_simple() -> ShellMetaPlugin {
|
||||
Self::new(None, None)
|
||||
}
|
||||
}
|
||||
|
||||
impl MetaPlugin for ShellMetaPlugin {
|
||||
fn is_finalized(&self) -> bool {
|
||||
self.is_finalized
|
||||
}
|
||||
|
||||
fn set_finalized(&mut self, finalized: bool) {
|
||||
self.is_finalized = finalized;
|
||||
}
|
||||
|
||||
fn finalize(&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,
|
||||
};
|
||||
}
|
||||
|
||||
// Mark as finalized
|
||||
self.is_finalized = true;
|
||||
|
||||
crate::meta_plugin::MetaPluginResponse {
|
||||
metadata: Vec::new(),
|
||||
is_finalized: true,
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self, _data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
|
||||
// If already finalized, don't process more data
|
||||
if self.is_finalized {
|
||||
return crate::meta_plugin::MetaPluginResponse {
|
||||
metadata: Vec::new(),
|
||||
is_finalized: true,
|
||||
};
|
||||
}
|
||||
|
||||
crate::meta_plugin::MetaPluginResponse {
|
||||
metadata: Vec::new(),
|
||||
is_finalized: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn meta_name(&self) -> String {
|
||||
self.meta_name.clone()
|
||||
}
|
||||
|
||||
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 shell = match env::var("SHELL") {
|
||||
Ok(shell) => shell,
|
||||
Err(_) => "unknown".to_string(),
|
||||
};
|
||||
|
||||
// Use process_metadata_outputs to handle output mapping
|
||||
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
|
||||
"shell",
|
||||
shell,
|
||||
&self.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,
|
||||
}
|
||||
}
|
||||
|
||||
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&self.outputs
|
||||
}
|
||||
|
||||
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&mut self.outputs
|
||||
}
|
||||
|
||||
fn default_outputs(&self) -> Vec<String> {
|
||||
vec!["shell".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.options
|
||||
}
|
||||
|
||||
fn options_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&mut self.options
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user