cli

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package cli implements the user- and agent-facing JetKVM command tree.

Cobra owns command parsing and help generation. Device and MCP behavior is injected so this package remains an adapter over the shared application core.

Index

Constants

View Source
const (
	ExitOK          = 0
	ExitInternal    = 1
	ExitUsage       = 2
	ExitNotFound    = 3
	ExitAuth        = 4
	ExitUnavailable = 5
	ExitUnsupported = 6
	ExitConflict    = 7
	ExitAmbiguous   = 8
)

Exit codes are part of the CLI's stable machine-facing contract.

Variables

View Source
var (
	ErrConfirmationRequired    = errors.New("action-time confirmation is required")
	ErrConfirmationUnavailable = errors.New("confirmation issuer is unavailable")
)

Functions

func ExitCode

func ExitCode(err error) int

ExitCode maps command failures to the stable process exit contract.

Types

type App

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

App owns one configured command tree and its output policy.

func New

func New(deps Dependencies) *App

New constructs the complete public command tree.

func (*App) Command

func (a *App) Command() *cobra.Command

Command exposes the Cobra tree for executable-level integration and help. Prefer Execute when the caller also needs stable exit-code handling.

func (*App) Execute

func (a *App) Execute(ctx context.Context, args []string) int

Execute runs the command and renders failures to stderr using the selected output mode. Successful command results are the only non-MCP bytes written to stdout.

type AutomationService

AutomationService is the CLI-facing control boundary implemented by the shared automation core. CLI commands never access JetKVM transports or RPCs.

type ConfirmationIssuer

type ConfirmationIssuer interface {
	Issue(context.Context, ConfirmationRequest) (context.Context, error)
}

ConfirmationIssuer prompts only when Interactive is true, or redeems an already-issued internal proof for non-interactive execution. It returns a context carrying that proof for the shared core to verify at execution time.

type ConfirmationRequest

type ConfirmationRequest struct {
	DeviceID    domain.DeviceID
	Ref         control.Ref
	OperationID uuid.UUID
	Action      string
	Summary     string
	Interactive bool
	Binding     confirmation.Binding
}

ConfirmationRequest binds an action-time confirmation to the exact device, control generation, operation, and normalized human-readable summary.

type Dependencies

type Dependencies struct {
	Devices       domain.DeviceService
	Automation    AutomationService
	Releaser      InputReleaser
	Confirmations ConfirmationIssuer
	MCP           MCPServer
	Version       buildinfo.Info
	Stdin         io.Reader
	Stdout        io.Writer
	Stderr        io.Writer
	IsTerminal    func(io.Writer) bool
	Logger        Logger
	Loader        RuntimeLoader
	ConfigPath    string
	Updater       UpdateService
	Setup         SetupService
	MCPLoader     func(context.Context, string) (MCPServer, func() error, error)
	OpenBrowser   func(context.Context, string) error
	InputTerminal func(io.Reader) bool
}

Dependencies are supplied by the executable's composition root.

type InputReleaser

type InputReleaser interface {
	ReleaseInput(context.Context, automation.ReleaseInputRequest) (operation.Receipt, error)
}

ReleaseInputRequest identifies an explicit neutralization operation. It is separate from an action batch because an empty or synthetic batch must never masquerade as terminal input release. InputReleaser is the dedicated core capability required by `input release`. A runtime that does not implement it fails closed instead of using close or direct HID as a substitute.

type Logger

type Logger interface {
	Debug(any, ...any)
	Info(any, ...any)
	Warn(any, ...any)
	Error(any, ...any)
}

Logger deliberately matches the structured shape used by charmbracelet/log without forcing callers or this package to a concrete logging implementation. Logs must be directed to stderr by the composition root.

type MCPServeOptions

type MCPServeOptions struct {
	Transport string
	Listen    string
	Stdin     io.Reader
	Stdout    io.Writer
	Stderr    io.Writer
}

MCPServeOptions is the CLI-to-MCP adapter boundary. The MCP implementation owns protocol details; the CLI owns user-facing argument validation.

type MCPServer

type MCPServer interface {
	Serve(context.Context, MCPServeOptions) error
}

MCPServer runs the MCP adapter over the shared application core.

type Observer added in v1.0.2

type Observer interface {
	Observe(context.Context, automation.ObserveRequest) (automation.ScreenObservation, error)
}

Observer is optional so control-only adapters do not need video support.

type Runtime

type Runtime struct {
	Devices       domain.DeviceService
	Automation    AutomationService
	Releaser      InputReleaser
	Confirmations ConfirmationIssuer
	MCP           MCPServer
	OutputMode    string
	Close         func() error
}

Runtime contains the initialized application services for one CLI process. Close flushes durable state and releases process-owned resources.

type RuntimeLoader

type RuntimeLoader interface {
	Load(context.Context, string) (Runtime, error)
}

RuntimeLoader creates the shared core after Cobra has parsed the authoritative --config flag. CLI and MCP commands then receive the same service instances.

type RuntimeLoaderFunc

type RuntimeLoaderFunc func(context.Context, string) (Runtime, error)

RuntimeLoaderFunc adapts a function to RuntimeLoader.

func (RuntimeLoaderFunc) Load

func (f RuntimeLoaderFunc) Load(ctx context.Context, path string) (Runtime, error)

Jump to

Keyboard shortcuts

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