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
refactor(cli): add shared warn() helper, unify warning stream (#1843)
Nehal kanak kuniyil thottathil01a64e9750f6
diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/command.py b/packages/cli/src/repowise/cli/commands/init_cmd/command.pyindex 711ac187a..0af3d52fc 100644--- a/packages/cli/src/repowise/cli/commands/init_cmd/command.py+++ b/packages/cli/src/repowise/cli/commands/init_cmd/command.py@@ -47,6 +47,7 @@ from repowise.cli.helpers import (run_async,save_config_partial,save_state,+ warn,)from repowise.cli.providers import resolve_embedderfrom repowise.cli.providers.embedders import embedder_was_requested as _embedder_was_requested@@ -413,8 +414,8 @@ def _run_generation_phase(# Warn when a local provider runs with default concurrencylocal_providers = ("ollama", "codex_cli", "claude_cli", "opencode")if provider.provider_name in local_providers and concurrency > 4:- console.print(- f" [{WARN}]Warning:[/] {provider.provider_name} is a local provider "+ warn(+ f" {provider.provider_name} is a local provider "f"running with concurrency={concurrency}. "f"If you see timeout errors, try [bold]--concurrency 1[/bold].")diff --git a/packages/cli/src/repowise/cli/commands/mcp_cmd.py b/packages/cli/src/repowise/cli/commands/mcp_cmd.pyindex 0934f48d1..5972c7286 100644--- a/packages/cli/src/repowise/cli/commands/mcp_cmd.py+++ b/packages/cli/src/repowise/cli/commands/mcp_cmd.py@@ -7,7 +7,7 @@ from pathlib import Pathimport click-from repowise.cli.helpers import console, find_repowise_repo_root, resolve_repo_path+from repowise.cli.helpers import console, find_repowise_repo_root, resolve_repo_path, warnfrom repowise.cli.ui import load_dotenv@@ -177,9 +177,8 @@ def mcp_command(workspace = _workspace_summary(repo_path, no_workspace=no_workspace)repowise_dir = repo_path / ".repowise"if workspace is None and not repowise_dir.exists():- console.print(- f"[yellow]Warning: No .repowise directory found at {repo_path}.[/yellow]\n"- "Run 'repowise init' first to generate documentation."+ warn(+ f"No .repowise directory found at {repo_path}.\nRun 'repowise init' first to generate documentation.")resolved_host = host or os.environ.get("REPOWISE_HOST", "127.0.0.1")diff --git a/packages/cli/src/repowise/cli/commands/reindex_cmd.py b/packages/cli/src/repowise/cli/commands/reindex_cmd.pyindex ff964b132..adb5e2232 100644--- a/packages/cli/src/repowise/cli/commands/reindex_cmd.py+++ b/packages/cli/src/repowise/cli/commands/reindex_cmd.py@@ -11,6 +11,7 @@ from repowise.cli.helpers import (get_db_url_for_repo,resolve_repo_path,run_async,+ warn,)from repowise.cli.ui import BRAND_STYLE, OWL_SPINNER@@ -177,9 +178,7 @@ async def _reindex(repo_path, embedder_name: str, batch_size: int) -> None:failed += 1warned += 1if warned <= 3:- console.print(- f"[yellow] Warning: failed to embed {page_id} during {stage}: {exc}[/yellow]"- )+ warn(f" failed to embed {page_id} during {stage}: {exc}")for page_id, text, meta in retry_items:try:@@ -189,9 +188,7 @@ async def _reindex(repo_path, embedder_name: str, batch_size: int) -> None:failed += 1warned += 1if warned <= 3:- console.print(- f"[yellow] Warning: failed to embed {page_id}: {exc}[/yellow]"- )+ warn(f" failed to embed {page_id}: {exc}")return next((exc for _item, stage, exc in terminal if stage == "embedding"), None)# Pages — one batched embed per slice instead of one embedder@@ -208,10 +205,7 @@ async def _reindex(repo_path, embedder_name: str, batch_size: int) -> None:failed += 1warned += 1if warned <= 3:- console.print(- f"[yellow] Warning: skipped {page.id}: no title to index it by"- "[/yellow]"- )+ warn(f" skipped {page.id}: no title to index it by")continueitem = embed_item(page.id,diff --git a/packages/cli/src/repowise/cli/commands/workspace_cmd.py b/packages/cli/src/repowise/cli/commands/workspace_cmd.pyindex daab3ce52..684a6da12 100644--- a/packages/cli/src/repowise/cli/commands/workspace_cmd.py+++ b/packages/cli/src/repowise/cli/commands/workspace_cmd.py@@ -17,6 +17,7 @@ from repowise.cli.helpers import (resolve_reasoning,resolve_repo_path,run_async,+ warn,)from repowise.cli.output import emit_json, format_option, json_option, resolve_formatfrom repowise.core.docs_mode import docs_mode_state_fields, resolve_docs_mode@@ -624,7 +625,7 @@ def _run_index_for_repo(file_count, symbol_count, _ = run_async(_do_index())console.print(f" [green]✓[/green] {file_count} files, {symbol_count:,} symbols")except Exception as exc:- console.print(f"[yellow]Warning:[/yellow] Indexing failed for '{alias}': {exc}")+ warn(f"Indexing failed for '{alias}': {exc}")return# Run LLM doc generation through the existing single-repo init pathwaydiff --git a/packages/cli/src/repowise/cli/helpers.py b/packages/cli/src/repowise/cli/helpers.pyindex 26f669d29..2786d0736 100644--- a/packages/cli/src/repowise/cli/helpers.py+++ b/packages/cli/src/repowise/cli/helpers.py@@ -57,6 +57,17 @@ T = TypeVar("T")console = Console(width=resolve_console_width(sys.stdout))err_console = Console(stderr=True, width=resolve_console_width(sys.stderr))++def warn(text: str) -> None:+ """Print a warning to stderr with the shared yellow ``Warning:`` prefix.++ Every CLI warning funnels through this helper so warnings render on the+ same ``err_console`` stream (never stdout) and use one ``[yellow]Warning:[/yellow]``+ spelling instead of hand-synced copies scattered across commands.+ """+ err_console.print(f"[yellow]Warning:[/yellow] {text}")++STATE_FILENAME = "state.json"REPOWISE_DIR = ".repowise"@@ -742,8 +753,8 @@ def _persist_provider_key(repo_path: Path, provider: str) -> None:try:save_repo_env_key(repo_path, env_var, value)except (OSError, ValueError) as exc:- err_console.print(- f"[yellow]Warning:[/yellow] could not save {env_var} to "+ warn(+ f"could not save {env_var} to "f".repowise/.env ({exc}). The index is complete, but "f"`repowise mcp` will need {env_var} in its environment.")@@ -1006,7 +1017,7 @@ def resolve_provider(warnings = validate_provider_config(provider_name)if warnings:for warning in warnings:- err_console.print(f"[yellow]Warning:[/yellow] {warning}")+ warn(warning)# For explicit provider requests, we still try to create it# The provider constructor will fail if the API key is actually requireddiff --git a/packages/cli/src/repowise/cli/worktree.py b/packages/cli/src/repowise/cli/worktree.pyindex 29ae9e11c..711851b52 100644--- a/packages/cli/src/repowise/cli/worktree.py+++ b/packages/cli/src/repowise/cli/worktree.py@@ -16,7 +16,7 @@ import timeimport uuidfrom pathlib import Path-from repowise.cli.helpers import console+from repowise.cli.helpers import console, warn_SEED_TEMPDIR_STALENESS_SECS = 3600@@ -218,10 +218,10 @@ def seed_index_from_base(if include_submodules is not None:state_include = st_data.get("include_submodules", False)if include_submodules != state_include:- console.print(- f"[yellow]Warning: --include-submodules={include_submodules} "+ warn(+ f"--include-submodules={include_submodules} "f"conflicts with copied state ({state_include}). Seeded state "- f"will take precedence.[/yellow]"+ f"will take precedence.")(temp_dir / "state.json").write_text(json.dumps(st_data, indent=2), encoding="utf-8")diff --git a/tests/unit/cli/test_helpers.py b/tests/unit/cli/test_helpers.pyindex 41fe1a261..41328b57d 100644--- a/tests/unit/cli/test_helpers.py+++ b/tests/unit/cli/test_helpers.py@@ -21,6 +21,7 @@ from repowise.cli.helpers import (run_async,save_state,validate_provider_config,+ warn,)# ---------------------------------------------------------------------------@@ -28,6 +29,24 @@ from repowise.cli.helpers import (# ---------------------------------------------------------------------------+class TestWarn:+ def test_warn_prints_warning_prefix_to_stderr(self, capsys):+ warn("something went wrong")+ captured = capsys.readouterr()+ assert "Warning:" in captured.err+ assert "something went wrong" in captured.err+ # Nothing leaks to stdout.+ assert captured.out == ""++ def test_warn_prefix_rendered(self, capsys):+ warn("boom")+ captured = capsys.readouterr()+ # Rich renders the [yellow] markup away when stderr isn't a tty, but the+ # human-facing "Warning:" prefix must survive on the stderr stream.+ assert captured.err.startswith("Warning: boom\n")+ assert captured.out == ""++class TestRunAsync:def test_returns_coroutine_result(self):async def _add(a, b):