client

package
v0.0.36 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = NewClient()

Functions

func ClearInstanceCache

func ClearInstanceCache()

ClearInstanceCache delegates to DefaultClient.ClearInstanceCache.

func IsProcessDead

func IsProcessDead(pid int) bool

IsProcessDead delegates to DefaultClient.IsProcessDead.

Types

type BatchCommandItem

type BatchCommandItem struct {
	Command string `json:"command"`
	Params  any    `json:"params,omitempty"`
}

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 BatchOptions struct {
	FailFast bool `json:"fail_fast"`
	Atomic   bool `json:"atomic"`
}

type Client added in v0.0.15

type Client struct {
	Debug bool
	// contains filtered or unexported fields
}

func NewClient added in v0.0.15

func NewClient() *Client

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

func (c *Client) DiscoverInstance(project string, port int) (*Instance, error)

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

func (c *Client) FindActiveByPort(port int) (*Instance, error)

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

func (c *Client) FindByPort(port int) (*Instance, error)

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

func (c *Client) IsProcessDead(pid int) bool

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

func (c *Client) ScanInstances() ([]Instance, error)

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) Send added in v0.0.15

func (c *Client) Send(inst *Instance, command string, params any, timeoutMs int) (*CommandResponse, error)

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 CommandRequest struct {
	Command string `json:"command"`
	Params  any    `json:"params"`
}

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"`
}

func Send

func Send(inst *Instance, command string, params any, timeoutMs int) (*CommandResponse, error)

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

func DiscoverInstance(project string, port int) (*Instance, error)

DiscoverInstance delegates to DefaultClient.DiscoverInstance.

func FindActiveByPort

func FindActiveByPort(port int) (*Instance, error)

FindActiveByPort delegates to DefaultClient.FindActiveByPort.

func FindByPort

func FindByPort(port int) (*Instance, error)

FindByPort delegates to DefaultClient.FindByPort.

func ScanInstances

func ScanInstances() ([]Instance, error)

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.

Jump to

Keyboard shortcuts

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