daemon

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorCodeNotFound           = "not_found"
	ErrorCodeAmbiguous          = "ambiguous"
	ErrorCodeWorktreeDirty      = "worktree_dirty"
	ErrorCodeBranchCheckedOut   = "branch_checked_out"
	ErrorCodeBranchNotMerged    = "branch_not_merged"
	ErrorCodeBranchNotFound     = "branch_not_found"
	ErrorCodeAgentStillRunning  = "agent_still_running"
	ErrorCodeNotWorktreeAgent   = "not_worktree_agent"
	ErrorCodeWorktreeRequireSep = "worktree_requires_slash"
)

Error code constants used on the wire.

Variables

This section is empty.

Functions

func AgentList

func AgentList(workDir string) ([]agent.Record, error)

AgentList sends GET /agents/list to the daemon.

func AgentLogs

func AgentLogs(workDir, name string, lines int) (string, error)

AgentLogs sends GET /agents/{name}/logs?lines=N to the daemon. Pass lines<=0 to request the default tail. On resolve failures it returns typed *agent.ErrNotFound or *agent.ErrAmbiguous.

func AgentPrune added in v0.2.1

func AgentPrune(workDir, name string, req AgentPruneRequest) error

AgentPrune sends POST /agents/{name}/prune to the daemon. On typed failures (ErrWorktreeDirty, ErrBranchNotMerged, ErrAgentStillRunning, ...) it returns a wrapped error that callers can match with errors.Is.

func AgentSession

func AgentSession(workDir, name string) (string, error)

AgentSession sends GET /agents/{name}/session to the daemon, returning the tmux session name. The `name` may be a shorthand query; the server resolves it before responding. On resolve failures it returns typed *agent.ErrNotFound or *agent.ErrAmbiguous.

func AgentSpawn

func AgentSpawn(workDir string, req AgentSpawnRequest) (agent.Record, error)

AgentSpawn sends POST /agents/spawn to the daemon and returns the new record.

func AgentStop

func AgentStop(workDir, name string) error

AgentStop sends POST /agents/{name}/stop to the daemon. On resolve failures it returns typed *agent.ErrNotFound or *agent.ErrAmbiguous so callers can branch with errors.As.

func IsRunning

func IsRunning(workDir string) bool

IsRunning checks if a daemon is listening on the workspace socket.

func SockPath

func SockPath(workDir string) string

SockPath returns the daemon socket path for a workspace.

Types

type AgentLogsResponse

type AgentLogsResponse struct {
	Output string `json:"output"`
}

AgentLogsResponse is the payload for GET /agents/{name}/logs.

type AgentManager

type AgentManager interface {
	Spawn(ctx context.Context, spec agent.SpawnSpec) (agent.Record, error)
	Stop(name string) error
	Prune(ctx context.Context, name string, opts agent.PruneOptions) error
	List() []agent.Record
	Logs(name string, lines int) (string, error)
	SessionName(name string) string
	Resolve(query string) (agent.Record, error)
}

AgentManager is the interface daemon socket handlers use to drive the agent lifecycle. It is satisfied by *agent.Manager.

type AgentPruneRequest added in v0.2.1

type AgentPruneRequest struct {
	// Force lifts the dirty-worktree and unmerged-branch safety checks.
	Force bool `json:"force,omitempty"`
	// DeleteBranch removes the local branch after the worktree is gone.
	DeleteBranch bool `json:"delete_branch,omitempty"`
}

AgentPruneRequest is the body for POST /agents/{name}/prune. Prune is a no-op on shared-workspace agents; it removes the on-disk worktree and agentstore record for worktree agents that have already been stopped.

type AgentResolveResponse added in v0.2.1

type AgentResolveResponse struct {
	Name    string `json:"name"`
	Session string `json:"session"`
	Repo    string `json:"repo,omitempty"`
}

AgentResolveResponse is the payload for GET /agents/resolve?q=<query>.

func AgentResolve added in v0.2.1

func AgentResolve(workDir, query string) (AgentResolveResponse, error)

AgentResolve asks the daemon to resolve a shorthand query to the canonical agent and returns the hydrated record (name, session, repo). Used by remote clients that need to confirm an agent exists before acting on it. On resolve failures it returns typed *agent.ErrNotFound or *agent.ErrAmbiguous.

type AgentSessionResponse

