MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / install_default_agent

Function install_default_agent

src/agents/kiro.rs:443–489  ·  view source on GitHub ↗
(path: &Path, owns_agent: bool)

Source from the content-addressed store, hash-verified

441}
442
443fn install_default_agent(path: &Path, owns_agent: bool) -> Result<()> {
444 if !owns_agent {
445 eprintln!(
446 " Skipping Kiro default-agent update because tracedecay does not own the agent file"
447 );
448 return Ok(());
449 }
450
451 let backup = backup_config_file(path)?;
452 let mut config = match load_json_file_strict(path) {
453 Ok(v) => v,
454 Err(e) => {
455 if let Some(ref b) = backup {
456 eprintln!(" Backup preserved at: {}", b.display());
457 }
458 return Err(e);
459 }
460 };
461
462 ensure_json_object(&config, path)?;
463 ensure_child_object(&mut config, "chat", path)?;
464
465 match config["chat"].get("defaultAgent") {
466 Some(v) if v.as_str() == Some(KIRO_AGENT_NAME) => {
467 eprintln!(" Kiro default agent already set to tracedecay");
468 return Ok(());
469 }
470 Some(v) if v.as_str().is_some_and(is_builtin_default_agent) => {}
471 Some(v) if is_empty_default_agent(v) => {}
472 None => {}
473 Some(v) => {
474 eprintln!(
475 " Kiro default agent is {}, leaving user choice unchanged",
476 format_json_scalar(v)
477 );
478 return Ok(());
479 }
480 }
481
482 config["chat"]["defaultAgent"] = json!(KIRO_AGENT_NAME);
483 safe_write_json_file(path, &config, backup.as_deref())?;
484 eprintln!(
485 "\x1b[32m✔\x1b[0m Set Kiro default agent in {}",
486 path.display()
487 );
488 Ok(())
489}
490
491fn is_builtin_default_agent(agent: &str) -> bool {
492 matches!(agent, "kiro_default" | "default")

Callers 1

installMethod · 0.85

Calls 7

backup_config_fileFunction · 0.85
load_json_file_strictFunction · 0.85
ensure_json_objectFunction · 0.85
ensure_child_objectFunction · 0.85
is_empty_default_agentFunction · 0.85
safe_write_json_fileFunction · 0.85
as_strMethod · 0.45

Tested by

no test coverage detected