feat: add is_finalized to MetaPluginResponse and remove direct db interaction from meta plugins

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:11:27 -03:00
parent ec428f5fc4
commit 9d60461354
3 changed files with 58 additions and 32 deletions

View File

@@ -95,37 +95,42 @@ impl MetaPlugin for MetaPluginProgram {
false
}
fn initialize(&mut self, item_id: i64) -> Result<PluginResponse> {
fn initialize(&mut self) -> MetaPluginResponse {
debug!("META: Initializing program plugin: {:?}", self);
// Store item ID for later use
self.item_id = Some(item_id);
let program = self.program.clone();
let args = self.args.clone();
debug!("META: Executing command: {:?} {:?}", program, args);
let mut process = Command::new(program.clone())
let mut process = match Command::new(program.clone())
.args(args.clone())
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.context(anyhow!(
"Problem spawning child process: {:?} {:?}",
program,
args
))?;
.spawn()
{
Ok(process) => process,
Err(e) => {
debug!("META: Failed to spawn process: {}", e);
return MetaPluginResponse {
metadata: Vec::new(),
is_finalized: true,
};
}
};
let stdin = process.stdin.take().unwrap();
self.writer = Some(Box::new(stdin));
self.process = Some(process);
Ok(MetaPluginResponse::default())
MetaPluginResponse {
metadata: Vec::new(),
is_finalized: false,
}
}
fn finalize(&mut self) -> Result<MetaPluginResponse> {
fn finalize(&mut self) -> MetaPluginResponse {
debug!("META: Finalizing program plugin");
let mut metadata = Vec::new();
@@ -134,7 +139,16 @@ impl MetaPlugin for MetaPluginProgram {
drop(self.writer.take());
// Wait for the process to complete
let output = process.wait_with_output()?;
let output = match process.wait_with_output() {
Ok(output) => output,
Err(e) => {
debug!("META: Failed to get process output: {}", e);
return MetaPluginResponse {
metadata: Vec::new(),
is_finalized: true,
};
}
};
if output.status.success() {
// Process the output
@@ -149,12 +163,11 @@ impl MetaPlugin for MetaPluginProgram {
debug!("META: Program output: {}", result);
self.result = Some(result);
// Create metadata to be stored
if let Some(item_id) = self.item_id {
if let Some(meta) = self.create_meta(item_id, &self.meta_name, result) {
metadata.push(meta);
}
}
// Create metadata to be returned
metadata.push(MetaData {
name: self.meta_name.clone(),
value: result,
});
}
} else {
debug!("META: Program failed with status: {:?}", output.status);
@@ -165,19 +178,22 @@ impl MetaPlugin for MetaPluginProgram {
}
}
Ok(MetaPluginResponse {
metadata: if metadata.is_empty() { None } else { Some(metadata) },
MetaPluginResponse {
metadata,
is_finalized: true,
})
}
}
fn update(&mut self, data: &[u8]) -> Result<MetaPluginResponse> {
fn update(&mut self, data: &[u8]) -> MetaPluginResponse {
if let Some(ref mut writer) = self.writer {
if let Err(e) = writer.write_all(data) {
debug!("META: Failed to write to process stdin: {}", e);
}
}
Ok(PluginResponse::default())
MetaPluginResponse {
metadata: Vec::new(),
is_finalized: false,
}
}
fn meta_name(&self) -> String {