run skill hooks from the skill directory

This commit is contained in:
Abhinav Vedmala
2026-05-01 10:34:20 -07:00
parent 0615194a36
commit 0f5b32b78f
10 changed files with 20 additions and 6 deletions
+2 -5
View File
@@ -2051,8 +2051,7 @@ print(json.dumps({{
.context("write skill pre tool use hook script")?;
fs::write(
skill_dir.join("SKILL.md"),
format!(
r#"---
r#"---
name: secure-operations
description: Perform operations with security checks
hooks:
@@ -2060,13 +2059,11 @@ hooks:
- matcher: "^Bash$"
hooks:
- type: command
command: "python3 {script_path}"
command: "python3 ./pre_tool_use_hook.py"
---
# Body
"#,
script_path = script_path.display(),
),
)
.context("write skill")?;
+2 -1
View File
@@ -29,10 +29,11 @@ pub(crate) async fn run_command(
) -> CommandRunResult {
let started_at = chrono::Utc::now().timestamp();
let started = Instant::now();
let execution_cwd = handler.execution_cwd.as_deref().unwrap_or(cwd);
let mut command = build_command(shell, handler);
command
.current_dir(cwd)
.current_dir(execution_cwd)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
+9
View File
@@ -39,6 +39,7 @@ struct HookHandlerSource<'a> {
source: HookSource,
disabled_hook_keys: &'a HashSet<String>,
env: HashMap<String, String>,
execution_cwd: Option<AbsolutePathBuf>,
plugin_id: Option<String>,
}
@@ -95,6 +96,7 @@ pub(crate) fn discover_handlers(
source: hook_source,
disabled_hook_keys: &disabled_hook_keys,
env: HashMap::new(),
execution_cwd: None,
plugin_id: None,
},
hook_events,
@@ -146,6 +148,7 @@ fn append_managed_requirement_handlers(
source: hook_source_for_requirement_source(managed_hooks.source.as_ref()),
disabled_hook_keys,
env: HashMap::new(),
execution_cwd: None,
plugin_id: None,
},
managed_hooks.get().hooks.clone(),
@@ -191,6 +194,7 @@ fn append_plugin_hook_sources(
source: HookSource::Plugin,
disabled_hook_keys,
env,
execution_cwd: None,
plugin_id: Some(plugin_id),
},
hooks,
@@ -229,6 +233,7 @@ pub(crate) fn append_skill_hook_sources(
source: HookSource::Skill,
disabled_hook_keys: &disabled_hook_keys,
env: HashMap::new(),
execution_cwd: source_path.parent(),
plugin_id: None,
},
hooks,
@@ -475,6 +480,7 @@ fn append_matcher_groups(
source: source.source,
display_order: *display_order,
env: source.env.clone(),
execution_cwd: source.execution_cwd.clone(),
});
}
*display_order += 1;
@@ -568,6 +574,7 @@ mod tests {
source: hook_source(),
disabled_hook_keys,
env: std::collections::HashMap::new(),
execution_cwd: None,
plugin_id: None,
}
}
@@ -615,6 +622,7 @@ mod tests {
source: hook_source(),
display_order: 0,
env: std::collections::HashMap::new(),
execution_cwd: None,
}]
);
}
@@ -650,6 +658,7 @@ mod tests {
source: hook_source(),
display_order: 0,
env: std::collections::HashMap::new(),
execution_cwd: None,
}]
);
}
+1
View File
@@ -164,6 +164,7 @@ mod tests {
source: HookSource::User,
display_order,
env: std::collections::HashMap::new(),
execution_cwd: None,
}
}
+1
View File
@@ -45,6 +45,7 @@ pub(crate) struct ConfiguredHandler {
pub source: HookSource,
pub display_order: i64,
pub env: HashMap<String, String>,
pub execution_cwd: Option<AbsolutePathBuf>,
}
impl ConfiguredHandler {
@@ -551,6 +551,7 @@ mod tests {
source: codex_protocol::protocol::HookSource::User,
display_order: 0,
env: std::collections::HashMap::new(),
execution_cwd: None,
}
}
@@ -542,6 +542,7 @@ mod tests {
source: codex_protocol::protocol::HookSource::User,
display_order: 0,
env: std::collections::HashMap::new(),
execution_cwd: None,
}
}
@@ -364,6 +364,7 @@ mod tests {
source: codex_protocol::protocol::HookSource::User,
display_order: 0,
env: std::collections::HashMap::new(),
execution_cwd: None,
}
}
+1
View File
@@ -531,6 +531,7 @@ mod tests {
source: codex_protocol::protocol::HookSource::User,
display_order: 0,
env: std::collections::HashMap::new(),
execution_cwd: None,
}
}
@@ -422,6 +422,7 @@ mod tests {
source: codex_protocol::protocol::HookSource::User,
display_order: 0,
env: std::collections::HashMap::new(),
execution_cwd: None,
}
}