claude

package
v0.56.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AgentStatusDone indicates the task completed successfully.
	AgentStatusDone = agentlib.AgentStatusDone
	// AgentStatusFailed indicates the task failed.
	AgentStatusFailed = agentlib.AgentStatusFailed
	// AgentStatusNeedsInput indicates the task requires additional user input.
	AgentStatusNeedsInput = agentlib.AgentStatusNeedsInput
)

Variables

This section is empty.

Functions

func BuildPrompt

func BuildPrompt(
	instructions string,
	envContext map[string]string,
	taskContent string,
) string

BuildPrompt combines instructions with environment context and task content.

func BuildResultSection

func BuildResultSection(result AgentResultLike) string

BuildResultSection renders the default ## Result markdown block for any AgentResultLike.

func NewAgentStep added in v0.54.0

func NewAgentStep(cfg AgentStepConfig) agentlib.Step

NewAgentStep wraps a single Claude invocation as an agentlib.Step.

Used by AI-heavy agents (trade-analysis, pr-reviewer style). The LLM reads the marshaled task content (frontmatter + body) and writes its output verbatim under the configured section heading.

For boundary parsing (markdown → typed Go struct), use agentlib.NewParseStep with an AIParser implementation instead.

func ParseKeyValuePairs added in v0.54.0

func ParseKeyValuePairs(raw string) map[string]string

ParseKeyValuePairs parses a comma-separated KEY1=VALUE1,KEY2=VALUE2 string into a map. Empty input returns nil. Pairs without '=' are silently skipped. Used by claude-agent main entry points to populate EnvContext (prompt template vars) and the Claude CLI process env from CLI flags / K8s Job env.

func PrintResult

func PrintResult(ctx context.Context, result AgentResult) error

PrintResult marshals an AgentResult to JSON and prints to stdout.

Types

type AgentDir

type AgentDir string

AgentDir is the path to the agent directory containing .claude/ config.

func (AgentDir) String

func (a AgentDir) String() string

String returns the path as a string.

type AgentResult

type AgentResult struct {
	Status    AgentStatus `json:"status"`
	Message   string      `json:"message,omitempty"`
	Files     []string    `json:"files,omitempty"`
	NextPhase string      `json:"next_phase,omitempty"`
}

AgentResult is the structured output written to stdout for the task/executor to read.

func (AgentResult) GetFiles added in v0.45.0

func (r AgentResult) GetFiles() []string

func (AgentResult) GetMessage added in v0.45.0

func (r AgentResult) GetMessage() string

func (AgentResult) GetNextPhase added in v0.53.2

func (r AgentResult) GetNextPhase() string

GetNextPhase returns the requested next task phase, or empty string for default behavior.

func (AgentResult) GetStatus added in v0.45.0

func (r AgentResult) GetStatus() AgentStatus

func (AgentResult) RenderResultSection added in v0.45.0

func (r AgentResult) RenderResultSection() string

type AgentResultLike added in v0.45.0

type AgentResultLike interface {
	GetStatus() AgentStatus
	GetMessage() string
	GetFiles() []string
	GetNextPhase() string
	RenderResultSection() string
}

AgentResultLike is the constraint for types that can be delivered as task results.

type AgentStatus

type AgentStatus = agentlib.AgentStatus

AgentStatus is the shared agent status type.

type AgentStepConfig added in v0.54.0

type AgentStepConfig struct {
	// Name is the step name for logs.
	Name string

	// Runner is the Claude CLI invocation backend (pre-configured with
	// AllowedTools, Model, ClaudeConfigDir via ClaudeRunnerConfig).
	Runner ClaudeRunner

	// Instructions is the system prompt for this step.
	Instructions Instructions

	// EnvContext is forwarded to the Claude CLI tool-invocation environment.
	EnvContext map[string]string

	// OutputSection is the body section heading for the LLM's output
	// (e.g. "## Analysis", "## Review").
	OutputSection string

	// NextPhase is the phase to advance to on success. Empty means
	// in-place save (multi-step phase intermediate).
	NextPhase string
}

AgentStepConfig bundles everything an agent Step needs at construction time.

The Runner is pre-configured with AllowedTools + Model via ClaudeRunnerConfig at construction; per-step Instructions + EnvContext are supplied here so a single Runner can serve multiple steps with different prompts.

type AllowedTools

type AllowedTools []string

AllowedTools is a list of tool names permitted in headless Claude sessions.

func ParseAllowedTools

func ParseAllowedTools(s string) AllowedTools

ParseAllowedTools parses a comma-separated string into AllowedTools.

func (AllowedTools) String

func (a AllowedTools) String() string

String returns the comma-separated tool list for the CLI --allowedTools flag.

type ClaudeConfigDir

type ClaudeConfigDir string

ClaudeConfigDir is the path to the Claude Code configuration directory (~/.claude).

func (ClaudeConfigDir) String

