hooks : on_install/on_start/on_stop/on_update globaux (settings.hooks) et par projet (issue #34) - echec non bloquant, dry-run respecte, ordre global puis projet

This commit is contained in:
2026-08-17 08:55:35 -04:00
parent 30cc49de3c
commit 18784ba9f7
6 changed files with 144 additions and 0 deletions
+5
View File
@@ -143,6 +143,11 @@ pub fn run(app: &App, agent_name: &str, method_sel: Option<&str>, force: bool) -
.with_agent(agent.name.clone())
.with_args(vec![format!("method={}", method.kind)]),
);
crate::hooks::run_hooks(
app,
"on_install",
&std::env::current_dir().unwrap_or_default(),
);
app.log.success(&format!(
"installed {} (v{version}) in {}",
agent.title(),
+6
View File
@@ -61,6 +61,8 @@ fn start_one(
let bin = PathBuf::from(&exec.program);
let is_managed = app.state.get(&agent.name).ok().flatten().is_some();
let ctx = crate::context::detect(&std::env::current_dir().unwrap_or_default());
let current = std::env::current_dir().unwrap_or_default();
crate::hooks::run_hooks(app, "on_start", cwd.unwrap_or(&current));
if background {
let pid = process::spawn_background(app, &agent.name, &bin, &exec.args, &exec.env, cwd)?;
if app.dry_run() {
@@ -194,6 +196,8 @@ fn stop_one(app: &App, agent: &AgentDef, force: bool, timeout: u64) -> Result<i3
);
let _ = sessions::finish_agent(app, &agent.name, Some(pid), 0, true);
app.state.update_pid(&agent.name, None, None)?;
let current = std::env::current_dir().unwrap_or_default();
crate::hooks::run_hooks(app, "on_stop", &current);
return Ok(0);
}
app.log.info(&format!("stopping '{}' (pid {pid})", agent.name));
@@ -210,6 +214,8 @@ fn stop_one(app: &App, agent: &AgentDef, force: bool, timeout: u64) -> Result<i3
app.emit(&ev);
let _ = sessions::finish_agent(app, &agent.name, Some(pid), if stopped { 0 } else { 1 }, stopped);
app.state.update_pid(&agent.name, None, None)?;
let current = std::env::current_dir().unwrap_or_default();
crate::hooks::run_hooks(app, "on_stop", &current);
if stopped {
app.log.success(&format!("{} stopped", agent.title()));
Ok(0)
+5
View File
@@ -102,6 +102,11 @@ fn update_one(app: &App, runner: &dyn Runner, name: &str) -> Result<i32> {
.with_agent(agent.name.clone())
.with_args(vec![format!("method={}", method.kind)]),
);
crate::hooks::run_hooks(
app,
"on_update",
&std::env::current_dir().unwrap_or_default(),
);
app.log.success(&format!(
"updated {} to v{version}",
agent.title()