kernel

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustRegister

func MustRegister(cmd Command)

MustRegister registers a command or panics on failure.

func MustRegisterHandler

func MustRegisterHandler(name string, handler HandlerFunc)

MustRegisterHandler registers a handler or panics on failure.

func Register

func Register(cmd Command) error

Register adds a command to the default registry.

func RegisterHandler

func RegisterHandler(name string, handler HandlerFunc) error

RegisterHandler registers a handler for a command in the default registry.

func Run

func Run(ctx context.Context, name string, input any) (any, error)

Run executes a handler in the default registry.

Types

type Command

type Command struct {
	Name        string       `json:"name"`
	Description string       `json:"description"`
	Category    string       `json:"category,omitempty"`
	Input       *SchemaRef   `json:"input,omitempty"`
	Output      *SchemaRef   `json:"output,omitempty"`
	REST        *RESTBinding `json:"rest,omitempty"`
	Examples    []Example    `json:"examples,omitempty"`
	SafetyLevel SafetyLevel  `json:"safety_level,omitempty"`
	EmitsEvents []string     `json:"emits_events,omitempty"`
	Idempotent  bool         `json:"idempotent,omitempty"`
}

Command describes a kernel command with metadata for CLI/TUI/REST.

func Get

func Get(name string) (Command, bool)

Get returns a command from the default registry.

func List

func List() []Command

List returns all commands from the default registry.

type Example

type Example struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Command     string `json:"command,omitempty"`
	Input       string `json:"input,omitempty"`
	Output      string `json:"output,omitempty"`
}

Example provides a usage example for OpenAPI and documentation.

type HandlerFunc

type HandlerFunc func(ctx context.Context, input any) (any, error)

HandlerFunc executes a command with the provided input.

type ListResponse

type ListResponse struct {
	Commands []Command `json:"commands"`
	Count    int       `json:"count"`
}

ListResponse is the output schema for listing registered commands.

type RESTBinding

type RESTBinding struct {
	Method string `json:"method,omitempty"`
	Path   string `json:"path,omitempty"`
}

RESTBinding describes the REST endpoint mapping for a command.

type Registry

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

Registry stores command metadata for CLI/TUI/REST surfaces.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty registry.

func (*Registry) Get

func (r *Registry) Get(name string) (Command, bool)

Get returns a command by name.

func (*Registry) List

func (r *Registry) List() []Command

List returns all commands in deterministic order.

func (*Registry) Register

func (r *Registry) Register(cmd Command) error

Register adds a command to the registry with validation.

func (*Registry) RegisterHandler

func (r *Registry) RegisterHandler(name string, handler HandlerFunc) error

RegisterHandler associates a handler with a registered command.

func (*Registry) Run

func (r *Registry) Run(ctx context.Context, name string, input any) (any, error)

Run executes a registered command handler.

type SafetyLevel

type SafetyLevel string

SafetyLevel indicates the operational risk of a command.

const (
	SafetySafe    SafetyLevel = "safe"
	SafetyCaution SafetyLevel = "caution"
	SafetyDanger  SafetyLevel = "danger"
)

type SchemaRef

type SchemaRef struct {
	Name        string `json:"name,omitempty"`
	Ref         string `json:"ref,omitempty"`
	Description string `json:"description,omitempty"`
}

SchemaRef points to an input or output schema used by a command. Ref should be a stable identifier (e.g., a Go type name or JSON Schema ref).

Jump to

Keyboard shortcuts

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