Documentation
¶
Index ¶
- func IsRunning(workdir string) (bool, int)
- func LogPath(workdir string) string
- func PIDPath(workdir string) string
- func ReadPID(workdir string) int
- func RemovePID(workdir string) error
- func StatePath(workdir string) string
- func Stop(workdir string) error
- func WritePID(workdir string, pid int) error
- type Agent
- type AgentConfig
- type State
- type StepLog
- type Tool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsRunning ¶
IsRunning returns true if the daemon is alive (PID exists and process is reachable).
func RemovePID ¶
RemovePID removes the PID file (called by worker on exit). Returns the underlying os.Remove error so callers can log a true failure (perms, busy filesystem) — a stale PID file blocks the next `agent start` because IsRunning() will see it and assume the prior worker is alive. ENOENT is expected when the file was already removed (e.g. by Stop) and is returned untouched so callers can filter with os.IsNotExist.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent drives a ReAct (Reason + Act) loop to accomplish a goal using tools.
func New ¶
func New(cfg AgentConfig) *Agent
New creates a new Agent with the built-in tool set registered.
type AgentConfig ¶
type AgentConfig struct {
Provider provider.Provider
Model string
Timeout time.Duration
DryRun bool
WorkDir string
}
Config holds configuration for creating a new Agent.
type State ¶
type State struct {
PID int `json:"pid"`
StartedAt time.Time `json:"started_at"`
LastRunAt time.Time `json:"last_run_at,omitempty"`
NextRunAt time.Time `json:"next_run_at,omitempty"`
RunCount int `json:"run_count"`
TotalTasksCompleted int `json:"total_tasks_completed"`
TotalTasksFailed int `json:"total_tasks_failed"`
Status string `json:"status"` // starting, idle, running, stopped
Interval string `json:"interval"`
Provider string `json:"provider,omitempty"`
Model string `json:"model,omitempty"`
LastError string `json:"last_error,omitempty"`
}
State tracks the daemon's runtime status, persisted to .cloop/agent.json.
func Load ¶
Load reads the agent state from disk; returns nil if not found.
On parse failure (zero-byte file from a torn pre-atomicfile write, schema drift, manual edit gone wrong) the corrupt file is quarantined aside as agent.json.corrupt-<unix> and (nil, nil) is returned. Losing run counters is preferable to refusing to start the daemon — and the user has the bytes preserved next to the original location for forensics.
func (*State) Save ¶
Save writes the agent state to disk atomically.
A torn write of agent.json (crash mid-write, ENOSPC) would corrupt the JSON; `Load` would then return an error and `cloop agent status` / the daemon itself would refuse to read its own counters. The write also runs under stateMu so two daemon goroutines saving in parallel can't interleave their MarshalIndent buffers.