Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(decisions): dedup paraphrases at the pass that creates the record (#2310)
Raghav Chamadiyaa1d303bea453
diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/command.py b/packages/cli/src/repowise/cli/commands/init_cmd/command.pyindex 3f79a6bf9..f4200e244 100644--- a/packages/cli/src/repowise/cli/commands/init_cmd/command.py+++ b/packages/cli/src/repowise/cli/commands/init_cmd/command.py@@ -238,20 +238,11 @@ def _run_deterministic_generation_phase(Returns the embedder actually used, which the caller persists so a later``repowise update`` embeds the same way rather than re-deciding."""+ from repowise.cli.providers import template_run_embedderfrom repowise.core.generation import GenerationConfigfrom repowise.core.providers.llm.template import TemplateProvider- # This mode is sold as "no key, no spend", and embedding 2000+ pages- # through a hosted embedder is a real bill. ``resolve_embedder`` infers one- # from any LLM key it finds in the environment, which is the right default- # for a run that is already paying a model and the wrong one here: nobody- # who typed --index-only asked to be charged. So a hosted embedder is used- # only when the user named it, through --embedder or REPOWISE_EMBEDDER.- # Anything else falls back to the mock, which keeps full-text search- # working and leaves semantic search to be built later with- # ``repowise reindex``.- hosted = embedder_name_resolved not in ("mock", "ollama")- embedder = "mock" if hosted and not embedder_was_requested else embedder_name_resolved+ embedder = template_run_embedder(embedder_name_resolved, embedder_was_requested)print_phase_header(console,@@ -1412,6 +1403,25 @@ def init_command(orchestrator_mode = OrchestratorMode.FAST if run_mode == "fast" else OrchestratorMode.STANDARD+ # The store generation would build anyway, hoisted so the analysis+ # checkpoint inside the pipeline can dedup decisions against it;+ # ``run_repo_generation`` reuses this object. Never more than that store,+ # so the exclusions are the runs that build none: a dry run, and index-only+ # fast mode, which also pins no embedder for a table to be read back with.+ # Keyless is dropped rather than handed to a matcher that refuses it.+ index_vector_store = None+ if not dry_run and not (index_only and run_mode == "fast"):+ from repowise.cli.providers import build_embedder, build_vector_store, template_run_embedder+ from repowise.core.providers.embedding import store_has_semantic_vectors++ _store_embedder = (+ template_run_embedder(embedder_name_resolved, embedder_was_requested)+ if index_only or no_provider+ else embedder_name_resolved+ )+ _candidate = build_vector_store(repo_path, build_embedder(_store_embedder, repo_path))+ index_vector_store = _candidate if store_has_semantic_vectors(_candidate) else None+index_columns: list[Any] = [SpinnerColumn(spinner_name=OWL_SPINNER, style=BRAND_STYLE),TextColumn("[progress.description]{task.description}"),@@ -1466,6 +1476,7 @@ def init_command(include_submodules=include_submodules,generate_docs=False,llm_client=llm_client,+ vector_store=index_vector_store,concurrency=concurrency,test_run=test_run,mode=orchestrator_mode,diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/generation.py b/packages/cli/src/repowise/cli/commands/init_cmd/generation.pyindex c8231956c..d06e4b96c 100644--- a/packages/cli/src/repowise/cli/commands/init_cmd/generation.py+++ b/packages/cli/src/repowise/cli/commands/init_cmd/generation.py@@ -289,7 +289,12 @@ def run_repo_generation(announce_file_page_cap(result.parsed_files, gen_config)embedder_impl: Any = build_embedder(embedder_name_resolved, repo_path)- vector_store: Any = build_vector_store(repo_path, embedder_impl)+ # One run, one store: ``init`` builds it before the pipeline and it arrives+ # on ``result``. Only a caller whose embedder matches+ # ``embedder_name_resolved`` may pre-set it.+ vector_store: Any = getattr(result, "vector_store", None)+ if vector_store is None:+ vector_store = build_vector_store(repo_path, embedder_impl)result.vector_store = vector_storedeterministic = bool(getattr(gen_config, "deterministic", False))diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/workspace.py b/packages/cli/src/repowise/cli/commands/init_cmd/workspace.pyindex 0d56b4a3f..381eb050f 100644--- a/packages/cli/src/repowise/cli/commands/init_cmd/workspace.py+++ b/packages/cli/src/repowise/cli/commands/init_cmd/workspace.py@@ -205,14 +205,13 @@ def _run_workspace_deterministic_generation(# so only the per-repo pin is folded in here — the flag already accounts for# the flag and env var, and re-reading them would override a caller that# decided otherwise. ``mock`` is not a pin anyone chose, so it does not count.- from repowise.cli.providers.embedders import pin_names_an_embedder+ from repowise.cli.providers.embedders import pin_names_an_embedder, template_run_embedderfrom repowise.core.generation import GenerationConfigfrom repowise.core.providers.llm.template import TemplateProviderrepo_config = load_config(repo_path)requested = embedder_was_requested or pin_names_an_embedder(repo_config.get("embedder"))- hosted = embedder_name_resolved not in ("mock", "ollama")- embedder = "mock" if hosted and not requested else embedder_name_resolved+ embedder = template_run_embedder(embedder_name_resolved, requested)gen_config = GenerationConfig.from_repo_config(repo_config,diff --git a/packages/cli/src/repowise/cli/providers/__init__.py b/packages/cli/src/repowise/cli/providers/__init__.pyindex ed6c4a07f..483014802 100644--- a/packages/cli/src/repowise/cli/providers/__init__.py+++ b/packages/cli/src/repowise/cli/providers/__init__.py@@ -19,6 +19,7 @@ from repowise.cli.providers.embedders import (pin_names_an_embedder,resolve_embedder,resolve_embedder_for_repo,+ template_run_embedder,)from repowise.cli.providers.vector_store import build_vector_store, existing_vector_dim@@ -34,4 +35,5 @@ __all__ = ["pin_names_an_embedder","resolve_embedder","resolve_embedder_for_repo",+ "template_run_embedder",]diff --git a/packages/cli/src/repowise/cli/providers/embedders.py b/packages/cli/src/repowise/cli/providers/embedders.pyindex a17a2a340..d689d9143 100644--- a/packages/cli/src/repowise/cli/providers/embedders.py+++ b/packages/cli/src/repowise/cli/providers/embedders.py@@ -124,6 +124,21 @@ def embedder_was_requested(embedder_flag: str | None, pinned_embedder: Any = Non)+def template_run_embedder(embedder_name_resolved: str, embedder_was_requested: bool) -> str:+ """The embedder a template-only run actually embeds with.++ That mode is sold as "no key, no spend", and :func:`resolve_embedder` infers+ a hosted embedder from any LLM key in the environment — right for a run+ already paying a model, wrong for one that promised nothing. So a hosted+ embedder is used only when the user named it.++ Shared because ``init`` has to predict this answer before the pipeline, to+ build the run's vector store with the backend generation will actually use.+ """+ hosted = embedder_name_resolved not in ("mock", "ollama")+ return "mock" if hosted and not embedder_was_requested else embedder_name_resolved++def resolve_embedder_for_repo(repo_path: Any) -> str:"""Return the embedder that can read *repo_path*'s vector store.diff --git a/packages/core/src/repowise/core/pipeline/orchestrator.py b/packages/core/src/repowise/core/pipeline/orchestrator.pyindex 9adbe288e..e23f801bc 100644--- a/packages/core/src/repowise/core/pipeline/orchestrator.py+++ b/packages/core/src/repowise/core/pipeline/orchestrator.py@@ -662,6 +662,10 @@ async def run_pipeline(# complete, so an interrupt during the long generation phase below can# resume past analysis instead of recomputing it. Skipped when we already# rehydrated analysis (it's by definition persisted) — best-effort.+ #+ # The store goes with them: this is where a decision record is first+ # written, so it is the only pass that can fold a paraphrase into an+ # existing one. By the end-of-run persist every group matches on title.if resume_controller is not None and not skip_analysis:await resume_controller.checkpoint_analysis(parsed_files=parsed_files,@@ -670,6 +674,7 @@ async def run_pipeline(decision_report=decision_report,doc_drift_report=doc_drift_report,git_metadata_list=git_metadata_list,+ vector_store=vector_store,progress=progress,)diff --git a/tests/integration/test_pipeline_resume.py b/tests/integration/test_pipeline_resume.pyindex 45341c58e..b4694e47a 100644--- a/tests/integration/test_pipeline_resume.py+++ b/tests/integration/test_pipeline_resume.py@@ -140,3 +140,29 @@ async def test_resume_skips_analysis_recompute(sf, sample_repo_path: Path, monkeresume_controller=ResumeController(sf, repo_id, resume=True),)assert result.parsed_files, "resume should still produce a usable index"+++async def test_analysis_checkpoint_receives_the_runs_vector_store(+ sf, sample_repo_path: Path, monkeypatch+) -> None:+ """The store a caller hands ``run_pipeline`` has to reach the checkpoint.++ Dropping it there is invisible: the run still succeeds and still embeds, it+ just stores a duplicate instead of folding it.+ """+ repo_id = await _make_repo(sf, sample_repo_path)+ seen: list[object] = []++ async def _capture(_self: object, **kwargs: object) -> None:+ seen.append(kwargs.get("vector_store"))++ monkeypatch.setattr(ResumeController, "checkpoint_analysis", _capture)++ store = object()+ await run_pipeline(+ sample_repo_path,+ vector_store=store,+ resume_controller=ResumeController(sf, repo_id, resume=False),+ )++ assert seen == [store]diff --git a/tests/unit/cli/test_embedder_resolution.py b/tests/unit/cli/test_embedder_resolution.pyindex f313221b1..06512b0fb 100644--- a/tests/unit/cli/test_embedder_resolution.py+++ b/tests/unit/cli/test_embedder_resolution.py@@ -842,3 +842,19 @@ def test_a_repo_pin_outranks_the_global_config(monkeypatch.setattr(Path, "home", classmethod(lambda _cls: tmp_path))assert resolve_embedder_for_repo(repo) == "mock"+++ ("resolved", "requested", "expected"),+ [+ ("openai", False, "mock"), # inferred from an LLM key: downgraded+ ("openai", True, "openai"), # named by the user: honoured+ ("mock", False, "mock"), # already free, nothing to downgrade+ ("ollama", False, "ollama"),+ ],+)+def test_template_run_embedder_downgrades_only_an_unasked_hosted_backend(+ resolved: str, requested: bool, expected: str+) -> None:+ """``init`` predicts this answer to build the run's store before the pipeline."""+ assert providers.template_run_embedder(resolved, requested) == expected