agent

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentEvent

type AgentEvent struct {
	Type      EventType
	Timestamp time.Time

	// Init fields
	Model     string
	SessionID string

	// Thinking / Text fields
	Text string

	// ToolUse fields
	ToolName  string
	ToolInput map[string]any

	// ToolResult fields
	Stdout  string
	Stderr  string
	IsError bool

	// Complete fields
	Result  string
	CostUSD float64
	Usage   Usage
}

AgentEvent is a parsed event from the agent's output stream.

type Bridge

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

Bridge manages the agent subprocess and pipes its output to a parser.

func NewBridge

func NewBridge(agentName string, prompt string) (*Bridge, error)

NewBridge creates a bridge for the given agent command. For Claude Code, it uses --print --output-format stream-json.

func (*Bridge) Kill

func (b *Bridge) Kill() error

Kill forcefully terminates the agent process.

func (*Bridge) Pause

func (b *Bridge) Pause() error

Pause sends SIGSTOP to the agent process.

func (*Bridge) Resume

func (b *Bridge) Resume() error

Resume sends SIGCONT to the agent process.

func (*Bridge) Run

func (b *Bridge) Run(ctx context.Context, events chan<- AgentEvent) error

Run starts the agent process and parses its output, emitting events. It blocks until the process exits or the context is cancelled.

func (*Bridge) Signal

func (b *Bridge) Signal(sig os.Signal) error

Signal sends a signal to the agent process.

type ClaudeCodeParser

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

ClaudeCodeParser parses Claude Code's stream-json output format.

func NewClaudeCodeParser

func NewClaudeCodeParser(r io.Reader) *ClaudeCodeParser

NewClaudeCodeParser creates a parser that reads from the given reader.

func (*ClaudeCodeParser) Parse

func (p *ClaudeCodeParser) Parse(ctx context.Context, events chan<- AgentEvent) error

Parse reads JSON lines from the reader and emits AgentEvents.

type EventType

type EventType int

EventType represents the type of agent event.

const (
	EventInit       EventType = iota // session initialization
	EventThinking                    // agent reasoning/planning
	EventText                        // agent text output
	EventToolUse                     // tool invocation (file edit, command, etc.)
	EventToolResult                  // tool execution result
	EventComplete                    // task finished
	EventError                       // error occurred
)

func (EventType) String

func (e EventType) String() string

type Parser

type Parser interface {
	// Parse reads from the agent process and emits events on the channel.
	// It blocks until the agent exits or the context is cancelled.
	Parse(ctx context.Context, events chan<- AgentEvent) error
}

Parser parses agent output into structured events.

type Usage

type Usage struct {
	InputTokens  int
	OutputTokens int
}

Usage holds token usage data from the agent.

Jump to

Keyboard shortcuts

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