Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Debug bool
Debug, when true, causes Send/SendBatch and instance discovery to print HTTP request/response bodies and discovery info to stderr. Set by the cmd package from the --debug flag or HERA_AGENT_DEBUG env var.
Functions ¶
func ClearInstanceCache ¶
func ClearInstanceCache()
ClearInstanceCache discards the cached scan result so the next call to ScanInstances reads from disk again. Useful in tests and after explicit install/uninstall flows where the cache could mask new state.
func IsProcessDead ¶
IsProcessDead is the public probe used by polling commands that want to detect a crashed Unity Editor without waiting for the heartbeat to stale. Returns true only when the OS confirms the process is gone.
Types ¶
type BatchCommandItem ¶
type BatchCommandItem struct {
Command string `json:"command"`
Params interface{} `json:"params,omitempty"`
}
BatchCommandItem is a single command inside a batch request.
type BatchCommandRequest ¶
type BatchCommandRequest struct {
Commands []BatchCommandItem `json:"commands"`
Options BatchOptions `json:"options"`
}
BatchCommandRequest sends multiple commands in one HTTP call.
type BatchCommandResponse ¶
type BatchCommandResponse struct {
Results []CommandResponse `json:"results"`
Completed int `json:"completed"`
Failed int `json:"failed"`
}
BatchCommandResponse is the JSON body returned by POST /commands.
func SendBatch ¶
func SendBatch(ctx context.Context, inst *Instance, req BatchCommandRequest) (*BatchCommandResponse, error)
SendBatch sends multiple commands to Unity in a single HTTP request. Timeout is derived from the command count (30s base + 15s per command, 5min cap).
type BatchOptions ¶
type BatchOptions struct {
FailFast bool `json:"fail_fast"`
}
BatchOptions controls batch execution behavior.
type CommandRequest ¶
type CommandRequest struct {
Command string `json:"command"`
Params interface{} `json:"params"`
}
CommandRequest is the JSON body sent to Unity's HTTP server.
type CommandResponse ¶
type CommandResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
Code string `json:"code,omitempty"`
Suggestions []string `json:"suggestions,omitempty"`
AgentHint string `json:"agent_hint,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
Timings map[string]int64 `json:"timings,omitempty"`
}
CommandResponse is the JSON body returned by Unity. Data is raw JSON so callers can unmarshal into any shape. Timings carries optional phase measurements (e.g. compile_ms, execute_ms, total_ms). Code/Suggestions are populated by structured error envelopes (e.g. EXEC_COMPILE_ERROR). AgentHint carries a short operational next-action for agent consumers.
type Instance ¶
type Instance struct {
State string `json:"state"`
ProjectPath string `json:"projectPath"`
Port int `json:"port"`
PID int `json:"pid"`
UnityVersion string `json:"unityVersion,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"`
CompileErrors bool `json:"compileErrors,omitempty"`
}
Instance represents a running Unity Editor discovered from ~/.hera-agent-unity/instances/.
func DiscoverInstance ¶
DiscoverInstance finds a running Unity instance from ~/.hera-agent-unity/instances/. If port > 0, matches an active instance by port. If project is set, matches by project path substring. Otherwise returns the most recently active instance.
func FindActiveByPort ¶
FindActiveByPort is like FindByPort but skips stopped or incomplete instances. Used by polling paths (waitForAlive, waitForReady) that only care about live instances.
func FindByPort ¶
FindByPort scans instance files and returns the instance matching the given port. If multiple instances share the same port, the one with the most recent timestamp wins.
func ScanInstances ¶
ScanInstances reads all instance files from ~/.hera-agent-unity/instances/. Stale files whose PID is no longer running are automatically removed. Results are cached for instanceCacheTTL to keep multi-step workflows (batch, exec → console → exec, etc.) from re-stat'ing the dir on every hop.