func (c ClaudeConfigDir) String() string

String returns the path as a string.

type ClaudeModel

type ClaudeModel string

ClaudeModel identifies which Claude model to use.

const (
	SonnetClaudeModel ClaudeModel = "sonnet"
	OpusClaudeModel   ClaudeModel = "opus"
)

func (ClaudeModel) String

func (c ClaudeModel) String() string

String returns the model name.

type ClaudeResult

type ClaudeResult struct {
	Result string `json:"result"`
}

ClaudeResult holds the parsed output from a Claude Code CLI session.

type ClaudeRunner

type ClaudeRunner interface {
	Run(ctx context.Context, prompt string) (*ClaudeResult, error)
}

ClaudeRunner spawns a headless Claude Code CLI session with a prompt and MCP tools.

func NewClaudeRunner

func NewClaudeRunner(config ClaudeRunnerConfig) ClaudeRunner

NewClaudeRunner creates a ClaudeRunner that spawns claude --print with MCP tools.

type ClaudeRunnerConfig

type ClaudeRunnerConfig struct {
	// ClaudeConfigDir overrides the Claude CLI config directory via CLAUDE_CONFIG_DIR.
	ClaudeConfigDir ClaudeConfigDir
	// AllowedTools is passed to claude --allowedTools to restrict tool access.
	AllowedTools AllowedTools
	// Model selects the Claude model (e.g. "sonnet", "opus").
	Model ClaudeModel
	// WorkingDirectory sets the CLI process working directory.
	WorkingDirectory AgentDir
	// Env holds extra KEY=VALUE entries appended to the subprocess environment
	// AFTER the allowlist filter (see allowlistEnv in claude-runner.go). This is
	// the escape hatch for passing through secrets or vars the allowlist would
	// otherwise strip (e.g. GH_TOKEN for gh CLI auth). Values here cross the
	// trust boundary into the Claude CLI subprocess — only add what the agent
	// genuinely needs.
	Env map[string]string
}

ClaudeRunnerConfig holds configuration for spawning Claude Code CLI.

type Instruction

type Instruction struct {
	Name    string
	Content string
}

Instruction is a named prompt section wrapped in XML tags.

func (Instruction) String

func (i Instruction) String() string

String renders the instruction as an XML-tagged block.

type Instructions

type Instructions []Instruction

Instructions is a list of named prompt sections.

func (Instructions) String

func (ii Instructions) String() string

String renders all instructions separated by newlines.

func (Instructions) Strings

func (ii Instructions) Strings() []string

Strings returns each instruction rendered as an XML-tagged string.

type PluginCommander added in v0.56.0

type PluginCommander interface {
	Run(ctx context.Context, name string, args ...string) (string, error)
}

PluginCommander runs an external command and returns its combined stdout.

func NewExecPluginCommander added in v0.56.0

func NewExecPluginCommander() PluginCommander

NewExecPluginCommander returns a PluginCommander that uses os/exec to run real processes.

type PluginInstaller added in v0.56.0

type PluginInstaller interface {
	EnsureInstalled(ctx context.Context, specs []PluginSpec) error
}

PluginInstaller ensures a list of Claude plugins are installed or updated.

func NewPluginInstaller added in v0.56.0

func NewPluginInstaller(commander PluginCommander) PluginInstaller

NewPluginInstaller returns a PluginInstaller that uses the given PluginCommander to manage Claude plugins.

type PluginSpec added in v0.56.0

type PluginSpec struct {
	Marketplace string // e.g. "bborbe/coding"
	Name        string // e.g. "coding"
}

PluginSpec identifies a Claude Code plugin to ensure is installed.

type ResultDeliverer

type ResultDeliverer[T AgentResultLike] interface {
	DeliverResult(ctx context.Context, result T) error
}

ResultDeliverer publishes a task result back after execution completes.

func NewNoopResultDeliverer

func NewNoopResultDeliverer() ResultDeliverer[AgentResult]

NewNoopResultDeliverer creates a ResultDeliverer[AgentResult] that does nothing.

func NewResultDelivererAdapter

func NewResultDelivererAdapter[T AgentResultLike](
	inner agentlib.ResultDeliverer,
) ResultDeliverer[T]

NewResultDelivererAdapter wraps a agentlib.ResultDeliverer to accept any AgentResultLike.

type TaskRunner

type TaskRunner[T AgentResultLike] interface {
	Run(ctx context.Context, taskContent string) (*T, error)
}

TaskRunner orchestrates task execution by launching a single Claude Code session.

func NewTaskRunner

func NewTaskRunner[T AgentResultLike](
	runner ClaudeRunner,
	instructions Instructions,
	envContext map[string]string,
	deliverer ResultDeliverer[T],
) TaskRunner[T]

NewTaskRunner creates a TaskRunner with injected dependencies.

Jump to

Keyboard shortcuts

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