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(agents): report unknown login state, honour network-off switch (#4731)
Aman65ee62f27470
diff --git a/packages/api-client/src/types/misc.ts b/packages/api-client/src/types/misc.tsindex 39e9db9ae..9e8fa8cdd 100644--- a/packages/api-client/src/types/misc.ts+++ b/packages/api-client/src/types/misc.ts@@ -42,7 +42,7 @@ export interface ProviderInfo {/** What on this machine makes it usable: a signed-in agent CLI (only with* `detect`), a key in the env or the repo's `.repowise/.env`, or a key* stored on this server. */- detected?: "signed_in" | "env" | "saved" | null;+ detected?: "signed_in" | "installed" | "env" | "saved" | null;}export interface EmbedderInfo {diff --git a/packages/cli/src/repowise/cli/mcp_config.py b/packages/cli/src/repowise/cli/mcp_config.pyindex 1e54c9e4c..53b0f91ad 100644--- a/packages/cli/src/repowise/cli/mcp_config.py+++ b/packages/cli/src/repowise/cli/mcp_config.py@@ -131,9 +131,12 @@ def is_codex_cli_installed() -> bool:def is_codex_logged_in() -> bool:- """Return True when the local Codex CLI reports an authenticated session."""+ """Return True when the local Codex CLI reports an authenticated session.- return is_codex_cli_installed() and CODEX.is_logged_in()+ An unknown answer (login check skipped while offline) is not signed in.+ """++ return is_codex_cli_installed() and CODEX.is_logged_in() is True# ---------------------------------------------------------------------------diff --git a/packages/core/src/repowise/core/agents/identity.py b/packages/core/src/repowise/core/agents/identity.pyindex 706dc5fd0..84fbf3adc 100644--- a/packages/core/src/repowise/core/agents/identity.py+++ b/packages/core/src/repowise/core/agents/identity.py@@ -44,6 +44,8 @@ import subprocessimport threadingfrom dataclasses import dataclass, field+from repowise.core.platform.telemetry import network_disabled+#: The attribution used when evidence is absent or unrecognised. Reserved: no#: identity may claim it, because "we could not tell" and "this agent" have to#: stay distinguishable.@@ -154,13 +156,20 @@ class AgentIdentity:def is_installed(self) -> bool:return self.which() is not None- def is_logged_in(self) -> bool:- """Installed and, where the CLI can say so cheaply, signed in."""+ def is_logged_in(self) -> bool | None:+ """Whether the agent's CLI is signed in: ``True``, ``False`` or ``None``.++ ``False``: not installed, or its login query says no (or broke).+ ``None``: installed, but unknown. The CLI has no cheap login query, or+ ``network_disabled()`` forbids running one (``REPOWISE_OFFLINE``,+ ``DO_NOT_TRACK``), so nothing is spawned. Callers that need a yes+ must treat ``None`` as not signed in.+ """command = self.which()if command is None:return False- if not self.login_check:- return True+ if not self.login_check or network_disabled():+ return Nonetry:# DEVNULL: an inherited Windows console stdin can block until the timeout.result = subprocess.run(diff --git a/packages/server/src/repowise/server/provider_config.py b/packages/server/src/repowise/server/provider_config.pyindex 0967cc189..a7c1cdca8 100644--- a/packages/server/src/repowise/server/provider_config.py+++ b/packages/server/src/repowise/server/provider_config.py@@ -312,17 +312,19 @@ def resolve_for_repo()-def _logged_in(identity: Any) -> bool:- """One CLI's login check; a check that breaks counts as not signed in."""+def _logged_in(identity: Any) -> bool | None:+ """One CLI's login check: ``None`` when it cannot say; a broken check is ``False``."""try:- return bool(identity.is_logged_in())+ state = identity.is_logged_in()+ return None if state is None else bool(state)except Exception:logger.debug("Login check for %s failed", identity.slug, exc_info=True)return False-def _signed_in_agent_providers() -> set[str]:- """Catalog providers whose agent CLI is installed and signed in here.+def _agent_login_states() -> dict[str, bool | None]:+ """Login state of each catalog provider's agent CLI: ``True`` signed in,+ ``None`` installed but unknown, ``False`` otherwise.Each check is a short subprocess (the CLI's own login query), so they runside by side.@@ -335,23 +337,27 @@ def _signed_in_agent_providers() -> set[str]:if (agent := PROVIDER_SPECS[p["id"]].agent) and (identity := get_identity(agent))}if not agents:- return set()+ return {}with ThreadPoolExecutor(max_workers=len(agents)) as pool:- signed_in = list(pool.map(_logged_in, agents.values()))- return {name for name, ok in zip(agents, signed_in, strict=True) if ok}+ states = list(pool.map(_logged_in, agents.values()))+ return dict(zip(agents, states, strict=True))def _detected_source(- provider_id: str, repo_path: str | Path | None, signed_in: set[str] | None+ provider_id: str, repo_path: str | Path | None, login_states: dict[str, bool | None] | None) -> str | None:"""What on this machine makes *provider_id* usable without setup.- ``signed_in``: its agent CLI is signed in (only checked when *signed_in*- is given). ``env``: a key in the process env or the repo's+ ``signed_in``: its agent CLI is signed in. ``installed``: the CLI is on+ PATH but cannot say (no login query, or the network-off switch is set).+ Both only when *login_states* is given. ``env``: a key in the process env or the repo's``.repowise/.env``. ``saved``: a key stored on this server."""if PROVIDER_SPECS[provider_id].agent:- return "signed_in" if signed_in is not None and provider_id in signed_in else None+ state = login_states.get(provider_id, False) if login_states is not None else False+ if state is None:+ return "installed"+ return "signed_in" if state else Noneif not _CATALOG_BY_ID[provider_id]["requires_key"]:return Nonesource = resolve_api_key(provider_id, repo_path)[1]@@ -377,7 +383,7 @@ def list_provider_status("""selection = resolve_for_repo(repo_id, repo_path)active_id, model = selection.provider, selection.model- signed_in = _signed_in_agent_providers() if detect else None+ login_states = _agent_login_states() if detect else Noneproviders = []for p in PROVIDER_CATALOG:@@ -399,7 +405,7 @@ def list_provider_status("local_model": p["local_model"],"env_vars": p["env_vars"],"setup_hint": p["setup_hint"],- "detected": _detected_source(p["id"], repo_path, signed_in),+ "detected": _detected_source(p["id"], repo_path, login_states),})diff --git a/packages/server/src/repowise/server/schemas/ui_helpers.py b/packages/server/src/repowise/server/schemas/ui_helpers.pyindex b95acc787..37a5cf66f 100644--- a/packages/server/src/repowise/server/schemas/ui_helpers.py+++ b/packages/server/src/repowise/server/schemas/ui_helpers.py@@ -64,7 +64,9 @@ class ProviderEntry(BaseModel):#: What on this machine makes it usable: ``signed_in`` (a signed-in agent#: CLI, reported only for ``?detect=true``), ``env`` (a key in the process#: env or the repo's ``.repowise/.env``) or ``saved`` (a key stored here).- detected: Literal["signed_in", "env", "saved"] | None = None+ #: ``installed``: an agent CLI is on PATH but its sign-in cannot be told+ #: (no login query, or ``REPOWISE_OFFLINE``/``DO_NOT_TRACK`` is set).+ detected: Literal["signed_in", "installed", "env", "saved"] | None = Noneclass EmbedderEntry(BaseModel):diff --git a/packages/types/src/generated/http.ts b/packages/types/src/generated/http.tsindex d99ed2166..2770071eb 100644--- a/packages/types/src/generated/http.ts+++ b/packages/types/src/generated/http.ts@@ -3463,7 +3463,7 @@ export interface ProviderEntry {local_model?: boolean;env_vars?: string[];setup_hint?: string;- detected?: "signed_in" | "env" | "saved" | null;+ detected?: "signed_in" | "installed" | "env" | "saved" | null;}export interface ProviderModelEntry {diff --git a/packages/ui/src/settings/model-sources.ts b/packages/ui/src/settings/model-sources.tsindex 911c7373f..8cd9ab9cf 100644--- a/packages/ui/src/settings/model-sources.ts+++ b/packages/ui/src/settings/model-sources.ts@@ -3,6 +3,11 @@* `.repowise/.env`, or a key stored on the server. */export type ModelSourceDetection = "signed_in" | "env" | "saved";+/** What the providers API may report: a source above, or `installed` (an agent+ * CLI is on PATH but its sign-in is unknown). `installed` is not a ready+ * source, so it never reaches a row. */+export type ProviderDetection = ModelSourceDetection | "installed";+/** The provider fields the source list reads. */export interface ModelSourceProvider {id: string;@@ -10,7 +15,7 @@ export interface ModelSourceProvider {requires_key?: boolean;/** A model that runs on this machine (not an agent CLI). */local_model?: boolean;- detected?: ModelSourceDetection | null;+ detected?: ProviderDetection | null;}export type ModelSourceKind = "cli" | "key" | "local" | "paste" | "hosted";@@ -45,7 +50,8 @@ function providerSource(kind,providerId: provider.id,name: shortName(provider.name),- detected: provider.detected ?? null,+ detected:+ provider.detected === "installed" ? null : (provider.detected ?? null),};}diff --git a/tests/unit/agents/test_identity.py b/tests/unit/agents/test_identity.pyindex a56e50322..47bd45f83 100644--- a/tests/unit/agents/test_identity.py+++ b/tests/unit/agents/test_identity.py@@ -291,6 +291,8 @@ def test_login_runs_the_declared_check_and_reads_the_exit_code(monkeypatch) -> Nimport shutilimport subprocess+ for name in ("REPOWISE_OFFLINE", "DO_NOT_TRACK", "REPOWISE_TELEMETRY_DISABLED"):+ monkeypatch.delenv(name, raising=False)monkeypatch.setattr(shutil, "which", lambda name: name)calls: list[list[str]] = []@@ -303,8 +305,35 @@ def test_login_runs_the_declared_check_and_reads_the_exit_code(monkeypatch) -> Nassert not identity.CODEX.is_logged_in()assert not identity.CLAUDE_CODE.is_logged_in()assert calls == [["codex", "login", "status"], ["claude", "auth", "status"]]- # No cheap login query: installed is the most this can say.- assert identity.OPENCODE.is_logged_in()+ # No cheap login query: installed is the most this can say, so unknown.+ assert identity.OPENCODE.is_logged_in() is None+ assert identity.COPILOT.is_logged_in() is None+++def test_an_agent_not_on_path_is_not_logged_in(monkeypatch) -> None:+ import shutil++ monkeypatch.setattr(shutil, "which", lambda name: None)+ assert identity.CLAUDE_CODE.is_logged_in() is False+ assert identity.OPENCODE.is_logged_in() is False+++ "switch", ["REPOWISE_OFFLINE", "DO_NOT_TRACK", "REPOWISE_TELEMETRY_DISABLED"]+)+def test_login_check_is_not_spawned_when_the_network_is_off(monkeypatch, switch) -> None:+ import shutil+ import subprocess++ monkeypatch.setenv(switch, "1")+ monkeypatch.setattr(shutil, "which", lambda name: name)++ def fail(*args: object, **kwargs: object) -> None:+ raise AssertionError("a login check was spawned with the network off")++ monkeypatch.setattr(subprocess, "run", fail)+ assert identity.CLAUDE_CODE.is_logged_in() is None+ assert identity.CODEX.is_logged_in() is Nonedef test_identity_for_provider_follows_the_indexing_link() -> None:diff --git a/tests/unit/server/test_provider_config.py b/tests/unit/server/test_provider_config.pyindex 2abe89a1c..486208fac 100644--- a/tests/unit/server/test_provider_config.py+++ b/tests/unit/server/test_provider_config.py@@ -354,6 +354,31 @@ def test_detect_names_signed_in_agent_clis(clean_env, monkeypatch):assert "codex" in calls+def test_detect_never_reports_signed_in_for_an_agent_without_a_login_check(clean_env, monkeypatch):+ import shutil++ monkeypatch.setattr(shutil, "which", lambda name: f"/bin/{name}")+ by_id = {p["id"]: p for p in pc.list_provider_status(detect=True)["providers"]}+ assert by_id["opencode"]["detected"] == "installed"+ assert by_id["copilot_cli"]["detected"] == "installed"+++def test_detect_does_not_run_login_checks_when_the_network_is_off(clean_env, monkeypatch):+ import shutil+ import subprocess++ clean_env["DO_NOT_TRACK"] = "1"+ monkeypatch.setattr(shutil, "which", lambda name: f"/bin/{name}")++ def fail(*args, **kwargs):+ raise AssertionError("a login check was spawned with DO_NOT_TRACK set")++ monkeypatch.setattr(subprocess, "run", fail)+ by_id = {p["id"]: p for p in pc.list_provider_status(detect=True)["providers"]}+ assert by_id["claude_cli"]["detected"] == "installed"+ assert by_id["codex_cli"]["detected"] == "installed"++def test_a_broken_login_check_counts_as_not_signed_in(clean_env, monkeypatch):from repowise.core.agents.identity import AgentIdentity