Skip to content

Add ucode doctor command to diagnose and fix the local setup - #294

Open
max-rozen-oss-db wants to merge 3 commits into
mainfrom
add-doctor-command
Open

Add ucode doctor command to diagnose and fix the local setup#294
max-rozen-oss-db wants to merge 3 commits into
mainfrom
add-doctor-command

Conversation

@max-rozen-oss-db

@max-rozen-oss-db max-rozen-oss-db commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds ucode doctor — a health check for the local ucode setup, modeled on brew doctor / flutter doctor / npm doctor. It runs a series of independent checks, prints a per-check status line, and for any problem it knows how to fix, prompts to apply the fix and reports whether it worked.

Checks

Check On problem
uv on PATH error — needed to install/upgrade ucode
npm on PATH warn — needed to install agent CLIs automatically
Databricks CLI installed offers to install
Databricks CLI version vs the databricks aitools floor offers to upgrade
Workspace configured warn — points at ucode configure
Databricks credentials valid offers to run databricks auth login (the usual launch failure is an expired/invalid token surfacing as a 403 from the agent)
ANTHROPIC_AUTH_TOKEN / ANTHROPIC_API_KEY in the env warn — it shadows the credential ucode configures for Claude Code (advisory; can't unset a parent shell's env)
Each configured coding agent's CLI offers to install (if missing) or update (if outdated)
mlflow CLI, when tracing is enabled offers to install the pinned version
ucode's installed build offers a reinstall-to-latest from GitHub

Checks that don't apply are skipped: credentials/tracing only run when a workspace is configured / tracing is enabled, and the env-collision check only appears when one of those vars is set.

Behavior

  • Opt-in fixes. The command is read-only until the user says yes to a specific suggestion. Each prompt defaults to no, so a declined or non-interactive (piped) run changes nothing.
  • Per-fix outcome. After each accepted fix it prints ✓ <check>: fixed or ! <check>: fix did not complete. A failed fix doesn't abort the run or the remaining checks.
  • Output. A ✓/!/✗/• status glyph per line, then a one-line summary (No problems detected. or N issues found; M fix(es) applied.).

Example (healthy machine, piped so prompts default to no):

ucode doctor

  ✓ uv: found on PATH
  ✓ npm: found on PATH
  ✓ Databricks CLI: v1.2.1
  ✓ Workspace: https://…databricks.com
  ✓ Databricks auth: credentials are valid
  ✓ Claude Code: installed and up to date
  • ucode: v0.1.0+… (installed from GitHub)
✔ No problems detected.

Implementation notes

New logic lives in src/ucode/doctor.py; cli.py gets a thin doctor command wrapper. To avoid reaching into privates, added read-only public helpers:

  • databricks.py: databricks_cli_version() (report-only, never upgrades) and upgrade_databricks_cli().
  • agents/__init__.py: tool_binary_installed(), tool_update_available(), update_tool_binary(), tracing_mlflow_ok(), ensure_tracing_mlflow_cli().

Testing

  • uv run pytest tests/test_doctor.py tests/test_databricks.py tests/test_cli.py — passing.
  • uv run ruff check . and uv run ruff format --check src/ tests/ — clean.
  • tests/test_doctor.py covers each check's classification (ok/warn/error + whether a fix is offered), the skip-when-not-applicable paths (no workspace, tracing disabled, env var unset/blank), and the doctor flow (applies on accept, skips on decline, reports failure without raising, never prompts on a healthy check).
  • One unrelated test (test_mcp ordering assertion) fails identically on main — pre-existing, not touched by this PR.

Mirrors the `brew doctor` / `flutter doctor` / `npm doctor` pattern: run a
series of independent checks, print a per-check status (✓/!/✗/•) with an
actionable message, and for any problem ucode knows how to fix, prompt the
user to apply the fix and report success/failure.

Checks:
- `uv` on PATH (needed to install/upgrade ucode)
- `npm` on PATH (needed to install agent CLIs)
- Databricks CLI installed, and its version vs the `databricks aitools` floor
- Workspace configured
- Each configured coding agent's CLI: installed and up to date
- ucode's installed build (offers a reinstall-to-latest from GitHub)

Each fix is opt-in — the command reads state until the user says yes to a
specific suggestion, and a declined or non-interactive (piped) run changes
nothing. Adds read-only public helpers so the doctor doesn't reach into
privates: `databricks_cli_version` / `upgrade_databricks_cli` in databricks.py
and `tool_binary_installed` / `tool_update_available` / `update_tool_binary`
in agents/__init__.py.

Co-authored-by: Isaac
Extends `ucode doctor` with three checks that target the most common
real-world setup failures:

- Databricks auth: validate the configured workspace's credentials up front
  (the usual launch failure is an expired/invalid token surfacing as a 403 from
  the agent). Offers to run `databricks auth login`.
- Claude auth env collision: warn when `ANTHROPIC_AUTH_TOKEN` / `ANTHROPIC_API_KEY`
  is set in the environment, since it shadows the credential ucode configures for
  Claude Code. Advisory only — we can't unset a parent shell's env.
- Tracing (mlflow CLI): when tracing is enabled, check the pinned `mlflow` CLI is
  installed and in range; offers to install it.

The auth and tracing checks return None (and are skipped) when they don't apply
— no workspace configured, or tracing disabled. Adds read-only public helpers
`tracing_mlflow_ok` / `ensure_tracing_mlflow_cli` in agents/__init__.py so the
doctor doesn't reach into agent internals.

Co-authored-by: Isaac
# Conflicts:
#	README.md
#	tests/test_databricks.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant