generated from nhcarrigan/template
feat: handle EnterWorktree and ExitWorktree tools
Ticket 202 Added EnterWorktree and ExitWorktree to the is_system_tool list so they never trigger permission prompts, matching the behaviour of EnterPlanMode/ExitPlanMode. Added human-readable descriptions to format_tool_description for both tools.
This commit is contained in:
@@ -1666,7 +1666,10 @@ fn process_json_line(
|
|||||||
|
|
||||||
// Helper function to check if a tool is a system tool that should never require permission
|
// Helper function to check if a tool is a system tool that should never require permission
|
||||||
let is_system_tool = |tool_name: &str| -> bool {
|
let is_system_tool = |tool_name: &str| -> bool {
|
||||||
matches!(tool_name, "ExitPlanMode" | "EnterPlanMode")
|
matches!(
|
||||||
|
tool_name,
|
||||||
|
"ExitPlanMode" | "EnterPlanMode" | "EnterWorktree" | "ExitWorktree"
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
for denial in denials {
|
for denial in denials {
|
||||||
@@ -2041,6 +2044,14 @@ fn format_tool_description(name: &str, input: &serde_json::Value) -> String {
|
|||||||
"Running command...".to_string()
|
"Running command...".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"EnterWorktree" => {
|
||||||
|
if let Some(path) = input.get("path").and_then(|v| v.as_str()) {
|
||||||
|
format!("Entering worktree: {}", path)
|
||||||
|
} else {
|
||||||
|
"Entering worktree session...".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"ExitWorktree" => "Exiting worktree session...".to_string(),
|
||||||
"CronCreate" => {
|
"CronCreate" => {
|
||||||
if let Some(prompt) = input.get("prompt").and_then(|v| v.as_str()) {
|
if let Some(prompt) = input.get("prompt").and_then(|v| v.as_str()) {
|
||||||
format!("Scheduling: {}", prompt)
|
format!("Scheduling: {}", prompt)
|
||||||
@@ -2222,6 +2233,27 @@ mod tests {
|
|||||||
assert_eq!(desc, "Using tool: CustomTool");
|
assert_eq!(desc, "Using tool: CustomTool");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_format_tool_description_enter_worktree() {
|
||||||
|
let input = serde_json::json!({"path": "/home/naomi/worktrees/feature-branch"});
|
||||||
|
let desc = format_tool_description("EnterWorktree", &input);
|
||||||
|
assert_eq!(desc, "Entering worktree: /home/naomi/worktrees/feature-branch");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_format_tool_description_enter_worktree_no_path() {
|
||||||
|
let input = serde_json::json!({});
|
||||||
|
let desc = format_tool_description("EnterWorktree", &input);
|
||||||
|
assert_eq!(desc, "Entering worktree session...");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_format_tool_description_exit_worktree() {
|
||||||
|
let input = serde_json::json!({});
|
||||||
|
let desc = format_tool_description("ExitWorktree", &input);
|
||||||
|
assert_eq!(desc, "Exiting worktree session...");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_format_tool_description_cron_create() {
|
fn test_format_tool_description_cron_create() {
|
||||||
let input = serde_json::json!({"prompt": "run tests", "schedule": "*/5 * * * *"});
|
let input = serde_json::json!({"prompt": "run tests", "schedule": "*/5 * * * *"});
|
||||||
|
|||||||
Reference in New Issue
Block a user