refactor: update meta plugin to use output mappings
Co-authored-by: aider (openai/andrew/openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
This commit is contained in:
@@ -13,7 +13,7 @@ use crate::meta_plugin::{MetaPlugin, output_metadata};
|
||||
pub struct CwdMetaPlugin {
|
||||
meta_name: String,
|
||||
is_saved: bool,
|
||||
output_names: std::collections::HashMap<String, String>,
|
||||
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
}
|
||||
|
||||
impl CwdMetaPlugin {
|
||||
@@ -21,7 +21,7 @@ impl CwdMetaPlugin {
|
||||
CwdMetaPlugin {
|
||||
meta_name: "cwd".to_string(),
|
||||
is_saved: false,
|
||||
output_names: std::collections::HashMap::new(),
|
||||
outputs: std::collections::HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ impl MetaPlugin for CwdMetaPlugin {
|
||||
Err(_) => "unknown".to_string(),
|
||||
};
|
||||
// Use central output handler
|
||||
output_metadata(conn, item_id, &self.meta_name, cwd, &self.output_names)?;
|
||||
self.save_meta(conn, item_id, "cwd", cwd)?;
|
||||
self.is_saved = true;
|
||||
Ok(())
|
||||
}
|
||||
@@ -59,8 +59,8 @@ impl MetaPlugin for CwdMetaPlugin {
|
||||
if let Some(outputs) = options.get("outputs") {
|
||||
if let Some(outputs_map) = outputs.as_mapping() {
|
||||
for (key, value) in outputs_map {
|
||||
if let (Some(key_str), Some(value_str)) = (key.as_str(), value.as_str()) {
|
||||
self.output_names.insert(key_str.to_string(), value_str.to_string());
|
||||
if let Some(key_str) = key.as_str() {
|
||||
self.outputs.insert(key_str.to_string(), value.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,8 +68,12 @@ impl MetaPlugin for CwdMetaPlugin {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_output_name(&self, default_name: &str) -> String {
|
||||
self.output_names.get(default_name).cloned().unwrap_or_else(|| default_name.to_string())
|
||||
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&self.outputs
|
||||
}
|
||||
|
||||
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||
self.outputs = outputs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +81,7 @@ impl MetaPlugin for CwdMetaPlugin {
|
||||
pub struct UidMetaPlugin {
|
||||
meta_name: String,
|
||||
is_saved: bool,
|
||||
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
}
|
||||
|
||||
impl UidMetaPlugin {
|
||||
@@ -84,6 +89,7 @@ impl UidMetaPlugin {
|
||||
UidMetaPlugin {
|
||||
meta_name: "uid".to_string(),
|
||||
is_saved: false,
|
||||
outputs: std::collections::HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,16 +114,38 @@ impl MetaPlugin for UidMetaPlugin {
|
||||
|
||||
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> {
|
||||
let uid = get_current_uid().to_string();
|
||||
self.save_meta(conn, item_id, uid)?;
|
||||
self.save_meta(conn, item_id, "uid", uid)?;
|
||||
self.is_saved = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||
if let Some(outputs) = options.get("outputs") {
|
||||
if let Some(outputs_map) = outputs.as_mapping() {
|
||||
for (key, value) in outputs_map {
|
||||
if let Some(key_str) = key.as_str() {
|
||||
self.outputs.insert(key_str.to_string(), value.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&self.outputs
|
||||
}
|
||||
|
||||
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||
self.outputs = outputs;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct UserMetaPlugin {
|
||||
meta_name: String,
|
||||
is_saved: bool,
|
||||
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
}
|
||||
|
||||
impl UserMetaPlugin {
|
||||
@@ -125,6 +153,7 @@ impl UserMetaPlugin {
|
||||
UserMetaPlugin {
|
||||
meta_name: "user".to_string(),
|
||||
is_saved: false,
|
||||
outputs: std::collections::HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,16 +181,38 @@ impl MetaPlugin for UserMetaPlugin {
|
||||
Some(username) => username.to_string_lossy().to_string(),
|
||||
None => "unknown".to_string(),
|
||||
};
|
||||
self.save_meta(conn, item_id, user)?;
|
||||
self.save_meta(conn, item_id, "user", user)?;
|
||||
self.is_saved = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||
if let Some(outputs) = options.get("outputs") {
|
||||
if let Some(outputs_map) = outputs.as_mapping() {
|
||||
for (key, value) in outputs_map {
|
||||
if let Some(key_str) = key.as_str() {
|
||||
self.outputs.insert(key_str.to_string(), value.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&self.outputs
|
||||
}
|
||||
|
||||
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||
self.outputs = outputs;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct GidMetaPlugin {
|
||||
meta_name: String,
|
||||
is_saved: bool,
|
||||
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
}
|
||||
|
||||
impl GidMetaPlugin {
|
||||
@@ -169,6 +220,7 @@ impl GidMetaPlugin {
|
||||
GidMetaPlugin {
|
||||
meta_name: "gid".to_string(),
|
||||
is_saved: false,
|
||||
outputs: std::collections::HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,16 +245,38 @@ impl MetaPlugin for GidMetaPlugin {
|
||||
|
||||
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> {
|
||||
let gid = get_current_gid().to_string();
|
||||
self.save_meta(conn, item_id, gid)?;
|
||||
self.save_meta(conn, item_id, "gid", gid)?;
|
||||
self.is_saved = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||
if let Some(outputs) = options.get("outputs") {
|
||||
if let Some(outputs_map) = outputs.as_mapping() {
|
||||
for (key, value) in outputs_map {
|
||||
if let Some(key_str) = key.as_str() {
|
||||
self.outputs.insert(key_str.to_string(), value.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&self.outputs
|
||||
}
|
||||
|
||||
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||
self.outputs = outputs;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct GroupMetaPlugin {
|
||||
meta_name: String,
|
||||
is_saved: bool,
|
||||
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
}
|
||||
|
||||
impl GroupMetaPlugin {
|
||||
@@ -210,6 +284,7 @@ impl GroupMetaPlugin {
|
||||
GroupMetaPlugin {
|
||||
meta_name: "group".to_string(),
|
||||
is_saved: false,
|
||||
outputs: std::collections::HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -237,16 +312,38 @@ impl MetaPlugin for GroupMetaPlugin {
|
||||
Some(groupname) => groupname.to_string_lossy().to_string(),
|
||||
None => "unknown".to_string(),
|
||||
};
|
||||
self.save_meta(conn, item_id, group)?;
|
||||
self.save_meta(conn, item_id, "group", group)?;
|
||||
self.is_saved = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||
if let Some(outputs) = options.get("outputs") {
|
||||
if let Some(outputs_map) = outputs.as_mapping() {
|
||||
for (key, value) in outputs_map {
|
||||
if let Some(key_str) = key.as_str() {
|
||||
self.outputs.insert(key_str.to_string(), value.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&self.outputs
|
||||
}
|
||||
|
||||
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||
self.outputs = outputs;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ShellMetaPlugin {
|
||||
meta_name: String,
|
||||
is_saved: bool,
|
||||
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
}
|
||||
|
||||
impl ShellMetaPlugin {
|
||||
@@ -254,6 +351,7 @@ impl ShellMetaPlugin {
|
||||
ShellMetaPlugin {
|
||||
meta_name: "shell".to_string(),
|
||||
is_saved: false,
|
||||
outputs: std::collections::HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -281,16 +379,38 @@ impl MetaPlugin for ShellMetaPlugin {
|
||||
Ok(shell) => shell,
|
||||
Err(_) => "unknown".to_string(),
|
||||
};
|
||||
self.save_meta(conn, item_id, shell)?;
|
||||
self.save_meta(conn, item_id, "shell", shell)?;
|
||||
self.is_saved = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||
if let Some(outputs) = options.get("outputs") {
|
||||
if let Some(outputs_map) = outputs.as_mapping() {
|
||||
for (key, value) in outputs_map {
|
||||
if let Some(key_str) = key.as_str() {
|
||||
self.outputs.insert(key_str.to_string(), value.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&self.outputs
|
||||
}
|
||||
|
||||
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||
self.outputs = outputs;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ShellPidMetaPlugin {
|
||||
meta_name: String,
|
||||
is_saved: bool,
|
||||
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
}
|
||||
|
||||
impl ShellPidMetaPlugin {
|
||||
@@ -298,6 +418,7 @@ impl ShellPidMetaPlugin {
|
||||
ShellPidMetaPlugin {
|
||||
meta_name: "shell_pid".to_string(),
|
||||
is_saved: false,
|
||||
outputs: std::collections::HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,16 +446,38 @@ impl MetaPlugin for ShellPidMetaPlugin {
|
||||
Ok(ppid) => ppid,
|
||||
Err(_) => process::id().to_string(),
|
||||
};
|
||||
self.save_meta(conn, item_id, pid)?;
|
||||
self.save_meta(conn, item_id, "shell_pid", pid)?;
|
||||
self.is_saved = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||
if let Some(outputs) = options.get("outputs") {
|
||||
if let Some(outputs_map) = outputs.as_mapping() {
|
||||
for (key, value) in outputs_map {
|
||||
if let Some(key_str) = key.as_str() {
|
||||
self.outputs.insert(key_str.to_string(), value.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&self.outputs
|
||||
}
|
||||
|
||||
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||
self.outputs = outputs;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct KeepPidMetaPlugin {
|
||||
meta_name: String,
|
||||
is_saved: bool,
|
||||
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
}
|
||||
|
||||
impl KeepPidMetaPlugin {
|
||||
@@ -342,6 +485,7 @@ impl KeepPidMetaPlugin {
|
||||
KeepPidMetaPlugin {
|
||||
meta_name: "keep_pid".to_string(),
|
||||
is_saved: false,
|
||||
outputs: std::collections::HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -366,16 +510,38 @@ impl MetaPlugin for KeepPidMetaPlugin {
|
||||
|
||||
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> {
|
||||
let pid = process::id().to_string();
|
||||
self.save_meta(conn, item_id, pid)?;
|
||||
self.save_meta(conn, item_id, "keep_pid", pid)?;
|
||||
self.is_saved = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||
if let Some(outputs) = options.get("outputs") {
|
||||
if let Some(outputs_map) = outputs.as_mapping() {
|
||||
for (key, value) in outputs_map {
|
||||
if let Some(key_str) = key.as_str() {
|
||||
self.outputs.insert(key_str.to_string(), value.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&self.outputs
|
||||
}
|
||||
|
||||
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||
self.outputs = outputs;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct HostnameMetaPlugin {
|
||||
meta_name: String,
|
||||
is_saved: bool,
|
||||
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
}
|
||||
|
||||
impl HostnameMetaPlugin {
|
||||
@@ -383,6 +549,7 @@ impl HostnameMetaPlugin {
|
||||
HostnameMetaPlugin {
|
||||
meta_name: "hostname".to_string(),
|
||||
is_saved: false,
|
||||
outputs: std::collections::HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -410,16 +577,38 @@ impl MetaPlugin for HostnameMetaPlugin {
|
||||
Ok(hostname) => hostname,
|
||||
Err(_) => "unknown".to_string(),
|
||||
};
|
||||
self.save_meta(conn, item_id, hostname)?;
|
||||
self.save_meta(conn, item_id, "hostname", hostname)?;
|
||||
self.is_saved = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||
if let Some(outputs) = options.get("outputs") {
|
||||
if let Some(outputs_map) = outputs.as_mapping() {
|
||||
for (key, value) in outputs_map {
|
||||
if let Some(key_str) = key.as_str() {
|
||||
self.outputs.insert(key_str.to_string(), value.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&self.outputs
|
||||
}
|
||||
|
||||
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||
self.outputs = outputs;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct FullHostnameMetaPlugin {
|
||||
meta_name: String,
|
||||
is_saved: bool,
|
||||
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
}
|
||||
|
||||
impl FullHostnameMetaPlugin {
|
||||
@@ -427,6 +616,7 @@ impl FullHostnameMetaPlugin {
|
||||
FullHostnameMetaPlugin {
|
||||
meta_name: "full_hostname".to_string(),
|
||||
is_saved: false,
|
||||
outputs: std::collections::HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -472,8 +662,29 @@ impl MetaPlugin for FullHostnameMetaPlugin {
|
||||
}
|
||||
}
|
||||
};
|
||||
self.save_meta(conn, item_id, hostname)?;
|
||||
self.save_meta(conn, item_id, "full_hostname", hostname)?;
|
||||
self.is_saved = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||
if let Some(outputs) = options.get("outputs") {
|
||||
if let Some(outputs_map) = outputs.as_mapping() {
|
||||
for (key, value) in outputs_map {
|
||||
if let Some(key_str) = key.as_str() {
|
||||
self.outputs.insert(key_str.to_string(), value.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&self.outputs
|
||||
}
|
||||
|
||||
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||
self.outputs = outputs;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user