agents

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package agents spawns and controls Claude Code sessions Caprock owns: a real `claude` process in a PTY, its output buffered for the terminal view and its exit recorded. Externally started sessions are never touched here — we only spawn, type into, pause and kill processes we started (.ai/05-orchestration.md).

Index

Constants

This section is empty.

Variables

View Source
var ErrNotOwned = errors.New("session is not owned by caprock (observe-only)")

ErrNotOwned is returned for control operations on a session Caprock did not spawn.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	SessionID string
	Cwd       string
	Worktree  string
	Command   string
	StartedAt time.Time
	// contains filtered or unexported fields
}

Agent is a live owned session.

func (*Agent) Exited

func (a *Agent) Exited() (int, bool)

Exited reports the exit state.

func (*Agent) Paused

func (a *Agent) Paused() bool

Paused reports the pause state.

func (*Agent) Resize

func (a *Agent) Resize(cols, rows int) error

Resize the terminal.

func (*Agent) Signal

func (a *Agent) Signal(sig ptyman.Signal) error

Signal the process.

func (*Agent) Snapshot

func (a *Agent) Snapshot() []byte

Snapshot returns the current terminal scrollback (for a fresh terminal connect).

func (*Agent) Subscribe

func (a *Agent) Subscribe() (<-chan []byte, func())

Subscribe returns a channel of new output chunks and a cancel func. The channel is closed when the process exits.

func (*Agent) Write

func (a *Agent) Write(b []byte) error

Write types into the session.

type Manager

type Manager struct {
	OnExit   func(sessionID string, code int)
	OnOutput func(sessionID string) // called (throttled by caller) when new bytes arrive
	// NewSessionID generates a session id; overridable in tests.
	NewSessionID func() string
	// contains filtered or unexported fields
}

Manager owns the set of running agents.

func NewManager

func NewManager(st *store.Store, dataDir, claudePath string, log *slog.Logger) *Manager

NewManager builds a manager. claudePath "" resolves "claude" on PATH.

func (*Manager) ClaudeAvailable

func (m *Manager) ClaudeAvailable() bool

ClaudeAvailable reports whether the resolved claude binary can be launched.

func (*Manager) Get

func (m *Manager) Get(sessionID string) (*Agent, bool)

Get returns a running agent.

func (*Manager) Input

func (m *Manager) Input(sessionID string, data []byte) error

Input writes typed bytes to an owned session.

func (*Manager) List

func (m *Manager) List() []*Agent

List returns running agents.

func (*Manager) Resize

func (m *Manager) Resize(sessionID string, cols, rows int) error

Resize an owned session's terminal.

func (*Manager) Shutdown

func (m *Manager) Shutdown()

Shutdown kills every owned session (daemon stopping).

func (*Manager) Signal

func (m *Manager) Signal(sessionID string, sig ptyman.Signal) error

Signal pauses/resumes/kills an owned session.

func (*Manager) Spawn

func (m *Manager) Spawn(ctx context.Context, req SpawnRequest) (*Agent, error)

Spawn launches a new session and registers it. The PTY session id is forced with `claude --session-id <uuid>` so hooks and transcript arrive under the id Caprock already knows.

type SpawnRequest

type SpawnRequest struct {
	Cwd            string   `json:"cwd"`
	Worktree       string   `json:"worktree,omitempty"`        // git worktree name to create under the repo
	Model          string   `json:"model,omitempty"`           // --model
	PermissionMode string   `json:"permission_mode,omitempty"` // --permission-mode
	Command        string   `json:"command,omitempty"`         // default "claude"
	Args           []string `json:"args,omitempty"`            // extra args
	Cols           int      `json:"cols,omitempty"`
	Rows           int      `json:"rows,omitempty"`
}

SpawnRequest describes a session to launch.

Jump to

Keyboard shortcuts

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