Skip to content

Add general-purpose jcode doctor diagnostic command #8

@quangdang46

Description

@quangdang46

Add general-purpose jcode doctor diagnostic command

Summary

Add a top-level jcode doctor (and jcode doctor --only <area>) command that inspects the user's environment and prints a structured report covering: auth, sessions, swarm readiness, MCP, browser, ambient, extensions, disk headroom, cgroup/CPU/memory budgets, and known platform quirks. Today jcode auth-test and jcode provider doctor cover auth only.

Reference: pi_agent_rust pi doctor.

Why

Current state in jcode

  • src/auth/doctor.rs exists but is scoped to auth.
  • No top-level Doctor subcommand in src/cli/args.rs. provider doctor exists as a subsub.

Implementation checklist

1. Subcommand and routing

  • Add Doctor { only: Option<DoctorArea>, format: ReportFormat, fix: bool } to the top-level Command enum in src/cli/args.rs.
  • DoctorArea: auth, sessions, swarm, mcp, browser, ambient, extensions, system, all (default).
  • ReportFormat: text (default), json, markdown.

2. Probe library

3. --fix

  • For findings that carry fix_command, --fix prompts and runs them. Default: no autorun.
  • Examples of fix_command: jcode session migrate, jcode browser setup, chmod 600 ~/.jcode/auth.json.

4. Output

  • Text mode: headed by an overall status (OK, WARN, FAIL), then a per-area summary with colors. Exit code: 0 if all probes are Info, 1 if any Warn, 2 if any Fail.
  • JSON mode: stable schema documented in docs/DOCTOR.md. Use this for scripting and CI.

5. Integration with existing commands

  • jcode auth-test --doctor-format=json becomes a thin alias to jcode doctor --only auth --format json.

Testing

Unit

  • Each probe has a unit test driven by fixtures (e.g. mock cgroup files under a temp dir).
  • JSON schema is stable: a snapshot test rejects accidental changes.

Integration

  • On a clean Linux box, jcode doctor exits 0 and contains an auth finding suggesting jcode login --provider claude.
  • Simulate an unwritable ~/.jcode/sessions/ and verify Fail is reported.

Manual

  • Run on macOS and Windows; verify platform-specific probes degrade gracefully.

Acceptance criteria

  • jcode doctor runs in <2 s with no network calls (auth probes are local; live checks are opt-in via --live).
  • Exit codes follow the documented convention.
  • JSON output validates against docs/doctor.schema.json.
  • jcode doctor --only swarm --format json matches the field set called out in pi_agent_rust's doctor docs.

References


Implementation notes addendum (Devin gap-analysis pass, 2026-05-21)

Verified jcode code paths

  • Existing diagnostic-shaped subcommand: src/cli/auth_test.rs (provider auth probing). Reuse this pattern for doctor.
  • Health-relevant code surfaces:
    • Storage: src/storage.rs (config/data dirs, perms harden)
    • Auth: src/auth/, src/auth/doctor.rs (already partially exists!) → fold into the new doctor command
    • Session storage health: src/session.rs, src/session_active_pids.rs
    • MCP servers: src/mcp/
    • Update channel: src/update.rs
    • Shell PATH: src/cli/startup.rs (look at how the launcher resolves jcode vs ~/.local/bin)

Recommended check buckets (mirror pi_agent_rust pi doctor --only ...)

  • config — required dirs exist, perms, settings parse cleanly
  • auth — credentials present and non-expired (reuse auth/doctor.rs)
  • shell~/.local/bin precedes ~/.cargo/bin, completions installed
  • sessions — session dir writable, no orphaned *.lock, index reachable
  • providers — at least one provider can list models
  • extensions (depends on TypeScript/QuickJS extension runtime for user-defined tools, commands, and hooks #3) — preflight check installed extensions
  • mcp — MCP server connectivity
  • swarm — jcode-specific: ambient daemon health
  • update — current binary version vs latest

CLI surface

  • jcode doctor (default: text)
  • jcode doctor --format json|markdown|text
  • jcode doctor --only auth,sessions
  • jcode doctor --fix (apply safe auto-fixes: chmod, create-dir, install completions)
  • Exit code: 0 on all-pass, 1 on warnings, 2 on errors. Important for CI gating.

Cross-references

Reference

  • pi_agent_rust: pi doctor — output formats, --only, --fix, swarm preflight details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions