fleet

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrStillRunning = errors.New("still running")

ErrStillRunning is returned by Wait when the timeout passes first.

Functions

func LoadAgents

func LoadAgents(home string) (map[string]Agent, error)

LoadAgents returns the built-in agents overlaid with ~/.fleet/agents.json.

func Root

func Root(home string) string

Root returns ~/.fleet.

func SocketPath

func SocketPath(home string) string

SocketPath returns the daemon's unix socket path.

Types

type Agent

type Agent struct {
	Argv []string `json:"argv"`
	Env  []string `json:"env,omitempty"`
	// Bare agents have no tools; cwd is irrelevant and the brief must carry everything.
	Bare bool `json:"bare,omitempty"`
}

Agent describes how to launch one ACP agent process.

type Client

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

Client talks to the daemon over its unix socket, starting it when absent.

func NewClient

func NewClient(home string) *Client

NewClient returns a client for the daemon under home.

func (*Client) Ensure

func (c *Client) Ensure(ctx context.Context) error

Ensure makes sure a daemon is answering, launching `fleet serve` detached if not.

func (*Client) Log

func (c *Client) Log(ctx context.Context, id string, tail int) (string, error)

Log returns the last events of a worker.

func (*Client) Ls

func (c *Client) Ls(ctx context.Context, all bool) (string, error)

Ls lists workers.

func (*Client) Result

func (c *Client) Result(ctx context.Context, id, turn string) (string, error)

Result returns a worker's reply text and footer. turn selects the reply: empty or "0" for the latest turn (live while running), a turn number for an earlier one, or "all" for every turn concatenated.

func (*Client) Say

func (c *Client) Say(ctx context.Context, id, message string) (string, error)

Say sends a follow-up to a worker.

func (*Client) Spawn

func (c *Client) Spawn(ctx context.Context, spec Spec) (string, error)

Spawn starts a worker and returns its first status lines.

func (*Client) Statuses

func (c *Client) Statuses(ctx context.Context) ([]Status, error)

Statuses returns the machine-readable snapshot of live workers.

func (*Client) Stop

func (c *Client) Stop(ctx context.Context, id string) (string, error)

Stop ends a worker.

func (*Client) Wait

func (c *Client) Wait(ctx context.Context, id string, timeout time.Duration) (string, error)

Wait blocks until the worker is final or timeout passes, returning its ls entry.

func (*Client) WaitOnce

func (c *Client) WaitOnce(ctx context.Context, id string, seconds int) (entry string, final bool, err error)

WaitOnce issues one long poll against the wait endpoint: final is true when the worker reached a final state within seconds. The body is the ls entry.

func (*Client) Watch

func (c *Client) Watch(ctx context.Context, ids []string, timeout time.Duration, out io.Writer) error

Watch prints one line per state change or flag until every watched worker is final or timeout passes. With no ids it watches every worker live at start.

type Daemon

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

Daemon owns the live workers and serves them over a unix socket.

func NewDaemon

func NewDaemon(home string, logger *slog.Logger) (*Daemon, error)

NewDaemon loads agent definitions and the metadata of past workers, then reattaches every worker whose host process outlived the previous daemon.

func (*Daemon) Ls

func (d *Daemon) Ls(all bool, only string) string

Ls renders one entry per worker: live ones always, finished ones with all.

func (*Daemon) Serve

func (d *Daemon) Serve(ctx context.Context) error

Serve listens on the unix socket until ctx is cancelled.

func (*Daemon) Spawn

func (d *Daemon) Spawn(ctx context.Context, spec Spec) (string, error)

Spawn validates the spec and starts a worker.

func (*Daemon) Statuses

func (d *Daemon) Statuses() []Status

Statuses snapshots every live worker.

type Meta

