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(dead-code): the live run applies dynamic hints and keeps logs off stdout (#3528)
Raghav Chamadiya7c59c1456c1e
diff --git a/packages/cli/src/repowise/cli/commands/dead_code_cmd.py b/packages/cli/src/repowise/cli/commands/dead_code_cmd.pyindex 2d76e576f..ea80829e4 100644--- a/packages/cli/src/repowise/cli/commands/dead_code_cmd.py+++ b/packages/cli/src/repowise/cli/commands/dead_code_cmd.py@@ -212,6 +212,13 @@ def _analyze_live(repo_path: Path, config: dict, notices: Any) -> DeadCodeReportdefault=False,help="Force single-repo mode even when invoked from a workspace.",)+ "--verbose",+ "-v",+ is_flag=True,+ default=False,+ help="Show debug logs from the live analysis (table format only).",+)def dead_code_command(path: str | None,min_confidence: float,@@ -224,6 +231,7 @@ def dead_code_command(no_unused_exports: bool,repo_alias: str | None,no_workspace: bool,+ verbose: bool,) -> None:"""Detect dead and unused code.@@ -235,7 +243,9 @@ def dead_code_command(--repo <alias> to target a different repo. Cross-repo dead-codedetection is not yet supported — run once per repo for now."""- if fmt != "table":+ # The live path parses the whole tree, and its structlog lines go to+ # stdout: they would corrupt JSON/Markdown and bury the table.+ if fmt != "table" or not verbose:silence_logs_for_machine_output_until_close()target = resolve_command_target(diff --git a/packages/cli/src/repowise/cli/commands/health_cmd/command.py b/packages/cli/src/repowise/cli/commands/health_cmd/command.pyindex 1e3ff713d..a42042b83 100644--- a/packages/cli/src/repowise/cli/commands/health_cmd/command.py+++ b/packages/cli/src/repowise/cli/commands/health_cmd/command.py@@ -535,37 +535,27 @@ def _recompute_report(repo_path: Path, *, persist: bool) -> tuple[Any, set[str],def _parse_tree(repo_path: Path) -> tuple[Any, list[Any]]:- """``(graph builder, parsed files)`` over the file set the index analyzed."""- from repowise.core.ingestion import (- ASTParser,- FileTraverser,- GraphBuilder,- wire_tsconfig_resolver,- )+ """``(graph builder, parsed files)`` over the file set the index analyzed.++ The graph is the one ``update`` builds (framework, pytest-root and+ dynamic-hint edges included), since ``--recompute`` persists into the+ rows the indexer writes. ``read_only`` keeps the parse cache, centrality+ cache and structural episodes untouched.+ """+ from repowise.core.pipeline.incremental import build_repo_graph# A repo initialized with --include-submodules persists the flag in# state.json, and a flagless traverser would score a smaller tree.state = load_state(repo_path)- flags = {- "include_submodules": bool(state.get("include_submodules", False)),- "include_nested_repos": bool(state.get("include_nested_repos", False)),- }- # `--recompute` persists into the rows the indexer writes, so it has to- # analyze the same file set. Without the config's exclude patterns it- # scored, and overwrote rows for, files the index had dropped, and on a- # repo excluding a manifest directory it could write a different `module`.- exclude_patterns: list[str] = list(load_config(repo_path).get("exclude_patterns") or [])- traverser = FileTraverser(repo_path, **flags, extra_exclude_patterns=exclude_patterns or None)- parser = ASTParser()- graph_builder = GraphBuilder(repo_path, **flags)- parsed_files = []- for fi in traverser.traverse():- try:- parsed = parser.parse_file(fi, Path(fi.abs_path).read_bytes())- graph_builder.add_file(parsed)- parsed_files.append(parsed)- except Exception:- continue- wire_tsconfig_resolver(graph_builder, repo_path, **flags)- graph_builder.build()+ # Without the config's exclude patterns it scored, and overwrote rows for,+ # files the index had dropped, and on a repo excluding a manifest+ # directory it could write a different `module`.+ parsed_files, _sources, graph_builder, _structure, _count = build_repo_graph(+ repo_path,+ list(load_config(repo_path).get("exclude_patterns") or []),+ collect_sources=True,+ include_submodules=bool(state.get("include_submodules", False)),+ include_nested_repos=bool(state.get("include_nested_repos", False)),+ read_only=True,+ )return graph_builder, parsed_filesdiff --git a/packages/cli/src/repowise/cli/commands/workspace_cmd.py b/packages/cli/src/repowise/cli/commands/workspace_cmd.pyindex 9f7b6f4c5..336ff258a 100644--- a/packages/cli/src/repowise/cli/commands/workspace_cmd.py+++ b/packages/cli/src/repowise/cli/commands/workspace_cmd.py@@ -728,11 +728,6 @@ def _generate_docs_for_added_repo(GenerationConfig,PageGenerator,)- from repowise.core.ingestion import (- ASTParser,- FileTraverser,- GraphBuilder,- )from repowise.core.persistence import (FullTextSearch,create_engine,@@ -744,28 +739,13 @@ def _generate_docs_for_added_repo()# Re-parse files. The pipeline persisted graph data already; for doc- # generation we need parsed files in-memory.- traverser = FileTraverser(repo_path, extra_exclude_patterns=exclude_patterns or None)- file_infos = list(traverser.traverse())- repo_structure = traverser.get_repo_structure()- parser = ASTParser()- graph_builder = GraphBuilder(repo_path)- parsed_files = []- source_map: dict = {}- for fi in file_infos:- try:- source = Path(fi.abs_path).read_bytes()- parsed = parser.parse_file(fi, source)- parsed_files.append(parsed)- source_map[fi.path] = source- graph_builder.add_file(parsed)- except Exception:- continue+ # generation we need parsed files in-memory, and the same graph init+ # builds (framework and dynamic-hint edges included).+ from repowise.core.pipeline.incremental import build_repo_graph- from repowise.core.ingestion import wire_tsconfig_resolver-- wire_tsconfig_resolver(graph_builder, repo_path)- graph_builder.build()+ parsed_files, source_map, graph_builder, repo_structure, _count = build_repo_graph(+ repo_path, exclude_patterns, collect_sources=True+ )from repowise.core.repo_config import load_repo_configdiff --git a/tests/unit/cli/test_dead_code_live_graph.py b/tests/unit/cli/test_dead_code_live_graph.pyindex 3c54033f0..060d01ade 100644--- a/tests/unit/cli/test_dead_code_live_graph.py+++ b/tests/unit/cli/test_dead_code_live_graph.py@@ -3,7 +3,8 @@It used to build a bare graph of its own, without the dynamic hints that``init`` and ``update`` add, so a module named only by a lazy-registry stringread as unreachable live while the stored index called it reachable. It also-must not write into an indexed repo: the command only reads.+must not write into an indexed repo: the command only reads, and its table+output carries no log lines. ``health --recompute`` builds the same graph."""from __future__ import annotations@@ -68,3 +69,23 @@ def test_the_live_analysis_writes_nothing_into_an_indexed_repo(tmp_path: Path) -_live(repo)assert list((repo / ".repowise").iterdir()) == []+++def test_the_live_table_keeps_log_lines_off_stdout(tmp_path: Path) -> None:+ result = CliRunner().invoke(+ dead_code_command, [str(_repo(tmp_path)), "--no-workspace", "--min-confidence", "0.0"]+ )++ assert result.exit_code == 0, result.output+ assert "Dead Code" in result.output+ for level in ("[debug", "[info", "[warning"):+ assert level not in result.output+++def test_health_recompute_builds_the_same_graph(tmp_path: Path) -> None:+ from repowise.cli.commands.health_cmd.command import _parse_tree++ graph_builder, _parsed = _parse_tree(_repo(tmp_path))++ graph = graph_builder.graph()+ assert graph.has_edge("src/app/main.py", "src/app/commands/status_cmd.py")