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(init): a workspace init stamps each repo so the first update has nothing to redo (#4293)
Raghav Chamadiya91fe3acca4b6
diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/_finish.py b/packages/cli/src/repowise/cli/commands/init_cmd/_finish.pyindex 755f40a91..8509f96f3 100644--- a/packages/cli/src/repowise/cli/commands/init_cmd/_finish.py+++ b/packages/cli/src/repowise/cli/commands/init_cmd/_finish.py@@ -9,10 +9,8 @@ from typing import Anyfrom repowise.cli.commands._index_outcome import record_index_outcome, refresh_read_snapshotsfrom repowise.cli.editor_setup import register_editor_clients, write_editor_project_filesfrom repowise.cli.helpers import (- config_fingerprint,console,get_head_commit,- head_commit_ts,load_config,load_state,run_async,@@ -22,12 +20,9 @@ from repowise.cli.helpers import (from repowise.cli.state_persistence import build_kg_state, save_knowledge_graph_jsonfrom repowise.cli.ui import OK, mascot, print_stage, progress_stepsfrom repowise.cli.ui.glyphs import glyph-from repowise.core.analysis.health import HEALTH_ANALYZER_VERSION-from repowise.core.analysis.security_scan import SECURITY_SCANNER_VERSIONfrom repowise.core.decision_lanes import record_decision_lanesfrom repowise.core.docs_mode import docs_mode_state_fieldsfrom repowise.core.generation.styles import DEFAULT_STYLE-from repowise.core.repo_config import config_dependency_fingerprintsfrom ._ingest import decision_llm_clientfrom ._interactive import offer_distill_rewrite_hook, offer_hook_install@@ -38,6 +33,7 @@ from .persistence import (keep_prior_documentation,persist_result,save_full_state_and_config,+ stamp_fresh_index,)from .reporting import show_completion@@ -283,21 +279,8 @@ def _save_index_only_state(run: InitRun, base_state: dict[str, Any]) -> None:embedder=embedder,embedding_model=resolve_embedding_model(embedder) if embedder else None,)- # Fingerprint after config writes so the first update doesn't false-positive.- base_state["config_fingerprint"] = config_fingerprint(repo_path)- base_state["config_dependency_fingerprints"] = config_dependency_fingerprints(repo_path)- # Without these stamps the version triggers never fire for keyless installs.- base_state["health_analyzer_version"] = HEALTH_ANALYZER_VERSION- base_state["security_scanner_version"] = SECURITY_SCANNER_VERSION- # Unstamped, the first update would re-render the whole wiki.- from repowise.cli.commands.update_cmd.command import _current_renderer_fingerprint-- base_state["renderer_fingerprint"] = _current_renderer_fingerprint(repo_path)- # Start the re-score cadence only when a health report was persisted;- # otherwise the first update's re-score must still run.- _head_ts = head_commit_ts(repo_path) if getattr(run.result, "health_report", None) else None- if _head_ts is not None:- base_state["last_full_rescore_at"] = _head_ts+ # After the config writes, so the first update doesn't false-positive.+ stamp_fresh_index(base_state, repo_path, run.result)save_state(repo_path, base_state, full_index=True)diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/persistence.py b/packages/cli/src/repowise/cli/commands/init_cmd/persistence.pyindex 5f851f0b6..d539d8534 100644--- a/packages/cli/src/repowise/cli/commands/init_cmd/persistence.py+++ b/packages/cli/src/repowise/cli/commands/init_cmd/persistence.py@@ -582,6 +582,16 @@ def save_full_state_and_config()# Re-save state with the fingerprint now that config.yaml is written.+ stamp_fresh_index(state, repo_path, result)+ save_state(repo_path, state, full_index=True)+++def stamp_fresh_index(state: dict[str, Any], repo_path: Path, result: Any) -> None:+ """Stamp what a just-finished init built, so the first update finds nothing to redo.++ Every init path calls this after its config.yaml writes, since the config+ fingerprint reads them.+ """state["config_fingerprint"] = config_fingerprint(repo_path)state["config_dependency_fingerprints"] = config_dependency_fingerprints(repo_path)# This index's health rows were written by the current analyzer, so start@@ -611,4 +621,3 @@ def save_full_state_and_config(_head_ts = head_commit_ts(repo_path) if getattr(result, "health_report", None) else Noneif _head_ts is not None:state["last_full_rescore_at"] = _head_ts- save_state(repo_path, state, full_index=True)diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/workspace.py b/packages/cli/src/repowise/cli/commands/init_cmd/workspace.pyindex 2b14b8c4b..e3aab31bc 100644--- a/packages/cli/src/repowise/cli/commands/init_cmd/workspace.py+++ b/packages/cli/src/repowise/cli/commands/init_cmd/workspace.py@@ -86,6 +86,7 @@ from .persistence import (apply_git_history_coverage_state,keep_prior_documentation,persist_result,+ stamp_fresh_index,)from .reporting import show_workspace_completion@@ -403,6 +404,10 @@ def _ingest_and_generate_repo(repo: Any, idx: int, total: int, ctx: _WorkspaceCtno_editor_setup=not ctx.editor_setup,)_save_repo_config(repo.path, ctx, docs)+ # After the config writes, which the config fingerprint reads. Unstamped,+ # the first update re-renders and re-scores every repo init just built.+ stamp_fresh_index(state, repo.path, result)+ save_state(repo.path, state, full_index=True)from repowise.cli.providers import embed_failure_messagediff --git a/tests/unit/cli/test_health_rescore_gate.py b/tests/unit/cli/test_health_rescore_gate.pyindex 7f77ea9bb..0e2bece7b 100644--- a/tests/unit/cli/test_health_rescore_gate.py+++ b/tests/unit/cli/test_health_rescore_gate.py@@ -148,10 +148,8 @@ class TestInitStampsTheCadence:@pytest.mark.parametrize("module_name",- [- "repowise.cli.commands.init_cmd._finish",- "repowise.cli.commands.init_cmd.persistence",- ],+ # Every init path stamps through persistence.stamp_fresh_index.+ ["repowise.cli.commands.init_cmd.persistence"],)def test_init_never_stamps_the_cadence_for_a_run_that_scored_nothing(module_name):"""The stamp says "these rows are current", so it must not outrun the rows.diff --git a/tests/unit/cli/test_workspace_init_provider.py b/tests/unit/cli/test_workspace_init_provider.pyindex 1269ee64e..84c08f6cc 100644--- a/tests/unit/cli/test_workspace_init_provider.py+++ b/tests/unit/cli/test_workspace_init_provider.py@@ -136,6 +136,22 @@ def test_workspace_member_persists_the_shared_git_coverage(}+def test_workspace_member_state_carries_the_fresh_index_stamps(+ tmp_path: Path, captured: dict[str, Any]+) -> None:+ """Unstamped, the first update re-renders and re-scores the repo init just built."""+ from repowise.core.analysis.health import HEALTH_ANALYZER_VERSION+ from repowise.core.analysis.security_scan import SECURITY_SCANNER_VERSION++ _run(tmp_path, SimpleNamespace(provider_name="omp", model_name="omp/default"))++ state = captured["saved_state"]+ assert state["config_fingerprint"]+ assert state["renderer_fingerprint"]+ assert state["health_analyzer_version"] == HEALTH_ANALYZER_VERSION+ assert state["security_scanner_version"] == SECURITY_SCANNER_VERSION++def test_unavailable_git_history_clears_stale_coverage() -> None:from repowise.cli.commands.init_cmd.persistence import (apply_git_history_coverage_state,