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 any, timeoutMs int) (*CommandResponse, error)
- func (c *Client) SendBatch(ctx context.Context, inst *Instance, req BatchCommandRequest, timeoutMs int) (*BatchCommandResponse, error)
- type CommandRequest
- type CommandResponse
- type CompilerInfo
- type Instance
- type InstanceCache
Constants ¶
This section is empty.
Variables ¶
var DefaultClient = NewClient()
Functions ¶
func ClearInstanceCache ¶
func ClearInstanceCache()
ClearInstanceCache delegates to DefaultClient.ClearInstanceCache.
func IsProcessDead ¶
IsProcessDead delegates to DefaultClient.IsProcessDead.
Types ¶
type BatchCommandItem ¶
type BatchCommandRequest ¶
type BatchCommandRequest struct {
Commands []BatchCommandItem `json:"commands"`
Options BatchOptions `json:"options"`
}
type BatchCommandResponse ¶
type BatchCommandResponse struct {
Results []CommandResponse `json:"results"`
Completed int `json:"completed"`
Failed int `json:"failed"`
}
func SendBatch ¶
func SendBatch(ctx context.Context, inst *Instance, req BatchCommandRequest, timeoutMs int) (*BatchCommandResponse, error)
type BatchOptions ¶
type Client ¶ added in v0.0.15
type Client struct {
Debug bool
// contains filtered or unexported fields
}
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, timeoutMs int) (*BatchCommandResponse, error)
type CommandRequest ¶
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"`
}
type CompilerInfo ¶ added in v0.0.33
type CompilerInfo struct {
CscPath string `json:"cscPath,omitempty"`
CscKind string `json:"cscKind,omitempty"`
CscFound bool `json:"cscFound,omitempty"`
DotnetPath string `json:"dotnetPath,omitempty"`
DotnetKind string `json:"dotnetKind,omitempty"`
DotnetFound bool `json:"dotnetFound,omitempty"`
Error string `json:"error,omitempty"`
}
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"`
DocsVersion string `json:"docsVersion,omitempty"`
Compiler *CompilerInfo `json:"compiler,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"`
CompileErrors bool `json:"compileErrors,omitempty"`
}
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.