feat: allow changing default agent tools

This commit is contained in:
thibaud-lclr 2026-04-16 08:34:25 +02:00
parent d5958e2134
commit 4b051807ff
2 changed files with 10 additions and 9 deletions

View file

@ -176,15 +176,15 @@ impl Agent {
let now = chrono::Utc::now().to_rfc3339(); let now = chrono::Utc::now().to_rfc3339();
if existing.is_default { if existing.is_default {
if existing.name != name || existing.role != role || existing.tool != tool { if existing.name != name || existing.role != role {
return Err(rusqlite::Error::InvalidParameterName( return Err(rusqlite::Error::InvalidParameterName(
"Default agents cannot change name, role, or tool".to_string(), "Default agents cannot change name or role".to_string(),
)); ));
} }
conn.execute( conn.execute(
"UPDATE agents SET custom_prompt = ?1, updated_at = ?2 WHERE id = ?3", "UPDATE agents SET tool = ?1, custom_prompt = ?2, updated_at = ?3 WHERE id = ?4",
params![custom_prompt, now, id], params![tool.as_str(), custom_prompt, now, id],
)?; )?;
return Ok(()); return Ok(());
} }
@ -308,7 +308,7 @@ mod tests {
} }
#[test] #[test]
fn test_update_default_agent_allows_prompt_only() { fn test_update_default_agent_allows_tool_and_prompt_only() {
let conn = setup(); let conn = setup();
let analyst = Agent::get_default_by_role(&conn, AgentRole::Analyst).unwrap(); let analyst = Agent::get_default_by_role(&conn, AgentRole::Analyst).unwrap();
@ -323,19 +323,20 @@ mod tests {
.unwrap_err(); .unwrap_err();
assert!(err assert!(err
.to_string() .to_string()
.contains("Default agents cannot change name, role, or tool")); .contains("Default agents cannot change name or role"));
Agent::update( Agent::update(
&conn, &conn,
&analyst.id, &analyst.id,
&analyst.name, &analyst.name,
analyst.role.clone(), analyst.role.clone(),
analyst.tool.clone(), AgentTool::ClaudeCode,
"Prompt override", "Prompt override",
) )
.unwrap(); .unwrap();
let updated = Agent::get_by_id(&conn, &analyst.id).unwrap(); let updated = Agent::get_by_id(&conn, &analyst.id).unwrap();
assert_eq!(updated.tool, AgentTool::ClaudeCode);
assert_eq!(updated.custom_prompt, "Prompt override"); assert_eq!(updated.custom_prompt, "Prompt override");
} }

View file

@ -82,7 +82,8 @@ export default function AgentForm() {
{initializing && <div className="text-sm text-gray-500">Loading agent...</div>} {initializing && <div className="text-sm text-gray-500">Loading agent...</div>}
{isEditing && isDefaultAgent && ( {isEditing && isDefaultAgent && (
<div className="rounded border border-blue-200 bg-blue-50 p-3 text-sm text-blue-700"> <div className="rounded border border-blue-200 bg-blue-50 p-3 text-sm text-blue-700">
This is a default agent. Only its script/prompt can be modified. This is a default agent. Its tool and script/prompt can be modified, but its name and
role are fixed.
</div> </div>
)} )}
@ -116,7 +117,6 @@ export default function AgentForm() {
<select <select
value={tool} value={tool}
onChange={(e) => setTool(e.target.value as AgentTool)} onChange={(e) => setTool(e.target.value as AgentTool)}
disabled={isEditing && isDefaultAgent}
className="w-full rounded border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" className="w-full rounded border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
> >
<option value="codex">Codex</option> <option value="codex">Codex</option>