MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / install_to

Method install_to

atomic-agent/src/hooks/gemini_cli.rs:371–441  ·  view source on GitHub ↗

Install hooks into a settings file (project or global).

(settings_path: &Path, force: bool)

Source from the content-addressed store, hash-verified

369
370 /// Install hooks into a settings file (project or global).
371 fn install_to(settings_path: &Path, force: bool) -> AgentResult<usize> {
372 // Ensure parent directory exists
373 if let Some(parent) = settings_path.parent() {
374 if !parent.exists() {
375 std::fs::create_dir_all(parent).map_err(|e| AgentError::ConfigError {
376 operation: "create directory".to_string(),
377 path: parent.to_path_buf(),
378 reason: e.to_string(),
379 })?;
380 }
381 }
382
383 let (mut raw, mut hooks) = Self::read_settings(settings_path)?;
384
385 if force {
386 remove_atomic_hooks(&mut hooks.session_start);
387 remove_atomic_hooks(&mut hooks.session_end);
388 remove_atomic_hooks(&mut hooks.before_agent);
389 remove_atomic_hooks(&mut hooks.after_agent);
390 remove_atomic_hooks(&mut hooks.before_tool);
391 remove_atomic_hooks(&mut hooks.after_tool);
392 }
393
394 // Define the hooks to install:
395 // (settings event key, matcher, verb, name, description)
396 let hook_defs: Vec<(&str, &str, &str, &str)> = vec![
397 ("session_start", "", "session-start", "atomic-session-start"),
398 ("session_end", "", "session-end", "atomic-session-end"),
399 ("before_agent", "", "before-agent", "atomic-turn-start"),
400 ("after_agent", "", "after-agent", "atomic-turn-end"),
401 ("before_tool", ".*", "before-tool", "atomic-pre-tool"),
402 ("after_tool", ".*", "after-tool", "atomic-post-tool"),
403 ];
404
405 let mut count = 0;
406 for (event_key, matcher, verb, hook_name) in &hook_defs {
407 let command =
408 crate::hooks::guarded_hook_command(&format!("{} {}", ATOMIC_HOOK_PREFIX, verb));
409
410 let matchers = match *event_key {
411 "session_start" => &mut hooks.session_start,
412 "session_end" => &mut hooks.session_end,
413 "before_agent" => &mut hooks.before_agent,
414 "after_agent" => &mut hooks.after_agent,
415 "before_tool" => &mut hooks.before_tool,
416 "after_tool" => &mut hooks.after_tool,
417 _ => continue,
418 };
419
420 if !hook_command_exists(matchers, matcher, &command) {
421 add_hook_to_matcher(matchers, matcher, &command, Some(hook_name));
422 count += 1;
423 }
424 }
425
426 if count == 0 {
427 return Ok(0);
428 }

Callers

nothing calls this directly

Calls 9

read_settingsFunction · 0.85
guarded_hook_commandFunction · 0.85
write_settingsFunction · 0.85
parentMethod · 0.80
remove_atomic_hooksFunction · 0.70
hook_command_existsFunction · 0.70
add_hook_to_matcherFunction · 0.70
existsMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected