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

Method run

atomic-cli/src/commands/agent/repair.rs:30–200  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

28
29impl Command for Repair {
30 fn run(&self) -> CliResult<()> {
31 let repo_root = find_repository_root()?;
32
33 // The repair mutates durable session state, so it runs under the
34 // shared workspace boundary — the same ordered lease every other
35 // mutating command holds (CB-12A AC3 "resumes under leases").
36 {
37 let mut repo =
38 atomic_repository::Repository::open_for_workspace_transaction(&repo_root)
39 .map_err(CliError::Repository)?;
40 let _workspace =
41 enter_workspace(&mut repo, atomic_repository::WorkspaceTxnMode::Reconcile)?;
42 }
43
44 let sessions_dir: PathBuf = atomic_repository::Repository::canonical_dot_dir(&repo_root)
45 .map(|dot| dot.join("sessions"))
46 .unwrap_or_else(|_| repo_root.join(".atomic").join("sessions"));
47 let store = SessionStore::new(&sessions_dir).map_err(|error| {
48 CliError::Internal(anyhow::anyhow!(
49 "cannot open the session store at {}: {error}",
50 sessions_dir.display()
51 ))
52 })?;
53 let loaded = store.load(&self.session).map_err(|error| {
54 CliError::Internal(anyhow::anyhow!(
55 "cannot load session '{}': {error}",
56 self.session
57 ))
58 })?;
59 let mut session = loaded.ok_or_else(|| CliError::InvalidArgument {
60 message: format!(
61 "session '{}' not found under {}",
62 self.session,
63 sessions_dir.display()
64 ),
65 })?;
66
67 let mut report = String::new();
68 let prior_status = session.status.label().to_string();
69
70 // ── Evidence verification (report only; never modified). ────────
71 let mut findings: Vec<String> = Vec::new();
72
73 if let (Some(last), Some(key)) = (session.last_attestation, session.mac_key.clone()) {
74 // Content-addressed attestations load through the repository's
75 // change store (read-only reopen: the workspace lease above was
76 // released with its guard).
77 let verified = atomic_repository::Repository::open_readonly(&repo_root)
78 .ok()
79 .and_then(|repo| repo.load_attestation(&last).ok());
80 match verified {
81 Some(attestation) => {
82 if attestation.verify_mac(&key) {
83 findings.push(format!(
84 "attestation {} verifies under the session MAC",
85 last
86 ));
87 } else {

Callers

nothing calls this directly

Calls 15

find_repository_rootFunction · 0.85
print_infoFunction · 0.85
print_successFunction · 0.85
print_warningFunction · 0.85
verify_macMethod · 0.80
enter_workspaceFunction · 0.50
loadMethod · 0.45
labelMethod · 0.45
cloneMethod · 0.45
okMethod · 0.45
load_attestationMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected