doctorcmd

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package doctorcmd implements the `doctor` command: a read-only assessment of whether the current key configuration can reach and trade on Korbit, with a fix named for every problem. It runs against the clienv.Cmd seam, so the cli (and the mcp doctor tool) dispatch into it without it importing cli. The Report renders its own human ✓/⚠/✗ checklist via FormatText (format.go), implementing textout.TextFormatter.

Index

Constants

View Source
const (
	CheckOK   = "ok"
	CheckWarn = "warn"
	CheckFail = "fail"
)

Check statuses, in increasing severity. CheckWarn does not flip the overall verdict; CheckFail marks a blocking config problem. Report.FormatText (format.go) renders these as the ✓/⚠/✗ marks.

Variables

This section is empty.

Functions

func Run

func Run(cx *clienv.Cmd, cmd *cobra.Command, args []string) error

Run implements the `doctor` command: a read-only assessment of whether the current key configuration can reach and trade on Korbit, with a fix named for every problem. ExitSuccess = healthy (warnings allowed), ExitConfig = blocking config problem, ExitInternal = only a network failure prevented verification.

Types

type Check

type Check struct {
	Name   string `json:"name"`
	Status string `json:"status"`
	Detail string `json:"detail"`
	// Context is optional secondary detail shown beneath Detail — e.g. the raw
	// transport error behind a "(network error)" summary. Kept out of Detail so
	// the human summary stays terse while the underlying cause is still recorded
	// (its own line in the text report, the `context` field in --json).
	Context string `json:"context,omitempty"`
	Fix     string `json:"fix,omitempty"`
}

Check is one diagnostic line: a name, a status, what was observed, and (when not ok) the exact fix.

type Report

type Report struct {
	OK   bool   `json:"ok"`
	Home string `json:"home"`
	// DefaultKeystore is the backend NEW keys go to; each existing key carries
	// its own backend (the keystore checks probe every backend in use).
	DefaultKeystore string `json:"defaultKeystore"`
	Key             string `json:"key,omitempty"`
	BaseURL         string `json:"baseUrl"`
	// WSBaseURL is the WebSocket endpoint the selected key would use (what
	// `monitor` resolves), shown so a check run against the sandbox or a per-key
	// host is never mistaken for production. Doctor probes it best-effort.
	WSBaseURL string  `json:"wsBaseUrl"`
	Checks    []Check `json:"checks"`
}

Report is the full machine-readable health report. `ok` is true when no check failed (warnings are allowed). It is exported so `setup` can embed the complementary health check it runs for a just-configured key (see Assess).

func AdvisoryReport

func AdvisoryReport(cx *clienv.Cmd, cmd *cobra.Command, forceKey string) *Report

AdvisoryReport runs Assess as an ADVISORY check and always returns a report, never an error. A hard fault Assess surfaces as an error (e.g. an unsafe base URL, or an unresolvable credential) becomes a single failing check, so a caller that embeds the report — `setup`'s complementary health check — shows it as a warning instead of dropping it or failing. forceKey pins a specific key (see Assess). Used by callers that embed the report instead of emitting it, so they behave alike.

func Assess

func Assess(cx *clienv.Cmd, cmd *cobra.Command, forceKey string) (Report, int, error)

Assess computes the doctor report and its exit code (ExitSuccess/ExitInternal/ExitConfig) for the selected key WITHOUT emitting it. forceKey, when non-empty, pins the assessment to that stored key, bypassing the --key/default/sole selection — `setup` uses it to health-check the key it just configured. The returned error is reserved for hard faults that aren't a report check (unreadable config, an unsafe base URL). Run wraps this and emits; AdvisoryReport wraps it for callers that want those faults folded into the report instead of returned.

func (Report) FormatText

func (r Report) FormatText(w io.Writer)

FormatText renders the doctor report as a ✓/⚠/✗ checklist for human output, satisfying textout.TextFormatter so the emitter renders it from these typed fields (the --json path marshals the same struct). The report carries the resolved endpoint(s) and home so a pass against the sandbox or a per-key host is never mistaken for production.

Jump to

Keyboard shortcuts

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