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

Function record_pre_commit

atomic-cli/src/commands/git/hooks.rs:890–950  ·  view source on GitHub ↗
(root: &Path)

Source from the content-addressed store, hash-verified

888}
889
890pub(crate) fn record_pre_commit(root: &Path) -> CliResult<()> {
891 let root = canonical_root(root)?;
892 let sessions_dir = match atomic_repository::Repository::canonical_dot_dir(&root) {
893 Ok(dot_dir) => dot_dir.join("sessions"),
894 Err(_) => return Ok(()), // not an Atomic repository — nothing to capture
895 };
896
897 // One git observation covers every active session's capture.
898 let token = match atomic_repository::observe_git_metadata(&root) {
899 Ok(observation) => observation.token(),
900 Err(error) => {
901 print_warning(&format!(
902 "pre-commit capture skipped: git observation failed: {error}"
903 ));
904 return Ok(());
905 }
906 };
907
908 let working_copy = match atomic_repository::Repository::open_readonly(&root)
909 .and_then(|repo| repo.require_working_copy_id().map(|id| id.to_string()))
910 {
911 Ok(working_copy) => working_copy,
912 Err(_) => return Ok(()), // no working-copy identity — nothing managed to capture
913 };
914
915 let store = match atomic_agent::turn::session::SessionStore::new(&sessions_dir) {
916 Ok(store) => store,
917 Err(_) => return Ok(()),
918 };
919
920 let active = match store.active_sessions() {
921 Ok(active) => active,
922 Err(_) => return Ok(()),
923 };
924
925 for mut session in active {
926 let turn = session.turn_count + 1;
927 match atomic_agent::turn::capture::write_capture(
928 &sessions_dir,
929 &mut session,
930 turn,
931 working_copy.clone(),
932 &token,
933 ) {
934 Ok(path) => {
935 // Persist the MAC key generated for the capture, or the
936 // turn-end consumer cannot authenticate the evidence.
937 let _ = store.save(&session);
938 log::debug!("wrote commit-time capture {}", path.display());
939 }
940 Err(error) => {
941 print_warning(&format!(
942 "pre-commit capture for session {} turn {} failed (advisory): {error}",
943 session.session_id, turn
944 ));
945 }
946 }
947 }

Calls 9

canonical_rootFunction · 0.85
observe_git_metadataFunction · 0.85
print_warningFunction · 0.85
write_captureFunction · 0.85
tokenMethod · 0.80
active_sessionsMethod · 0.80
cloneMethod · 0.45
saveMethod · 0.45