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

Function run_watch

atomic-cli/src/commands/git/watch.rs:477–626  ·  view source on GitHub ↗

The daemon entry point: consent, then the hint loop (or a single pass).

(root: &Path, once: bool, poll_ms: u64)

Source from the content-addressed store, hash-verified

475
476/// The daemon entry point: consent, then the hint loop (or a single pass).
477pub(crate) fn run_watch(root: &Path, once: bool, poll_ms: u64) -> CliResult<()> {
478 let config = shim_config(root)?;
479 if !config.git.shim.enabled {
480 return Err(CliError::InvalidRepository {
481 reason: "the shim is not enabled for this repository (set [git.shim] \
482 enabled = true); the watch daemon is an optional accelerator on top of \
483 command-boundary reconciliation"
484 .to_string(),
485 });
486 }
487 if let Some(refusal) = config.git.shim.watch.startup_refusal() {
488 return Err(CliError::InvalidRepository {
489 reason: refusal.to_string(),
490 });
491 }
492 // RFC §11.2 tier precedence (review R4): an explicit `git.watch = "off"`
493 // overrides the shim-watch consent. The daemon is a tier accelerator,
494 // not an independent consent surface — the explicit off wins.
495 if config.git.watch == atomic_config::GitWatch::Off {
496 return Err(CliError::InvalidRepository {
497 reason: "the shim watch daemon is disabled by [git] watch = \"off\"; \
498 command-boundary reconciliation remains the correctness guarantee"
499 .to_string(),
500 });
501 }
502 // RFC §11.2 rule 7: CI and containers default off. An explicit opt-in
503 // still runs — this log line keeps that choice observable instead of
504 // silently succeeding.
505 let environment = atomic_config::Environment::detect();
506 if environment != atomic_config::Environment::Desktop {
507 log::warn!(
508 "shim watch: explicitly opted in while running in a {environment:?} environment; \
509 the RFC default-off rule is satisfied by the disabled default, not by refusal"
510 );
511 }
512 let quiet = Duration::from_millis(config.git.shim.watch.effective_quiet_ms());
513 let poll = Duration::from_millis(poll_ms.max(MIN_POLL_INTERVAL_MS));
514 let sessions = SessionStore::for_repo(root).map_err(|error| CliError::InvalidRepository {
515 reason: format!("cannot open the session store: {error}"),
516 })?;
517
518 // Baseline: the metadata truth as the daemon first observes it. Only
519 // deltas from this (or from the daemon's own prior writes, folded in by
520 // re-baselining after each pass) are external hints.
521 let mut baseline = MetadataHint::observe(root)?;
522 // The last truth an unsafe-state notice was already emitted for; a
523 // deferral notices once per distinct truth and retries silently.
524 let mut notice_gate: Option<MetadataHint> = None;
525 if once {
526 // Single-pass mode always attempts: the shared transaction
527 // classifier decides, a fully-aligned workspace is a no-op, and a
528 // deferred pass reports its notice and exits nonzero so callers
529 // (and the fault corpus) can distinguish "acted" from "deferred".
530 match reactive_pass(root, None, None, quiet, poll, &sessions)? {
531 PassOutcome::Attempted { .. } | PassOutcome::NoChange => return Ok(()),
532 PassOutcome::Deferred => {
533 return Err(CliError::StaleBaseline {
534 report: "shim watch: the external transition was noticed but the \

Callers 2

runMethod · 0.85
runMethod · 0.85

Calls 9

shim_configFunction · 0.85
observeFunction · 0.85
reactive_passFunction · 0.85
print_infoFunction · 0.85
startup_refusalMethod · 0.80
effective_quiet_msMethod · 0.80
differs_fromMethod · 0.80
as_refMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected