agent

package
v0.30.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "dev"

Version is set at build time via -ldflags.

Functions

func BridgeTerminalStream added in v0.27.0

func BridgeTerminalStream(stream net.Conn, p *ClaudeCodePTY)

BridgeTerminalStream bridges a yamux terminal stream to a PTY.

Protocol on the stream:

  • Prefix 0x00 + data: terminal I/O bytes
  • Prefix 0x01 + JSON: control commands (resize, etc.)

func DefaultRegistryDir added in v0.20.0

func DefaultRegistryDir() string

DefaultRegistryDir returns the default directory for agentserver config.

func DefaultRegistryPath added in v0.20.0

func DefaultRegistryPath() string

DefaultRegistryPath returns the default path for the registry file.

func RegisterDefaultCard added in v0.30.1

func RegisterDefaultCard(serverURL, proxyToken, displayName string) error

RegisterDefaultCard registers a default agent card for a claudecode agent.

func RunClaudeCode added in v0.27.0

func RunClaudeCode(opts ClaudeCodeOptions)

RunClaudeCode executes the Claude Code agent connect workflow. It registers with the server (or loads saved credentials), then establishes a tunnel and bridges terminal streams to a local Claude Code PTY.

func RunConnect added in v0.6.1

func RunConnect(opts ConnectOptions)

RunConnect executes the agent connect workflow.

func RunTaskWorker added in v0.30.0

func RunTaskWorker(ctx context.Context, opts TaskWorkerOptions)

RunTaskWorker starts the task worker that polls for tasks. Blocks until ctx is cancelled.

func SaveRegistry added in v0.20.0

func SaveRegistry(path string, reg *Registry) error

SaveRegistry writes the registry to disk.

Types

type AgentInfoData added in v0.16.0

type AgentInfoData struct {
	Hostname        string                 `json:"hostname"`
	OS              string                 `json:"os"`
	Platform        string                 `json:"platform"`
	PlatformVersion string                 `json:"platform_version"`
	KernelArch      string                 `json:"kernel_arch"`
	CPUModelName    string                 `json:"cpu_model_name"`
	CPUCountLogical int                    `json:"cpu_count_logical"`
	MemoryTotal     uint64                 `json:"memory_total"`
	DiskTotal       uint64                 `json:"disk_total"`
	DiskFree        uint64                 `json:"disk_free"`
	AgentVersion    string                 `json:"agent_version"`
	OpencodeVersion string                 `json:"opencode_version"`
	Workdir         string                 `json:"workdir"`
	HostInfo        *host.InfoStat         `json:"host_info,omitempty"`
	CPUInfo         *cpuInfoDetail         `json:"cpu_info,omitempty"`
	MemoryInfo      *mem.VirtualMemoryStat `json:"memory_info,omitempty"`
	DiskInfo        *disk.UsageStat        `json:"disk_info,omitempty"`
}

AgentInfoData is the system info payload sent from agent to server.

type ClaudeCodeOptions added in v0.27.0

type ClaudeCodeOptions struct {
	Server    string
	Code      string
	Name      string
	ClaudeBin string
	WorkDir   string
}

ClaudeCodeOptions holds all flags for the claudecode command.

type ClaudeCodePTY added in v0.27.0

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

ClaudeCodePTY manages a Claude Code process running inside a pseudo-terminal.

func NewClaudeCodePTY added in v0.27.0

func NewClaudeCodePTY(claudeBin, workDir string, cols, rows uint16) (*ClaudeCodePTY, error)

NewClaudeCodePTY starts a Claude Code process in a PTY.

func (*ClaudeCodePTY) Close added in v0.27.0

func (p *ClaudeCodePTY) Close() error

Close terminates the process and closes the PTY.

func (*ClaudeCodePTY) IsAlive added in v0.27.0

func (p *ClaudeCodePTY) IsAlive() bool

IsAlive reports whether the underlying process is still running.

func (*ClaudeCodePTY) Read added in v0.27.0

func (p *ClaudeCodePTY) Read(b []byte) (int, error)

func (*ClaudeCodePTY) Resize added in v0.27.0

func (p *ClaudeCodePTY) Resize(cols, rows uint16) error

Resize changes the PTY window size.

func (*ClaudeCodePTY) Write added in v0.27.0

func (p *ClaudeCodePTY) Write(b []byte) (int, error)

type Client

type Client struct {
	ServerURL     string
	SandboxID     string
	TunnelToken   string
	OpencodeURL   string // local HTTP service URL (e.g. http://localhost:4096)
	OpencodeToken string // optional Basic Auth password for opencode
	Workdir       string
	BackendType   string // "opencode" or "claudecode"

	// OnTerminalStream is called when the server opens a terminal stream.
	// Implementations should bridge the stream to a PTY.
	// If nil, terminal streams are rejected.
	OnTerminalStream func(stream net.Conn)
	// contains filtered or unexported fields
}

Client is the cli-agent tunnel client that connects to the server and forwards HTTP/terminal requests to a local service.

func NewClient

func NewClient(serverURL, sandboxID, tunnelToken, opencodeURL, opencodeToken, workdir string) *Client

NewClient creates a new agent tunnel client.

func (*Client) Run

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

