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 ¶
- func ClearRouteProgress(baseDir, agentID string) error
- func EvalExpr(expr string, state *game.State) (bool, error)
- func EvalExprWithRoute(expr string, state *game.State, route *RouteProgress, ...) (bool, error)
- func GenerateDOT(skill *Skill) string
- func GenerateDOTWithRegistry(skill *Skill, registry *Registry) string
- func HasRouteProgress(baseDir, agentID string) bool
- func SaveRouteProgress(baseDir, agentID string, route *RouteProgress) error
- type ActionDispatcher
- type BackgroundSlot
- type ClientDispatcher
- type Condition
- type ConditionList
- type Executor
- type ParameterDefinition
- type Registry
- type Repeat
- type RouteProgress
- type RouteStep
- type Skill
- type Step
- type Target
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearRouteProgress ¶
ClearRouteProgress removes the agent's route.json file
func EvalExpr ¶
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 ¶
GenerateDOT produces a DOT digraph representation of a single skill.
func GenerateDOTWithRegistry ¶
GenerateDOTWithRegistry produces a DOT digraph representation of a skill, optionally expanding sub-skill references using the provided registry.
func HasRouteProgress ¶
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 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.
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 ¶
LoadRegistry reads all .yaml and .yml files from a directory into a registry.
func (*Registry) LoadFromDir ¶
LoadFromDir loads all skill YAML files from a directory into this registry.
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 ParseSkill ¶
ParseSkill parses and validates a skill from YAML bytes.
func (*Skill) FirstStepID ¶
FirstStepID returns the ID of the first step.
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.