skills

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 13 Imported by: ? 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 skills provides composable state machine definitions for game actions. Skills are loaded from YAML files and define sequences of game commands with conditional branching, looping, target resolution, and sub-skill composition.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearRouteProgress

func ClearRouteProgress(baseDir, agentID string) error

ClearRouteProgress removes the agent's route.json file

func EvalExpr

func EvalExpr(expr string, state *game.State) (bool, error)

EvalExpr evaluates a condition expression against game state. Supported forms:

  • Bare booleans: "docked", "has_cargo", "cargo_full", "fuel_low"
  • Negation: "not docked"
  • Comparisons: "fuel_pct < 0.1", "credits >= 5000"
  • String comparisons: "current_poi == poi-123", "system_name == Alpha"
  • Functions: "at_poi_type(station, asteroid_belt)", "has_module_type(mining)"
  • Navigation functions: "fuel_sufficient_for_jumps(4)", "at_system('sol')", "poi_is_dockable()"
  • Route functions: "has_route_progress()", "route_destination_system()", "route_step_count()"
  • Special: "default" (always true)

func EvalExprWithRoute

func EvalExprWithRoute(expr string, state *game.State, route *RouteProgress, customVars map[string]float64) (bool, error)

EvalExprWithRoute evaluates a condition expression against game state with optional route context and custom float variables (e.g. last_announce_age).

func GenerateDOT

func GenerateDOT(skill *Skill) string

GenerateDOT produces a DOT digraph representation of a single skill.

func GenerateDOTWithRegistry

func GenerateDOTWithRegistry(skill *Skill, registry *Registry) string

GenerateDOTWithRegistry produces a DOT digraph representation of a skill, optionally expanding sub-skill references using the provided registry.

func HasRouteProgress

func HasRouteProgress(baseDir, agentID string) bool

HasRouteProgress checks if an agent has a saved route

func SaveRouteProgress

func SaveRouteProgress(baseDir, agentID string, route *RouteProgress) error

SaveRouteProgress writes route state to agent's route.json

Types

type ActionDispatcher

type ActionDispatcher interface {
	Dispatch(ctx context.Context, action, target string) error
	GetState() *game.State
}

ActionDispatcher executes a single game action. This interface decouples the executor from the game client, making testing possible and allowing the agent runner to provide its own dispatch logic.

type BackgroundSlot

type BackgroundSlot struct {
	Description     string   `yaml:"description,omitempty"`
	Interrupt       string   `yaml:"interrupt"`
	CleanupOutputs  []string `yaml:"cleanup_outputs,omitempty"`
	IdleSteps       []string `yaml:"idle_steps"`
	MinIdleDuration int      `yaml:"min_idle_duration,omitempty"`
}

BackgroundSlot declares that this skill has idle windows where a background skill can run. The agent personality config fills in which skill to use.

type ClientDispatcher

type ClientDispatcher struct {
	Client    game.GameClient
	Logger    *log.Logger
	TickDelay time.Duration  // delay after tick-consuming actions; 0 = default (11s)
	Route     *RouteProgress // Active route for multi-system travel

	FoundPOI             string            // ID of most recently found POI
	SkillParams          map[string]string // Skill parameters for current execution
	LastAnnounceTime     time.Time         // Last time a service announcement was sent
	FoundDistressRequest bool              // True after scan_chat_for_distress finds a match
	// contains filtered or unexported fields
}

ClientDispatcher adapts a game.Client into an ActionDispatcher for the skill executor. It maps action names to the corresponding game client methods and waits for server ticks between actions.

After travel/jump actions it automatically refreshes system data so that POI-based conditions (current_poi_type, at_poi_type) can evaluate correctly.

func NewClientDispatcher

func NewClientDispatcher(client game.GameClient, baseDir, agentID string, logger *log.Logger) *ClientDispatcher

NewClientDispatcher creates a dispatcher wrapping a connected game client.

func (*ClientDispatcher) CustomVars

func (d *ClientDispatcher) CustomVars() map[string]float64

CustomVars returns computed variables for the expression evaluator.

func (*ClientDispatcher) Dispatch

func (d *ClientDispatcher) Dispatch(ctx context.Context, action, target string) error

Dispatch executes a single game action and waits for the tick if needed.

func (*ClientDispatcher) EnsureSystemData

func (d *ClientDispatcher) EnsureSystemData(ctx context.Context)

EnsureSystemData loads system POIs if they aren't populated yet. Call this before running a skill to make sure initial conditions can evaluate.

func (*ClientDispatcher) GetState

func (d *ClientDispatcher) GetState() *game.State

GetState returns the current game state.

type Condition

type Condition struct {
	Expr string
	Goto string
}

Condition is an ordered expression/goto pair preserving YAML key order.

type ConditionList

type ConditionList []Condition

ConditionList preserves YAML mapping key ordering for deterministic evaluation.

func (*ConditionList) UnmarshalYAML