type Meta struct {
	ID        string     `json:"id"`
	Spec      Spec       `json:"spec"`
	Started   time.Time  `json:"started"`
	SessionID string     `json:"session_id,omitempty"`
	PID       int        `json:"pid,omitempty"`
	State     State      `json:"state"`
	Detail    string     `json:"detail,omitempty"`
	Turns     int        `json:"turns"`
	TurnLog   []TurnInfo `json:"turn_log,omitempty"`
	Usage     Usage      `json:"usage"`
	// ContextUsed and ContextSize are the agent's latest reported context
	// window fill in tokens; CostUSD is the latest reported session cost.
	ContextUsed int64     `json:"context_used,omitempty"`
	ContextSize int64     `json:"context_size,omitempty"`
	CostUSD     float64   `json:"cost_usd,omitempty"`
	Ended       time.Time `json:"ended,omitempty"`
	// Restart survival: AckSeq is the host stream position handled so far,
	// NextRPCID keeps request ids unique across reattaches, and TurnCallID
	// with TurnDeadline describe the in-flight prompt call to resume.
	AckSeq       int64     `json:"ack_seq,omitempty"`
	NextRPCID    int64     `json:"next_rpc_id,omitempty"`
	TurnCallID   int64     `json:"turn_call_id,omitempty"`
	TurnDeadline time.Time `json:"turn_deadline,omitempty"`
}

Meta is the persisted description of a worker.

type Now

type Now struct {
	Line string
	Flag string
}

Now describes what the worker is doing, plus any flag.

type Spec

type Spec struct {
	Agent    string `json:"agent"`
	Model    string `json:"model"`
	Thinking string `json:"thinking"`
	Cwd      string `json:"cwd"`
	Label    string `json:"label"`
	Brief    string `json:"brief"`
	Writes   bool   `json:"writes"`
	Minutes  int    `json:"minutes"`
}

Spec is what a caller asks for when spawning a worker.

type State

type State string

State is a worker's lifecycle state.

const (
	StateStarting State = "STARTING"
	StateRunning  State = "RUNNING"
	StateDone     State = "DONE"
	StateTimeout  State = "TIMEOUT"
	StateStopped  State = "STOPPED"
	StateFailed   State = "FAILED"
	StateQuota    State = "QUOTA"
)

func (State) Terminal

func (s State) Terminal() bool

Terminal reports whether the state can no longer change on its own.

type Status

type Status struct {
	ID    string `json:"id"`
	State State  `json:"state"`
	Flag  string `json:"flag,omitempty"`
	Label string `json:"label"`
	Line  string `json:"line"`
	Entry string `json:"entry"`
}

Status is the machine-readable form of one ls entry.

type TurnInfo

type TurnInfo struct {
	State State `json:"state"`
	Chars int   `json:"chars"`
}

TurnInfo records how one turn ended so past turns stay listable after the in-memory text of earlier turns is gone.

type Usage

type Usage struct {
	Input      int64 `json:"input"`
	CachedRead int64 `json:"cached_read"`
	Output     int64 `json:"output"`
}

Usage is cumulative token usage across turns.

type Worker

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

Worker owns one ACP agent session, reached through the worker's host.

func (*Worker) Meta

func (w *Worker) Meta() Meta

Meta returns a snapshot of the persisted description.

func (*Worker) Result

func (w *Worker) Result() string

Result returns the text of the latest turn.

func (*Worker) ResultTurn

func (w *Worker) ResultTurn(turn string) (string, error)

ResultTurn returns one turn's reply text. An empty turn, "0", or the number of the latest turn gives the live text; "all" concatenates every turn; any other number reads that turn's saved reply.

func (*Worker) Say

func (w *Worker) Say(text string) (string, error)

Say queues a follow-up prompt on the same session. It runs at once when the worker is idle, or after the current turn ends.

func (*Worker) Stop

func (w *Worker) Stop()

Stop cancels the current turn and ends the process.

func (*Worker) TurnsLine

func (w *Worker) TurnsLine() string

TurnsLine lists every turn with its end state and reply size for the result footer. The latest turn reports live values until it ends.

Jump to

Keyboard shortcuts

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