diagnostics

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package diagnostics contains the opt-in, protocol-neutral event contract shared by MCP and transport adapters. It deliberately accepts typed fields only; raw URLs, headers, bodies, cookies and arbitrary log text do not belong in this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Emit

func Emit(ctx context.Context, event Event)

Emit sends an event when the context carries a diagnostic scope.

func WithChildScope

func WithChildScope(ctx context.Context, module Module, requestID uint64) context.Context

WithChildScope changes only the module and request number while preserving the parent sink. Without a parent scope it deliberately remains a no-op; this keeps public SDK usage quiet outside the CLI/MCP bootstrap.

func WithScope

func WithScope(ctx context.Context, sink Sink, module Module, requestID uint64) context.Context

WithScope installs an explicit diagnostic scope. A nil sink is converted to a no-op sink so ordinary SDK callers remain silent and nil-safe.

Types

type Event

type Event struct {
	Module    Module
	Kind      EventKind
	Operation string
	Resource  string
	Route     string
	Target    string
	Proxy     string
	UserAgent string
	Reason    Reason
	Status    int
	Count     int
	RequestID uint64
	Duration  time.Duration
}

Event is the complete safe diagnostic payload. Resource and Target are non-secret identifiers or local destinations supplied by trusted adapters; the presenter removes URL userinfo, query and fragment before rendering.

type EventKind

type EventKind string

EventKind is a closed set of diagnostic lifecycle stages. Event data is intentionally finite and safe; callers cannot supply preformatted output.

const (
	EventStarted         EventKind = "started"
	EventCompleted       EventKind = "completed"
	EventFailed          EventKind = "failed"
	EventNetworkRequest  EventKind = "network_request"
	EventChallenge       EventKind = "challenge"
	EventSolverStarted   EventKind = "solver_started"
	EventSolverCompleted EventKind = "solver_completed"
	EventReplay          EventKind = "replay"
	EventDownload        EventKind = "download"
	EventAccount         EventKind = "account"
	EventConfiguration   EventKind = "configuration"
)

type Module

type Module string

Module is the stable product and subsystem prefix shown by the presenter.

const (
	ModulePixivCLI       Module = "Pixiv CLI"
	ModuleFanboxCLI      Module = "FANBOX CLI"
	ModulePixivMCP       Module = "Pixiv MCP server"
	ModuleFanboxMCP      Module = "FANBOX MCP server"
	ModulePixivAccount   Module = "Pixiv account pool"
	ModulePixivAuth      Module = "Pixiv authentication"
	ModuleFanboxAuth     Module = "FANBOX authentication"
	ModulePixivAuthDB    Module = "Pixiv authentication database"
	ModuleFanboxAuthDB   Module = "FANBOX authentication database"
	ModulePixivConfig    Module = "Pixiv configuration"
	ModuleFanboxConfig   Module = "FANBOX configuration"
	ModulePixivNetwork   Module = "Pixiv network"
	ModuleFanboxNetwork  Module = "FANBOX network"
	ModuleFanboxSolver   Module = "FANBOX FlareSolverr"
	ModulePixivDownload  Module = "Pixiv download"
	ModuleFanboxDownload Module = "FANBOX download"

	// Descriptive aliases keep call sites readable when they distinguish the
	// server subsystem from the product name.
	ModulePixivMCPServer  = ModulePixivMCP
	ModuleFanboxMCPServer = ModuleFanboxMCP
)

type Reason

type Reason string

Reason is a stable, non-secret explanation selected by the emitting layer. Raw Go errors do not belong in Event; the command boundary still returns the original business error through its normal error path.

const (
	ReasonNone                 Reason = ""
	ReasonCommandFailed        Reason = "command failed"
	ReasonToolFailed           Reason = "tool failed"
	ReasonChallenge            Reason = "challenge required"
	ReasonSolverUnavailable    Reason = "solver unavailable"
	ReasonSolverFailed         Reason = "solver failed"
	ReasonMalformedSolver      Reason = "malformed solver response"
	ReasonAccountFrozen        Reason = "account frozen"
	ReasonAccountExhausted     Reason = "account pool exhausted"
	ReasonConfigurationFailed  Reason = "configuration failed"
	ReasonAuthenticationFailed Reason = "authentication failed"
)

type Scope

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

Scope binds a sink, module and optional MCP-local request number to a context. A zero request ID is reserved for a top-level CLI operation.

func ScopeFromContext

func ScopeFromContext(ctx context.Context) (Scope, bool)

ScopeFromContext returns the current scope for tests and controlled adapter composition. The sink itself is intentionally not exported as a field.

func (Scope) Emit

func (scope Scope) Emit(event Event)

Emit makes Scope implement a convenient direct sink-like API.

type Sink

type Sink interface {
	Emit(Event)
}

Sink receives one typed event at a time.

func Nop

func Nop() Sink

Nop returns the sink used when diagnostics are disabled.

type SinkFunc

type SinkFunc func(Event)

SinkFunc adapts a function to Sink.

func (SinkFunc) Emit

func (f SinkFunc) Emit(event Event)

Jump to

Keyboard shortcuts

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