Documentation
¶
Index ¶
- Variables
- func ClearInstanceCache()
- func IsProcessDead(pid int) bool
- type BatchCommandItem
- type BatchCommandRequest
- type BatchCommandResponse
- type BatchOptions
- type Client
- func (c *Client) ClearInstanceCache()
- func (c *Client) DiscoverInstance(project string, port int) (*Instance, error)
- func (c *Client) FindActiveByPort(port int) (*Instance, error)
- func (c *Client) FindByPort(port int) (*Instance, error)
- func (c *Client) IsProcessDead(pid int) bool
- func (c *Client) ScanInstances() ([]Instance, error)
- func (c *Client) Send(inst *Instance, command string, params interface{}, timeoutMs int) (*CommandResponse, error)
- func (c *Client) SendBatch(ctx context.Context, inst *Instance, req BatchCommandRequest) (*BatchCommandResponse, error)
- type CommandRequest
- type CommandResponse
- type Instance
- type InstanceCache
Constants ¶
This section is empty.
Variables ¶
var DefaultClient = NewClient()
DefaultClient is the package-level singleton used by the top-level Send and SendBatch convenience functions.
Functions ¶
func ClearInstanceCache ¶
func ClearInstanceCache()
ClearInstanceCache delegates to DefaultClient.ClearInstanceCache.
func IsProcessDead ¶
IsProcessDead delegates to DefaultClient.IsProcessDead.
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 is a convenience wrapper that delegates to DefaultClient.SendBatch.
type BatchOptions ¶
type BatchOptions struct {
FailFast bool `json:"fail_fast"`
}
BatchOptions controls batch execution behavior.
type Client ¶ added in v0.0.15
type Client struct {
Debug bool
// contains filtered or unexported fields
}
Client holds per-client configuration, an HTTP client, an instance cache, and a process-death checker. Use NewClient to create a fully initialized instance, or DefaultClient for the package-level singleton.
func NewClient ¶ added in v0.0.15
func NewClient() *Client
NewClient creates a Client with the default HTTP client, instance cache, and OS-specific process-death checker.
func (*Client) ClearInstanceCache ¶ added in v0.0.15
func (c *Client) 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 (*Client) DiscoverInstance ¶ added in v0.0.15
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 (*Client) FindActiveByPort ¶ added in v0.0.15
FindActiveByPort is like FindByPort but skips stopped or incomplete instances. Used by polling paths (waitForAlive, waitForReady) that only care about live instances.
func (*Client) FindByPort ¶ added in v0.0.15
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 (*Client) IsProcessDead ¶ added in v0.0.15
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.
func (*Client) ScanInstances ¶ added in v0.0.15
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.
func (*Client) SendBatch ¶ added in v0.0.15
func (c *Client) 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 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 delegates to DefaultClient.DiscoverInstance.
func FindActiveByPort ¶
FindActiveByPort delegates to DefaultClient.FindActiveByPort.
func FindByPort ¶
FindByPort delegates to DefaultClient.FindByPort.
func ScanInstances ¶
ScanInstances delegates to DefaultClient.ScanInstances.
type InstanceCache ¶ added in v0.0.15
type InstanceCache struct {
// contains filtered or unexported fields
}
InstanceCache stores the last ScanInstances result for process-level reuse. A 5-second TTL is short enough that a stopped editor disappears quickly, but long enough that batch / multi-step workflows don't re-stat the dir on every hop.
func NewInstanceCache ¶ added in v0.0.15
func NewInstanceCache() *InstanceCache
NewInstanceCache creates a cache with the default 5-second TTL.
func (*InstanceCache) Clear ¶ added in v0.0.15
func (c *InstanceCache) Clear()
Clear discards the cached data so the next call reads from disk again.
func (*InstanceCache) Get ¶ added in v0.0.15
func (c *InstanceCache) Get() ([]Instance, bool)
Get returns a shallow copy of the cached instances if they are still valid. The second return value reports whether the cache hit.
func (*InstanceCache) Set ¶ added in v0.0.15
func (c *InstanceCache) Set(instances []Instance)
Set stores a copy of the given instances and refreshes the timestamp.