Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

feat(offline): REPOWISE_OFFLINE, DO_NOT_TRACK and the telemetry opt-out skip the PyPI check and agent-CLI probes (#4440)

Raghav Chamadiyaf826041e5688
diff --git a/docs/reference/CONFIG.md b/docs/reference/CONFIG.md
index bc246c08c..e7e8a3748 100644
--- a/docs/reference/CONFIG.md
+++ b/docs/reference/CONFIG.md
@@ -1045,6 +1045,7 @@ Anonymous usage telemetry is **on by default** (opt-out).
|----------|-------------|
| `DO_NOT_TRACK` | Any truthy value disables it (cross-tool convention) |
| `REPOWISE_TELEMETRY_DISABLED` | Disables it, Repowise-specific |
+| `REPOWISE_OFFLINE` | Disables it, plus the PyPI release check and the `init` probe of signed-in agent CLIs (`DO_NOT_TRACK` and `REPOWISE_TELEMETRY_DISABLED` turn those off too) |
| `REPOWISE_TELEMETRY_DEBUG` | Prints the payload to stderr instead of sending |
### Misc
diff --git a/docs/reference/TELEMETRY.md b/docs/reference/TELEMETRY.md
index c0a369228..f7a0bd011 100644
--- a/docs/reference/TELEMETRY.md
+++ b/docs/reference/TELEMETRY.md
@@ -157,6 +157,7 @@ Any one of these disables all telemetry:
repowise telemetry disable # persisted to ~/.repowise/platform.json
export REPOWISE_TELEMETRY_DISABLED=1
export DO_NOT_TRACK=1 # the cross-tool standard (https://consoledonottrack.com)
+export REPOWISE_OFFLINE=1 # also skips the PyPI release check and agent-CLI login probes
```
Check the current state anytime:
diff --git a/packages/cli/src/repowise/cli/commands/health_cmd/command.py b/packages/cli/src/repowise/cli/commands/health_cmd/command.py
index 785a8c4dc..8a9f685e6 100644
--- a/packages/cli/src/repowise/cli/commands/health_cmd/command.py
+++ b/packages/cli/src/repowise/cli/commands/health_cmd/command.py
@@ -621,9 +621,14 @@ def _render_headline(kpis: dict[str, Any], code_shape: bool, unanalysed: int) ->
analysed_note,
band_for,
headline_band,
+ headline_scope,
)
share = kpis.get("analysed_share")
+ analysed = kpis.get("file_count") or 0
+ unanalysed_count = kpis.get("unanalysed_file_count") or 0
+ # A minority-analysed score never prints bare: its coverage rides beside it.
+ scope = headline_scope(analysed, unanalysed_count)
def banded(label: str, score: Any, band: str | None) -> str:
# Every score printed carries its band, so a Fair figure never sits
@@ -636,7 +641,7 @@ def _render_headline(kpis: dict[str, Any], code_shape: bool, unanalysed: int) ->
avg = kpis.get("average_health")
avg_band = headline_band(avg, share)
- parts = [banded("Code health", avg, avg_band)]
+ parts = [banded("Code health", avg, avg_band) + (f" {scope}" if scope else "")]
# Production code beside the all-files figure, while tests are in it.
production = kpis.get("production_average")
has_tests = (kpis.get("production_file_count") or 0) < (kpis.get("file_count") or 0)
@@ -661,8 +666,8 @@ def _render_headline(kpis: dict[str, Any], code_shape: bool, unanalysed: int) ->
"their language yet.[/dim]"
)
# The share behind the headline, from the same counts as its band.
- note = analysed_note(kpis.get("file_count") or 0, kpis.get("unanalysed_file_count") or 0)
- if note:
+ note = analysed_note(analysed, unanalysed_count)
+ if note and not scope:
console.print(f"[dim]Code health {note}.[/dim]")
diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/_provider.py b/packages/cli/src/repowise/cli/commands/init_cmd/_provider.py
index f8f849fb7..4705be644 100644
--- a/packages/cli/src/repowise/cli/commands/init_cmd/_provider.py
+++ b/packages/cli/src/repowise/cli/commands/init_cmd/_provider.py
@@ -99,6 +99,10 @@ def note_subscription_cli(run: InitRun) -> None:
def _wants_subscription_note(run: InitRun) -> bool:
"""A scripted run nobody picked a provider for, and no model writes."""
+ from repowise.core.platform.telemetry import network_disabled
+
+ if network_disabled(): # the probe spawns third-party CLIs that phone home
+ return False
chosen = run.is_interactive or run.opts.provider_name or run.config.get("provider")
return not chosen and bool(run.opts.index_only or run.no_provider)
diff --git a/packages/cli/src/repowise/cli/platform/settings.py b/packages/cli/src/repowise/cli/platform/settings.py
index 070545bb0..7cae768cf 100644
--- a/packages/cli/src/repowise/cli/platform/settings.py
+++ b/packages/cli/src/repowise/cli/platform/settings.py
@@ -8,7 +8,7 @@ Precedence (highest first):
1. ``DO_NOT_TRACK`` — the cross-tool `console do-not-track` standard. Any
truthy value is a hard off and also suppresses the first-run notice.
-2. ``REPOWISE_TELEMETRY_DISABLED`` — tool-specific hard off.
+2. ``REPOWISE_TELEMETRY_DISABLED`` / ``REPOWISE_OFFLINE`` — tool-specific hard off.
3. Stored consent (``telemetry_enabled`` in ``platform.json``) when the user
has explicitly run ``repowise telemetry disable``/``enable``.
4. Default: enabled.
@@ -48,7 +48,7 @@ def is_enabled() -> bool:
"""Return whether telemetry may currently be sent."""
if do_not_track():
return False
- if _env_truthy("REPOWISE_TELEMETRY_DISABLED"):
+ if _env_truthy("REPOWISE_TELEMETRY_DISABLED") or _env_truthy("REPOWISE_OFFLINE"):
return False
# Opt-out default: enabled unless the user explicitly stored a disable.
stored = store.load().get(_ENABLED_KEY)
@@ -77,6 +77,8 @@ def disabled_reason() -> str | None:
return "DO_NOT_TRACK is set"
if _env_truthy("REPOWISE_TELEMETRY_DISABLED"):
return "REPOWISE_TELEMETRY_DISABLED is set"
+ if _env_truthy("REPOWISE_OFFLINE"):
+ return "REPOWISE_OFFLINE is set"
if store.load().get(_ENABLED_KEY) is False:
return "disabled via 'repowise telemetry disable'"
return None
diff --git a/packages/core/src/repowise/core/analysis/health/grading.py b/packages/core/src/repowise/core/analysis/health/grading.py
index bf2152089..85454d75d 100644
--- a/packages/core/src/repowise/core/analysis/health/grading.py
+++ b/packages/core/src/repowise/core/analysis/health/grading.py
@@ -136,6 +136,14 @@ def analysed_note(analysed: int, unanalysed: int) -> str | None:
return f"analysed {analysed} of {analysed + unanalysed} code files"
+def headline_scope(analysed: int, unanalysed: int) -> str | None:
+ """``"across N of M code files"`` when a minority was analysed, else ``None``."""
+ share = analysed_share(analysed, unanalysed)
+ if share is None or share >= HEADLINE_MIN_ANALYSED_SHARE:
+ return None
+ return f"across {analysed} of {analysed + unanalysed} code files"
+
+
def format_score(score: float) -> str:
"""A 1-10 score at one decimal, rounded down, for display beside its band.
diff --git a/packages/core/src/repowise/core/platform/telemetry.py b/packages/core/src/repowise/core/platform/telemetry.py
index 962890811..ebb7fd70f 100644
--- a/packages/core/src/repowise/core/platform/telemetry.py
+++ b/packages/core/src/repowise/core/platform/telemetry.py
@@ -86,6 +86,13 @@ def _env_truthy(name: str) -> bool:
return os.environ.get(name, "").strip().lower() in _TRUTHY
+def network_disabled() -> bool:
+ """True when ``REPOWISE_OFFLINE``, ``DO_NOT_TRACK`` or ``REPOWISE_TELEMETRY_DISABLED`` is set."""
+ return any(
+ _env_truthy(n) for n in ("REPOWISE_OFFLINE", "DO_NOT_TRACK", "REPOWISE_TELEMETRY_DISABLED")
+ )
+
+
def debug_mode() -> bool:
"""``REPOWISE_TELEMETRY_DEBUG`` prints the payload to stderr instead of sending."""
return _env_truthy("REPOWISE_TELEMETRY_DEBUG")
@@ -169,7 +176,7 @@ def record_event(event: str, properties: dict[str, Any] | None = None) -> None:
"""
try:
# Cheap synchronous gate: env hard-offs need neither disk nor a thread.
- if _env_truthy("DO_NOT_TRACK") or _env_truthy("REPOWISE_TELEMETRY_DISABLED"):
+ if network_disabled():
return
props = dict(properties or {})
diff --git a/packages/core/src/repowise/core/upgrade/release.py b/packages/core/src/repowise/core/upgrade/release.py
index a2309e29d..c23cbb8c5 100644
--- a/packages/core/src/repowise/core/upgrade/release.py
+++ b/packages/core/src/repowise/core/upgrade/release.py
@@ -19,6 +19,8 @@ from dataclasses import dataclass
from pathlib import Path
from typing import Any
+from repowise.core.platform.telemetry import network_disabled
+
from .changelog import ChangelogEntry, parse_changelog
PYPI_URL = "https://pypi.org/pypi/repowise/json"
@@ -93,6 +95,8 @@ def fetch_latest_version(timeout: float = 2.0) -> tuple[str | None, str | None]:
Returns ``(latest, error)``. ``latest`` is ``None`` on any failure (network,
JSON, or a version we cannot compare), with ``error`` describing why.
"""
+ if network_disabled():
+ return None, "network checks are off"
try:
import httpx
@@ -180,6 +184,8 @@ def fetch_release_highlights(version: str, timeout: float = 2.0) -> list[str] |
``None`` on any network or parse failure, so the caller keeps its plain
wording. Nothing is sent but the GET.
"""
+ if network_disabled():
+ return None
import httpx
try:
@@ -217,6 +223,8 @@ def latest_highlights_cached(
return titles
except (OSError, ValueError, KeyError, TypeError, AttributeError):
pass # no cache yet, or a malformed one: fetch
+ if network_disabled():
+ return [] # not cached, so the titles show once the switch is off
titles = fetch_release_highlights(version, timeout=timeout)
with contextlib.suppress(OSError): # a read-only home only costs a refetch
_HIGHLIGHTS_CACHE_PATH.parent.mkdir(parents=True, exist_ok=True)
diff --git a/packages/server/src/repowise/server/mcp_server/tool_health/summary.py b/packages/server/src/repowise/server/mcp_server/tool_health/summary.py
index ef5414a96..710bfe834 100644
--- a/packages/server/src/repowise/server/mcp_server/tool_health/summary.py
+++ b/packages/server/src/repowise/server/mcp_server/tool_health/summary.py
@@ -5,7 +5,12 @@ from __future__ import annotations
from typing import Any
from repowise.core.analysis.health.complexity.languages import NO_DIALECT_STATUS
-from repowise.core.analysis.health.grading import TARGET_SCORE, analysed_share, headline_band
+from repowise.core.analysis.health.grading import (
+ TARGET_SCORE,
+ analysed_share,
+ headline_band,
+ headline_scope,
+)
from repowise.core.analysis.health.models import primary_finding, split_by_origin
from repowise.core.analysis.health.perf.coverage import PerfCoverage
from repowise.core.analysis.health.ranking import worst_kpis
@@ -208,6 +213,12 @@ def _compute_kpis(
"band": headline_band(round(avg, 2), share),
# Only said when some files were left out, as ``unanalysed_file_count`` is.
**({"analysed_share": share} if unanalysed else {}),
+ # Beside a score most code files did not feed.
+ **(
+ {"average_health_scope": scope}
+ if (scope := headline_scope(len(metrics), unanalysed))
+ else {}
+ ),
# The heads of ``worst_files`` and ``test_worst_files``, as REST names them.
**worst_kpis(metrics, deductions),
# ``None`` until the pillar is measured.
diff --git a/tests/unit/cli/test_health_cmd_controls.py b/tests/unit/cli/test_health_cmd_controls.py
index 68a71fcf7..22c0e99ad 100644
--- a/tests/unit/cli/test_health_cmd_controls.py
+++ b/tests/unit/cli/test_health_cmd_controls.py
@@ -179,10 +179,10 @@ def test_a_mostly_unanalysed_repo_gets_no_band_in_any_scope() -> None:
"""A narrowed recompute keeps the unanalysed files in the share."""
for args in ((), ("--scope", "production")):
out = _mostly_unanalysed_output(*args)
- assert "Code health: 10.0/10 ·" in out, args
+ # Never a bare score: coverage sits on the headline itself.
+ assert "Code health: 10.0/10 across 4 of 435 code files ·" in out, args
# No band anywhere on the line, the worst file's included.
assert "Excellent" not in out, args
- assert "analysed 4 of 435 code files" in out, args
def test_the_headline_names_production_code_while_tests_are_in_it() -> None:
diff --git a/tests/unit/cli/test_subscription_providers.py b/tests/unit/cli/test_subscription_providers.py
index f4f89203c..3837a0622 100644
--- a/tests/unit/cli/test_subscription_providers.py
+++ b/tests/unit/cli/test_subscription_providers.py
@@ -179,6 +179,17 @@ def test_note_is_quiet_when_a_model_writes_the_docs(monkeypatch: Any) -> None:
assert _note(monkeypatch, run) == ""
[email protected]("var", ["REPOWISE_OFFLINE", "DO_NOT_TRACK", "REPOWISE_TELEMETRY_DISABLED"])
+def test_note_spawns_no_agent_cli_when_network_is_off(monkeypatch: Any, var: str) -> None:
+ def _boom(*args: Any, **kwargs: Any) -> None:
+ raise AssertionError("agent CLI probed with an off switch set")
+
+ monkeypatch.setattr(subscription, "logged_in_agent_providers", _boom)
+ monkeypatch.setattr(subscription.subprocess, "run", _boom)
+ monkeypatch.setenv(var, "1")
+ assert _note(monkeypatch, _run()) == ""
+
+
def test_note_is_quiet_without_a_logged_in_cli(monkeypatch: Any) -> None:
_logged_in(monkeypatch)
assert _note(monkeypatch, _run()) == ""
diff --git a/tests/unit/cli/test_telemetry.py b/tests/unit/cli/test_telemetry.py
index 36aa9ba56..682d646c7 100644
--- a/tests/unit/cli/test_telemetry.py
+++ b/tests/unit/cli/test_telemetry.py
@@ -30,7 +30,12 @@ def isolated_store(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
monkeypatch.setattr(store, "_path", lambda: tmp_path / "platform.json")
monkeypatch.setattr(spool, "_path", lambda: tmp_path / spool.SPOOL_FILENAME)
# Clear any inherited telemetry env so each test controls precedence.
- for var in ("DO_NOT_TRACK", "REPOWISE_TELEMETRY_DISABLED", "REPOWISE_TELEMETRY_DEBUG"):
+ for var in (
+ "DO_NOT_TRACK",
+ "REPOWISE_TELEMETRY_DISABLED",
+ "REPOWISE_TELEMETRY_DEBUG",
+ "REPOWISE_OFFLINE",
+ ):
monkeypatch.delenv(var, raising=False)
monkeypatch.setattr(emitter, "_flush_thread", None, raising=False)
@@ -49,6 +54,11 @@ class TestConsentPrecedence:
monkeypatch.setenv("REPOWISE_TELEMETRY_DISABLED", "true")
assert settings.is_enabled() is False
+ def test_offline_env_disables(self, monkeypatch: pytest.MonkeyPatch):
+ monkeypatch.setenv("REPOWISE_OFFLINE", "1")
+ assert settings.is_enabled() is False
+ assert settings.disabled_reason() == "REPOWISE_OFFLINE is set"
+
def test_stored_disable_then_enable(self):
settings.set_enabled(False)
assert settings.is_enabled() is False
diff --git a/tests/unit/health/test_grading.py b/tests/unit/health/test_grading.py
index e5f7eb88e..4b2db34e5 100644
--- a/tests/unit/health/test_grading.py
+++ b/tests/unit/health/test_grading.py
@@ -24,6 +24,7 @@ from repowise.core.analysis.health.grading import (
distribution,
format_score,
headline_band,
+ headline_scope,
)
@@ -187,3 +188,10 @@ def test_analysed_note_only_when_files_were_left_out() -> None:
assert analysed_note(4, 431) == "analysed 4 of 435 code files"
assert analysed_note(435, 0) is None
assert analysed_share(0, 0) is None
+
+
+def test_headline_scope_only_when_a_minority_was_analysed() -> None:
+ assert headline_scope(9, 106) == "across 9 of 115 code files"
+ assert headline_scope(60, 40) is None
+ assert headline_scope(115, 0) is None
+ assert headline_scope(0, 0) is None
diff --git a/tests/unit/server/mcp/test_health.py b/tests/unit/server/mcp/test_health.py
index baaeb8c48..eb25d17c7 100644
--- a/tests/unit/server/mcp/test_health.py
+++ b/tests/unit/server/mcp/test_health.py
@@ -3017,6 +3017,17 @@ def test_kpis_name_production_code_beside_the_all_files_average() -> None:
assert "production_average" not in _compute_kpis([prod], deductions={})
+def test_kpis_scope_a_score_most_code_files_did_not_feed() -> None:
+ from repowise.core.persistence.models import HealthFileMetric
+ from repowise.server.mcp_server.tool_health.summary import _compute_kpis
+
+ rows = [HealthFileMetric(file_path=f"s{i}.sh", score=10.0, nloc=10) for i in range(9)]
+ minority = _compute_kpis(rows, unanalysed=106, deductions={})
+ assert minority["average_health_scope"] == "across 9 of 115 code files"
+ assert minority["band"] is None
+ assert "average_health_scope" not in _compute_kpis(rows, unanalysed=1, deductions={})
+
+
@pytest.mark.asyncio
async def test_workspace_rows_count_the_files_the_overview_counts(setup_mcp, health_data, session):
"""repo="all" and the single-repo overview state one file count."""
diff --git a/tests/unit/upgrade/test_release.py b/tests/unit/upgrade/test_release.py
index dfc758957..4db90818d 100644
--- a/tests/unit/upgrade/test_release.py
+++ b/tests/unit/upgrade/test_release.py
@@ -5,6 +5,8 @@ from __future__ import annotations
import json
+import pytest
+
import repowise.core.upgrade.release as rel
from repowise.core.upgrade.release import (
BUNDLED_CHANGELOG_PATH,
@@ -126,3 +128,40 @@ def test_check_latest_version_cached_does_not_poison_on_failure(monkeypatch, tmp
assert calls["n"] == 2
assert second.latest_version == "9.9.9"
assert second.update_available is True
+
+
+# --- offline / opt-out switches -------------------------------------------
+
+
[email protected]("var", ["REPOWISE_OFFLINE", "DO_NOT_TRACK", "REPOWISE_TELEMETRY_DISABLED"])
+def test_network_off_switches_skip_release_fetches(monkeypatch, var):
+ import httpx
+
+ def _boom(*args, **kwargs):
+ raise AssertionError("network call made with an off switch set")
+
+ monkeypatch.setattr(httpx, "get", _boom)
+ monkeypatch.setenv(var, "1")
+ latest, error = rel.fetch_latest_version()
+ assert latest is None and error
+ assert rel.fetch_release_highlights("1.0.0") is None
+
+
+def test_an_off_switch_leaves_no_empty_highlights_cache(monkeypatch, tmp_path):
+ """Offline must not cache "no highlights", or they stay hidden once back online."""
+ cache = tmp_path / "highlights.json"
+ monkeypatch.setattr(rel, "_HIGHLIGHTS_CACHE_PATH", cache)
+ monkeypatch.setenv("REPOWISE_OFFLINE", "1")
+
+ assert rel.latest_highlights_cached("1.0.0") == []
+ assert not cache.exists()
+
+
+def test_do_not_track_zero_keeps_the_network_on(monkeypatch):
+ from repowise.core.platform.telemetry import network_disabled
+
+ for var in ("REPOWISE_OFFLINE", "REPOWISE_TELEMETRY_DISABLED"):
+ monkeypatch.delenv(var, raising=False)
+ monkeypatch.setenv("DO_NOT_TRACK", "0")
+
+ assert network_disabled() is False