type AgentSessionResponse struct {
	Session string `json:"session"`
	Name    string `json:"name"`
}

AgentSessionResponse is the payload for GET /agents/{name}/session. Name is the canonical agent name the query resolved to; may differ from the request path when the server accepts shorthand. Always populated so clients can distinguish "resolved to empty" from "field not sent by old server".

type AgentSpawnRequest

type AgentSpawnRequest struct {
	Template string `json:"template"`
	Repo     string `json:"repo"`
	Name     string `json:"name,omitempty"`
	// Branch opts into a dedicated git worktree on this branch. Requires an
	// owner/repo Repo. When empty, the agent uses today's shared workspace.
	Branch string `json:"branch,omitempty"`
	// Base is the ref used to create Branch when it does not already exist.
	// Ignored when Branch already exists locally or on origin. Defaults to the
	// repository's default branch.
	Base string `json:"base,omitempty"`
}

AgentSpawnRequest is the body for POST /agents/spawn.

type AgentSpawnSpec

type AgentSpawnSpec = agent.SpawnRequest

AgentSpawnSpec is retained as an alias to agent.SpawnRequest for backwards compatibility with call sites; new code should use agent.SpawnRequest directly.

type ProcessStateInfo

type ProcessStateInfo = agent.ProcessState

ProcessStateInfo is the daemon-facing view of a process state. Aliased to agent.ProcessState so the agent package, daemon, and service all agree on a single struct without import cycles.

type ProcessStateProvider

type ProcessStateProvider interface {
	States() map[string]ProcessStateInfo
}

ProcessStateProvider returns the state of all supervised processes. This is implemented by service.Supervisor.

type Response

type Response struct {
	OK      bool            `json:"ok"`
	Data    json.RawMessage `json:"data,omitempty"`
	Error   string          `json:"error,omitempty"`
	Code    string          `json:"code,omitempty"`
	Matches []string        `json:"matches,omitempty"`
}

Response is the standard envelope for all daemon API responses. Code is an optional machine-readable classifier for failures (e.g. "not_found", "ambiguous") so clients can reconstruct typed errors without string-matching. Matches is populated alongside Code="ambiguous".

func Send

func Send(workDir, method, path string, body any) (*Response, error)

Send sends a request to the daemon and returns the response.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an HTTP server listening on a Unix socket for daemon IPC.

func New

func New(sockPath, configPath string, processes ProcessStateProvider) *Server

New creates a new daemon server. The processes provider is optional (may be nil).

func (*Server) ReloadConfig

func (s *Server) ReloadConfig() error

ReloadConfig reloads config from disk and re-syncs the scheduler. Implements web.ConfigReloader.

func (*Server) SetAgentManager

func (s *Server) SetAgentManager(m AgentManager)

SetAgentManager attaches an agent manager. Must be called before any /agents/* request is served; otherwise those endpoints return 503.

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown gracefully stops the server and removes the socket file.

func (*Server) SockPath

func (s *Server) SockPath() string

SockPath returns the path to the Unix socket.

func (*Server) Start

func (s *Server) Start() error

Start binds the Unix socket and begins serving requests.

func (*Server) StartWeb

func (s *Server) StartWeb(cfg *config.Config, agentSvc web.AgentService) error

StartWeb starts the web UI on a TCP listener if web is enabled in config. agentSvc is the high-level agent.Manager used by web and daemon handlers; it may be nil to disable agent UI features.

Before serving any request the web package mints (or loads) a bearer token at <state>/api.token, used to gate /api/* routes. The file is user-only (0600) and readable by plugins running as the same Unix user.

type TaskAddRequest

type TaskAddRequest struct {
	Name         string   `json:"name"`
	Schedule     string   `json:"schedule"`
	PromptFile   string   `json:"prompt_file"`
	Model        string   `json:"model,omitempty"`
	MaxTurns     int      `json:"max_turns,omitempty"`
	Channels     []string `json:"channels,omitempty"`
	NotifyOnFail bool     `json:"notify_on_fail,omitempty"`
	Silent       bool     `json:"silent,omitempty"`
	Enabled      bool     `json:"enabled"`
}

TaskAddRequest is the body for POST /task/add.

type TaskNameRequest

type TaskNameRequest struct {
	Name string `json:"name"`
}

TaskNameRequest is the body for POST /task/remove, /task/enable, /task/disable.

Jump to

Keyboard shortcuts

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