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

Method resolve_once_with_origin

src/serve.rs:645–695  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

643 }
644
645 async fn resolve_once_with_origin(&self) -> Result<(TraceDecay, ServeProjectResolutionOrigin)> {
646 let first_error = match ensure_initialized(&self.project_path).await {
647 Ok(cg) => {
648 self.log_choice_if_template(
649 cg.project_root(),
650 "discovered from the working directory",
651 );
652 return Ok((cg, ServeProjectResolutionOrigin::StartupPath));
653 }
654 Err(e) => e,
655 };
656 if self.explicit_path {
657 return Err(first_error);
658 }
659
660 let discovered = crate::config::resolve_path_with_discovery(None);
661 if discovered != self.project_path {
662 if let Ok(cg) = ensure_initialized(&discovered).await {
663 self.log_choice_if_template(
664 cg.project_root(),
665 "discovered from the working directory",
666 );
667 return Ok((cg, ServeProjectResolutionOrigin::FreshCwd));
668 }
669 }
670
671 if let Some(p) = resolve_project_from_roots(&self.initialize_roots).await {
672 self.log_choice_if_template(&p, "matched an MCP initialize root");
673 return ensure_initialized(&p)
674 .await
675 .map(|cg| (cg, ServeProjectResolutionOrigin::InitializeRoots));
676 }
677
678 match resolve_serve_from_global_db(self.global_db_match).await {
679 ServeGlobalDbResolution::Found(p) => {
680 self.log_choice_if_template(&p, "resolved from the global project registry");
681 ensure_initialized(&p)
682 .await
683 .map(|cg| (cg, ServeProjectResolutionOrigin::GlobalDb))
684 }
685 ServeGlobalDbResolution::Ambiguous(paths) => Err(TraceDecayError::Config {
686 message: global_db_ambiguity_message(&paths),
687 }),
688 ServeGlobalDbResolution::None => Err(TraceDecayError::Config {
689 message: format!(
690 "no TraceDecay index found at '{}' and no projects registered in the global database — run 'tracedecay init' in your project first",
691 self.project_path.display()
692 ),
693 }),
694 }
695 }
696
697 fn log_choice_if_template(&self, project: &Path, why: &str) {
698 if self.path_was_template {

Callers 2

resolve_serve_startupFunction · 0.80
resolve_onceMethod · 0.80

Calls 7

ensure_initializedFunction · 0.85
project_rootMethod · 0.45

Tested by

no test coverage detected