Run connects to the server and enters the tunnel event loop. It automatically reconnects with exponential backoff on disconnection.

type ConnectOptions added in v0.6.1

type ConnectOptions struct {
	Server          string
	Code            string
	Name            string
	WorkspaceID     string // optional: disambiguate when dir has multiple workspaces
	OpencodeURL     string
	OpencodeURLSet  bool // true if --opencode-url was explicitly provided
	OpencodeToken   string
	AutoStart       bool
	OpencodeBin     string
	OpencodePort    int  // 0 = auto-assign from registry
	OpencodePortSet bool // true if --opencode-port was explicitly provided
}

ConnectOptions holds all flags for the connect command.

type LockedRegistryFile added in v0.20.0

type LockedRegistryFile struct {
	Path string
	Reg  *Registry
	// contains filtered or unexported fields
}

LockedRegistryFile holds an exclusive lock on the registry for safe read-modify-write operations. Call Close() when done.

func LockRegistry added in v0.20.0

func LockRegistry(path string) (*LockedRegistryFile, error)

LockRegistry acquires an exclusive file lock and loads the registry. The caller must call Close() when done to release the lock and optionally save changes via Save() before Close().

func (*LockedRegistryFile) Close added in v0.20.0

func (l *LockedRegistryFile) Close()

Close releases the file lock.

func (*LockedRegistryFile) Save added in v0.20.0

func (l *LockedRegistryFile) Save() error

Save writes the registry to disk while the lock is held.

type OpencodeProcess

type OpencodeProcess struct {
	Port int
	// contains filtered or unexported fields
}

OpencodeProcess manages a local opencode serve subprocess.

func StartOpencode

func StartOpencode(bin string, port int, password string) (*OpencodeProcess, error)

StartOpencode starts "opencode serve --hostname 127.0.0.1 --port {port}" as a child process. It returns immediately after starting the process.

func (*OpencodeProcess) Stop

func (p *OpencodeProcess) Stop()

Stop sends SIGTERM to the child process, waits briefly, then sends SIGKILL if needed.

func (*OpencodeProcess) WaitReady

func (p *OpencodeProcess) WaitReady(ctx context.Context, timeout time.Duration) error

WaitReady polls http://localhost:{port}/ every 500ms until a response is received or the timeout expires.

type Registry added in v0.20.0

type Registry struct {
	Entries []*RegistryEntry `json:"entries"`
}

Registry holds all agent registrations on this machine.

func LoadRegistry added in v0.20.0

func LoadRegistry(path string) (*Registry, error)

LoadRegistry reads the registry from disk. Returns an empty registry if the file does not exist.

func (*Registry) Find added in v0.20.0

func (r *Registry) Find(dir, workspaceID string) *RegistryEntry

Find returns the entry matching (dir, workspaceID), or nil if not found.

func (*Registry) FindByDir added in v0.20.0

func (r *Registry) FindByDir(dir string) []*RegistryEntry

FindByDir returns all entries for the given directory.

func (*Registry) NextPort added in v0.20.0

func (r *Registry) NextPort() int

NextPort returns the lowest available port starting from basePort. It finds the first gap in the used port range to reuse freed ports.

func (*Registry) Put added in v0.20.0

func (r *Registry) Put(entry *RegistryEntry)

Put adds or replaces an entry keyed by (Dir, WorkspaceID).

func (*Registry) Remove added in v0.20.0

func (r *Registry) Remove(dir, workspaceID string) bool

Remove deletes the entry matching (dir, workspaceID). Returns true if an entry was removed, false if not found.

type RegistryEntry added in v0.20.0

type RegistryEntry struct {
	Dir          string `json:"dir"`
	Server       string `json:"server"`
	SandboxID    string `json:"sandbox_id"`
	TunnelToken  string `json:"tunnel_token"`
	WorkspaceID  string `json:"workspace_id"`
	Name         string `json:"name"`
	Type         string `json:"type,omitempty"` // "opencode" or "claudecode"
	OpencodePort int    `json:"opencode_port,omitempty"`
}

RegistryEntry represents a single agent registration keyed by (Dir, WorkspaceID).

func Register

func Register(serverURL, code, name, agentType string) (*RegistryEntry, error)

Register registers a new local agent with the server using a one-time code.

type TaskWorker added in v0.30.0

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

TaskWorker receives and executes delegated tasks using the Go Agent SDK.

func NewTaskWorker added in v0.30.0

func NewTaskWorker(opts TaskWorkerOptions) *TaskWorker

func (*TaskWorker) ExecuteTask added in v0.30.0

func (w *TaskWorker) ExecuteTask(ctx context.Context, taskID, prompt, systemContext string, maxTurns int, maxBudgetUSD float64) error

ExecuteTask runs a single task: creates session, connects bridge, executes via Agent SDK.

type TaskWorkerOptions added in v0.30.0

type TaskWorkerOptions struct {
	ServerURL  string // agentserver base URL (e.g. https://agentserver.example.com)
	ProxyToken string // sandbox proxy_token for auth
	SandboxID  string // this agent's sandbox ID
	Workdir    string // working directory for claude CLI
	CLIPath    string // path to claude binary (default: "claude")
}

TaskWorkerOptions configures the task worker.

Jump to

Keyboard shortcuts

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