func (cl *ConditionList) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML reads a YAML mapping node while preserving key order.

type Executor

type Executor struct {
	MaxSteps int // Safety limit; 0 = default (1000).
	// contains filtered or unexported fields
}

Executor walks a skill state machine, evaluating conditions and dispatching actions through the ActionDispatcher.

func NewExecutor

func NewExecutor(registry *Registry, dispatcher ActionDispatcher, logger *log.Logger) *Executor

NewExecutor creates a skill executor.

func (*Executor) Run

func (e *Executor) Run(ctx context.Context, skillName string) error

Run executes a skill by name to completion.

func (*Executor) RunWithParams

func (e *Executor) RunWithParams(ctx context.Context, skillName string, params map[string]string) error

RunWithParams executes a skill with parameters.

type ParameterDefinition

type ParameterDefinition struct {
	Name        string `yaml:"name"`
	Description string `yaml:"description"`
	Required    bool   `yaml:"required"`
	Default     string `yaml:"default,omitempty"`
}

ParameterDefinition defines a skill parameter with metadata.

type Registry

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

Registry holds loaded skill definitions indexed by name.

func LoadRegistry

func LoadRegistry(dir string) (*Registry, error)

LoadRegistry reads all .yaml and .yml files from a directory into a registry.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty registry.

func (*Registry) Get

func (r *Registry) Get(name string) *Skill

Get returns a skill by name, or nil if not found.

func (*Registry) Has

func (r *Registry) Has(name string) bool

Has returns true if a skill with the given name exists.

func (*Registry) LoadFromDir

func (r *Registry) LoadFromDir(dir string) error

LoadFromDir loads all skill YAML files from a directory into this registry.

func (*Registry) Names

func (r *Registry) Names() []string

Names returns all registered skill names sorted alphabetically.

type Repeat

type Repeat struct {
	While []string `yaml:"while"`
}

Repeat defines loop behavior for a step.

type RouteProgress

type RouteProgress struct {
	DestinationSystem string      `json:"destination_system"`
	DestinationPOI    string      `json:"destination_poi,omitempty"`
	Route             []RouteStep `json:"route"`
	CurrentStep       int         `json:"current_step"`
	Timestamp         time.Time   `json:"timestamp"`
}

RouteProgress stores navigation state for disconnect recovery

func LoadRouteProgress

func LoadRouteProgress(baseDir, agentID string) (*RouteProgress, error)

LoadRouteProgress reads route state from agent's route.json

type RouteStep

type RouteStep struct {
	SystemID string `json:"system_id"`
	Name     string `json:"name"`
	Jumps    int    `json:"jumps"`
}

RouteStep represents one system in a multi-jump route

type Skill

type Skill struct {
	Name           string                `yaml:"name"`
	Description    string                `yaml:"description"`
	Prerequisites  []string              `yaml:"prerequisites,omitempty"`
	Parameters     []ParameterDefinition `yaml:"parameters,omitempty"`
	Targets        map[string]Target     `yaml:"targets,omitempty"`
	Outputs        []string              `yaml:"outputs,omitempty"`
	BackgroundSlot *BackgroundSlot       `yaml:"background_slot,omitempty"`
	Steps          []Step                `yaml:"steps"`
}

Skill defines a composable state machine for game actions.

func LoadSkill

func LoadSkill(path string) (*Skill, error)

LoadSkill reads and validates a skill YAML file.

func ParseSkill

func ParseSkill(data []byte) (*Skill, error)

ParseSkill parses and validates a skill from YAML bytes.

func (*Skill) FirstStepID

func (s *Skill) FirstStepID() string

FirstStepID returns the ID of the first step.

func (*Skill) StepByID

func (s *Skill) StepByID(id string) *Step

StepByID returns the step with the given ID, or nil if not found.

func (*Skill) Validate

func (s *Skill) Validate() error

Validate checks that the skill definition is well-formed.

type Step

type Step struct {
	ID          string            `yaml:"id"`
	Action      string            `yaml:"action,omitempty"`
	Skill       string            `yaml:"skill,omitempty"`
	Check       bool              `yaml:"check,omitempty"`
	Terminal    bool              `yaml:"terminal,omitempty"`
	Target      string            `yaml:"target,omitempty"`
	Next        string            `yaml:"next,omitempty"`
	OnError     string            `yaml:"on_error,omitempty"`
	Conditions  ConditionList     `yaml:"conditions,omitempty"`
	Args        map[string]string `yaml:"args,omitempty"`
	Repeat      *Repeat           `yaml:"repeat,omitempty"`
	SkillParams map[string]string `yaml:"skill_params,omitempty"`
}

Step is a single node in the skill state machine. Exactly one of Action, Skill, Check, or Terminal must be set.

type Target

type Target struct {
	POIType     []string `yaml:"poi_type"`
	Description string   `yaml:"description"`
}

Target defines a POI type reference resolved at runtime.

Jump to

Keyboard shortcuts

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