Skip to content

feat: enhance doctor.py with config validation, service detection, and management probing - #2

Closed
benzntech wants to merge 1 commit into
ferretgeek:mainfrom
benzntech:feat/doctor-enhancements
Closed

feat: enhance doctor.py with config validation, service detection, and management probing#2
benzntech wants to merge 1 commit into
ferretgeek:mainfrom
benzntech:feat/doctor-enhancements

Conversation

@benzntech

Copy link
Copy Markdown

Summary

Enhanced scripts/doctor.py with diagnostics and auto-fix capabilities based on real-world deployment findings.

Changes

Detection Improvements

  • User-level systemd services - Detects systemctl --user services (what the official installer creates)
  • Binary fallback - Checks common install paths (/root/cliproxyapi/, /usr/local/bin/, /opt/CLIProxyAPI/) when no systemd service is found
  • Config file discovery - Finds config.yaml next to binary if not specified via -config flag
  • Tilde expansion - Properly expands ~/.cli-proxy-api to full paths

Config Validation & Auto-Fix

  • auth-dir validation - Detects empty/missing auth-dir (causes CLIProxyAPI startup failure)
  • Auto-fix auth-dir - Creates missing directories, resolves to absolute paths
  • Management key detection - Warns when remote-management.secret-key is empty
  • Key structure validation - Detects enabled vs allow-remote key name mismatch

New CLI Flags

Flag Purpose
--auto-fix-config Auto-fix auth-dir path, create missing directories
--auto-gen-key Generate management key and write to config
--install-system-service Install system-level systemd service from user-level setup
--probe-management Test if management API is reachable
--key <KEY> Provide management key for auth probing
--json Structured output for AI parsing

Management Endpoint Probing

  • HTTP probe to /v0/management/usage with optional auth key
  • Reports reachability, auth status, and 404/401 diagnostics
  • Tip for correct key usage when auth fails

Testing

  • Verified syntax: python3 -m py_compile scripts/doctor.py
  • Tested detection on live CLIProxyAPI v6.9.16 installation
  • Confirmed management endpoint probing with valid key
  • Tilde expansion verified (~/.cli-proxy-api/root/.cli-proxy-api)

Notes

  • This PR contains backend changes only (no UI/language modifications)
  • All new features are opt-in via CLI flags; default behavior unchanged
  • Structured JSON output for AI agent integration

…d management probing

Key improvements based on real deployment findings:
- Detect user-level systemd services (systemctl --user) as fallback
- Detect CLIProxyAPI binary from common install paths when no service found
- Validate config.yaml for auth-dir, management key, and key structure issues
- Auto-fix auth-dir path when missing or empty
- Auto-generate management key (--auto-gen-key)
- Install system-level systemd service from user-level setup
- Probe management endpoint to verify connectivity and auth (--probe-management --key)
- Fix tilde (~) expansion in auth-dir paths
- All diagnostics output as structured JSON (--json) for AI parsing

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
@ferretgeek

Copy link
Copy Markdown
Owner

感谢这次贡献。当前 main 已经历较大演进,PR 与最新版存在冲突,其中 /v0/management/usage 已被移除。为避免合入过时诊断逻辑,先关闭本 PR;其中 user-level systemd、配置发现和结构化输出思路仍有价值,欢迎基于最新 main 重新拆分提交。

@ferretgeek ferretgeek closed this Aug 7, 2026
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.

2 participants