doctor

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 1 Imported by: 0

README

Doctor Package

The doctor package provides a pluggable diagnostic system for Moat. It allows different components to register diagnostic sections that can be displayed via the moat doctor command.

Architecture

The doctor system uses a simple registry pattern:

type Section interface {
    Name() string
    Print(w io.Writer) error
}

Any package can implement a Section and register it with the doctor command. This makes the diagnostic system extensible without tight coupling.

Usage

Implementing a Doctor Section

To add diagnostic output for your package:

  1. Implement the doctor.Section interface:
package mypackage

import (
    "fmt"
    "io"
)

type DoctorSection struct{}

func (d *DoctorSection) Name() string {
    return "My Package Configuration"
}

func (d *DoctorSection) Print(w io.Writer) error {
    // Output diagnostic information
    fmt.Fprintln(w, "Status: ✅ OK")
    fmt.Fprintln(w, "Version: 1.0.0")
    return nil
}
  1. Register it in the doctor command (cmd/moat/cli/doctor.go):
reg.Register(&mypackage.DoctorSection{})
Examples

See existing implementations:

  • Claude section (cmd/moat/cli/doctor.go:claudeSection) - Shows Claude Code configuration including:

    • ~/.claude.json config status
    • ~/.claude/settings.json plugins and marketplaces
    • MCP server configuration
  • Codex section (internal/codex/doctor.go) - Shows OpenAI Codex configuration:

    • Config directory status
    • Session information
    • Auth file warnings (should only exist in containers)
  • Credentials section (cmd/moat/cli/doctor.go:credentialSection) - Shows stored credentials:

    • Token prefixes (safe to display)
    • JWT token claims (redacted)
    • Expiration status
    • OAuth scopes

Design Principles

  1. Redact Sensitive Data - Never output full tokens, secrets, or credentials. Show prefixes or redacted values.

  2. Actionable Output - When something is wrong, tell the user exactly what to do to fix it.

  3. Graceful Degradation - If a section fails, show an error but continue with other sections.

  4. Pluggable - Packages should be able to add their own diagnostic output without modifying the core doctor command logic.

Security

The doctor output is designed to be safe to share for debugging:

  • Tokens are shown as prefixes only (e.g., sk-ant-api03...)
  • JWT claims are redacted (showing first few characters of IDs)
  • Sensitive metadata is filtered out
  • Expiration times are shown as durations, not absolute timestamps

Never include full credentials, API keys, or other secrets in doctor output.

Documentation

Overview

Package doctor provides diagnostic output for debugging Moat.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds all registered doctor sections.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new doctor section registry.

func (*Registry) Register

func (r *Registry) Register(s Section)

Register adds a section to the registry.

func (*Registry) Sections

func (r *Registry) Sections() []Section

Sections returns all registered sections.

type Section

type Section interface {
	// Name returns the section name (e.g., "Container Runtime")
	Name() string

	// Print outputs the section's diagnostic information to the writer.
	// Returns an error if the section fails to generate diagnostics.
	Print(w io.Writer) error
}

Section represents a diagnostic section that can be printed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL