You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Swarm sessions in particular benefit from a pre-flight that catches cgroup CPU quota mismatches, NUMA topology surprises, and target/tmp headroom before a 10-agent run dies halfway through.
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.
New module src/doctor/ with one file per area. Each probe returns DoctorFinding { area, severity: Info|Warn|Fail, summary, details, suggested_fix: Option<String>, fix_command: Option<String> }.
auth: reuse src/auth/doctor.rs; report each configured provider's status.
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.
Add general-purpose
jcode doctordiagnostic commandSummary
Add a top-level
jcode doctor(andjcode 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. Todayjcode auth-testandjcode provider doctorcover auth only.Reference:
pi_agent_rustpi doctor.Why
doctorexisted: [Bug] It doesn't work at all 1jehuang/jcode#231, Bug: Server fails to start with "No credentials configured" error despite successful OpenCode Go auth 1jehuang/jcode#234, Bug: Infinite reload loop causing CPU 100% — caused by stale builds/stable directory 1jehuang/jcode#216, auto_server_reload causes infinite reload loop when binary hash is "unknown" 1jehuang/jcode#213, Bug: Infinite reload loop causing CPU 100% — caused by stale builds/stable directory 1jehuang/jcode#216, Terminal corruption after /quit - typed input invisible 1jehuang/jcode#214, Jcode crashed back to terminal prompt during tool-heavy workflow session 1jehuang/jcode#218, [Upstream #175] Repeated emergency compaction loop accumulates [Emergency compaction] markers and inflates compacted_count past messages.len() (active_messages() fallback) #135, [Upstream #177] Tried for hours: UNUSABLE - Unstable Provider Setup, Broken Model Management, and Concerning Telemetry Collection #136, [Upstream #207] No command can delete a session #153, [Upstream #233] Add logging instrumentation to 5 uninstrumented source modules #170. Even when the bug is real, support response speeds up if the user pastes adoctorreport.Current state in jcode
src/auth/doctor.rsexists but is scoped to auth.Doctorsubcommand insrc/cli/args.rs.provider doctorexists as a subsub.Implementation checklist
1. Subcommand and routing
Doctor { only: Option<DoctorArea>, format: ReportFormat, fix: bool }to the top-levelCommandenum insrc/cli/args.rs.DoctorArea:auth,sessions,swarm,mcp,browser,ambient,extensions,system,all(default).ReportFormat:text(default),json,markdown.2. Probe library
src/doctor/with one file per area. Each probe returnsDoctorFinding { area, severity: Info|Warn|Fail, summary, details, suggested_fix: Option<String>, fix_command: Option<String> }.auth: reusesrc/auth/doctor.rs; report each configured provider's status.sessions:.lockfiles (link to Terminal corruption after /quit - typed input invisible 1jehuang/jcode#214/Bug: Infinite reload loop causing CPU 100% — caused by stale builds/stable directory 1jehuang/jcode#216 root causes).swarm:$CARGO_TARGET_DIRand$TMPDIR.mcp:~/.jcode/mcp.jsonand.jcode/mcp.json; for each server, attempt a 1-second handshake; report whether the agent will actually see those tools (this would have caught feat(nix): add flake.nix for build, devShell, and checks (#95) #206 fast).browser:jcode browser statuslogic and surface its output asDoctorFindings.ambient:extensions(after the extension-runtime issue lands):system:$PATHordering of~/.local/binvs~/.cargo/bin(perAGENTS.md).3.
--fixfix_command,--fixprompts and runs them. Default: no autorun.fix_command:jcode session migrate,jcode browser setup,chmod 600 ~/.jcode/auth.json.4. Output
OK,WARN,FAIL), then a per-area summary with colors. Exit code:0if all probes areInfo,1if anyWarn,2if anyFail.docs/DOCTOR.md. Use this for scripting and CI.5. Integration with existing commands
jcode auth-test --doctor-format=jsonbecomes a thin alias tojcode doctor --only auth --format json.Testing
Unit
Integration
jcode doctorexits0and contains anauthfinding suggestingjcode login --provider claude.~/.jcode/sessions/and verifyFailis reported.Manual
Acceptance criteria
jcode doctorruns in <2 s with no network calls (auth probes are local; live checks are opt-in via--live).docs/doctor.schema.json.jcode doctor --only swarm --format jsonmatches the field set called out inpi_agent_rust's doctor docs.References
pi_agent_rust:pi doctor.Implementation notes addendum (Devin gap-analysis pass, 2026-05-21)
Verified jcode code paths
src/cli/auth_test.rs(provider auth probing). Reuse this pattern fordoctor.src/storage.rs(config/data dirs, perms harden)src/auth/,src/auth/doctor.rs(already partially exists!) → fold into the newdoctorcommandsrc/session.rs,src/session_active_pids.rssrc/mcp/src/update.rssrc/cli/startup.rs(look at how the launcher resolvesjcodevs~/.local/bin)Recommended check buckets (mirror pi_agent_rust
pi doctor --only ...)config— required dirs exist, perms, settings parse cleanlyauth— credentials present and non-expired (reuseauth/doctor.rs)shell—~/.local/binprecedes~/.cargo/bin, completions installedsessions— session dir writable, no orphaned*.lock, index reachableproviders— at least one provider can list modelsextensions(depends on TypeScript/QuickJS extension runtime for user-defined tools, commands, and hooks #3) — preflight check installed extensionsmcp— MCP server connectivityswarm— jcode-specific: ambient daemon healthupdate— current binary version vs latestCLI surface
jcode doctor(default: text)jcode doctor --format json|markdown|textjcode doctor --only auth,sessionsjcode doctor --fix(apply safe auto-fixes: chmod, create-dir, install completions)0on all-pass,1on warnings,2on errors. Important for CI gating.Cross-references
extensionsbucket.--extension-policy safe|balanced|permissive+ command-level exec mediation #14--explain-extension-policyties in cleanly withdoctor --only extensions.doctorexit-code regression.Reference
pi doctor— output formats,--only,--fix, swarm preflight details.