Run doctor checks via daemon, streaming results to on_result callback.
(
project_root: str | None = None,
on_result: Callable[[DoctorCheckResult], None] | None = None,
)
| 360 | |
| 361 | |
| 362 | def doctor( |
| 363 | project_root: str | None = None, |
| 364 | on_result: Callable[[DoctorCheckResult], None] | None = None, |
| 365 | ) -> list[DoctorCheckResult]: |
| 366 | """Run doctor checks via daemon, streaming results to on_result callback.""" |
| 367 | if project_root is not None: |
| 368 | project_root = normalize_input_path(project_root) |
| 369 | conn = _connect_and_handshake() |
| 370 | try: |
| 371 | conn.send_bytes(encode_request(DoctorRequest(project_root=project_root))) |
| 372 | results: list[DoctorCheckResult] = [] |
| 373 | while True: |
| 374 | try: |
| 375 | data = conn.recv_bytes() |
| 376 | except EOFError: |
| 377 | raise RuntimeError("Connection to daemon lost during doctor checks") |
| 378 | resp = decode_response(data) |
| 379 | if isinstance(resp, ErrorResponse): |
| 380 | detail = f"Daemon error: {resp.message}" |
| 381 | if resp.traceback: |
| 382 | detail += f"\n{resp.traceback}" |
| 383 | raise RuntimeError(detail) |
| 384 | if isinstance(resp, DoctorResponse): |
| 385 | results.append(resp.result) |
| 386 | if on_result is not None: |
| 387 | on_result(resp.result) |
| 388 | if resp.final: |
| 389 | break |
| 390 | else: |
| 391 | raise RuntimeError(f"Unexpected response: {type(resp).__name__}") |
| 392 | return results |
| 393 | finally: |
| 394 | conn.close() |
| 395 | |
| 396 | |
| 397 | # --------------------------------------------------------------------------- |
nothing calls this directly
no test coverage detected