agent

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package agent manages Claude Code agent lifecycle: spawning, stopping, listing, attaching, and resuming background tmux sessions in devcontainers.

Index

Constants

View Source
const ContainerPrefix = "human-agent-"

ContainerPrefix is prepended to all managed agent container names.

Variables

This section is empty.

Functions

func AgentsDir

func AgentsDir() string

AgentsDir returns the directory where agent metadata is stored. Falls back to ./.human/agents/ when the home directory is unknown.

func ContainerName

func ContainerName(name string) string

ContainerName returns the Docker container name for an agent.

func DeleteMeta

func DeleteMeta(name string) error

DeleteMeta removes the agent metadata file from disk.

func FetchTicketPrompt

func FetchTicketPrompt(ctx context.Context, key string, instances []tracker.Instance) (string, error)

FetchTicketPrompt loads the ticket identified by key from the configured tracker instances and formats its content as a prompt string suitable for sending to Claude Code.

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration returns a human-readable duration string. Examples: "2m", "1h30m", "3d12h".

func MetaPath

func MetaPath(name string) string

MetaPath returns the file path for the given agent's metadata JSON.

func WriteMeta

func WriteMeta(m Meta) error

WriteMeta persists agent metadata to disk as indented JSON with restricted file permissions (0600).

Types

type Manager

type Manager struct {
	Docker devcontainer.DockerClient
}

Manager orchestrates agent lifecycle using devcontainers.

func (*Manager) Attach

func (m *Manager) Attach(_ context.Context, name string) (Meta, error)

Attach returns the container name for docker exec -it.

func (*Manager) BuildClaudeArgs

func (m *Manager) BuildClaudeArgs(opts StartOpts) []string

BuildClaudeArgs constructs Claude Code CLI arguments.

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, name string) error

Delete stops the container and deletes the agent metadata so no trace remains. Best-effort: always deletes metadata even if container cleanup fails. The whole sequence holds the per-name lock so a concurrent Stop cannot re-create the metadata file after DeleteMeta removes it.

func (*Manager) Refresh

func (m *Manager) Refresh(ctx context.Context) error

Refresh syncs metadata with actual container state.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context, opts StartOpts) (Meta, error)

Start creates a new container-based agent.

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context, name string) error

Stop stops and removes an agent's container.

type Meta

type Meta struct {
	Name          string    `json:"name"`
	ContainerID   string    `json:"container_id"`
	ContainerName string    `json:"container_name"`
	Cwd           string    `json:"cwd"`
	Prompt        string    `json:"prompt,omitempty"`
	Status        Status    `json:"status"`
	CreatedAt     time.Time `json:"created_at"`
	StoppedAt     time.Time `json:"stopped_at,omitempty"`
	SkipPerms     bool      `json:"skip_perms,omitempty"`
	Model         string    `json:"model,omitempty"`
	ConfigDir     string    `json:"config_dir,omitempty"`
	ImageName     string    `json:"image_name,omitempty"`
	RemoteUser    string    `json:"remote_user,omitempty"`
}

Meta holds the persisted metadata for a single agent.

func ListMetas

func ListMetas() ([]Meta, error)

ListMetas returns metadata for all agents, sorted by creation time (newest first).

func ReadMeta

func ReadMeta(name string) (Meta, error)

ReadMeta loads agent metadata from disk.

type StartOpts

type StartOpts struct {
	Name        string
	Prompt      string
	Model       string
	SkipPerms   bool
	ConfigDir   string // where .devcontainer/devcontainer.json lives (default: cwd)
	Workspace   string // directory to mount into container (default: cwd)
	Rebuild     bool
	Interactive bool // foreground TTY mode
}

StartOpts configures an agent start operation.

type Status

type Status string

Status represents the lifecycle state of an agent.

const (
	StatusRunning Status = "running"
	StatusStopped Status = "stopped"
	StatusFailed  Status = "failed"
)

Jump to

Keyboard shortcuts

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