agents

package
v0.11.7 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: EUPL-1.2 Imports: 35 Imported by: 0

Documentation

Overview

Package agents implements infrastructure adapters for AI agent integration.

The agents package provides concrete implementations of the AgentProvider and AgentRegistry ports defined in the domain layer, enabling workflow steps to invoke AI agents (Claude, Gemini, Codex, OpenCode, and OpenAI-compatible endpoints) for code generation, analysis, and decision-making tasks. Each provider wraps a CLI executor and handles model-specific invocation patterns, streaming output, and error mapping.

Architecture Role

In the hexagonal architecture:

  • Implements domain/ports.AgentProvider (per-provider adapters)
  • Implements domain/ports.AgentRegistry (provider registration and lookup)
  • Implements domain/ports.CLIExecutor (CLI command execution)
  • Application layer orchestrates agent steps via these port interfaces
  • Domain layer defines agent contracts without implementation coupling

All agent providers delegate CLI execution to an injected CLIExecutor, allowing test isolation via mock executors. The registry supports runtime provider registration and enables workflow steps to reference agents by name (e.g., "claude", "gemini").

Agent Providers

## ClaudeProvider (claude_provider.go)

Anthropic Claude provider:

  • Execute: Single-shot prompt execution via Claude CLI
  • ExecuteConversation: Multi-turn conversation with context preservation
  • Name: Returns "claude" for registry lookup
  • Validate: Checks required options (model, temperature)

Supported models: claude-3-opus, claude-3-sonnet, claude-3-haiku, claude-2.1, claude-2

## GeminiProvider (gemini_provider.go)

Google Gemini provider:

  • Execute: Single-shot prompt execution via Gemini CLI
  • ExecuteConversation: Multi-turn conversation support
  • Name: Returns "gemini"
  • Validate: Checks model and API key configuration

## CodexProvider (codex_provider.go)

OpenAI Codex provider (code-focused GPT models):

  • Execute: Single-shot code generation via OpenAI CLI
  • ExecuteConversation: Not supported (returns error)
  • Name: Returns "codex"
  • Validate: Checks API key and model configuration

## OpenCodeProvider (opencode_provider.go)

Open-source code generation models (StarCoder, CodeLlama, etc.):

  • Execute: Single-shot execution via custom CLI wrapper
  • ExecuteConversation: Limited support (model-dependent)
  • Name: Returns "opencode"
  • Validate: Checks CLI tool availability

## OpenAICompatibleProvider (openai_compatible_provider.go)

HTTP adapter for any OpenAI-compatible API endpoint (Ollama, LM Studio, vLLM, etc.):

  • Execute: Single-shot prompt via Chat Completions API
  • ExecuteConversation: Multi-turn conversation with history
  • Name: Returns "openai_compatible" for registry lookup
  • Validate: Checks base_url and model configuration

Configuration via agent options: base_url, api_key, model, temperature. Falls back to OPENAI_BASE_URL / OPENAI_MODEL / OPENAI_API_KEY env vars.

Registry and Discovery

## AgentRegistry (registry.go)

Provider registration and lookup:

  • Register: Add provider by name (thread-safe)
  • Get: Retrieve provider by name
  • List: Enumerate registered provider names
  • Has: Check if provider exists
  • RegisterDefaults: Pre-populate with built-in providers

CLI Execution

## ExecCLIExecutor (cli_executor.go)

External binary execution:

  • Run: Execute command with streaming stdout/stderr, context cancellation
  • Process cleanup: Kills descendant processes on cancellation
  • Signal propagation: Forwards SIGINT/SIGTERM to child processes

Used by all agent providers to invoke CLI tools (claude, gemini, gpt, etc.).

Provider Options

## Functional Options Pattern (options.go)

Provider configuration via option functions:

  • WithClaudeExecutor: Inject custom executor for Claude provider
  • WithGeminiExecutor: Inject custom executor for Gemini provider
  • WithCodexExecutor: Inject custom executor for Codex provider
  • WithOpenCodeExecutor: Inject custom executor for OpenCode provider
  • WithHTTPClient: Inject custom HTTP client for OpenAICompatible provider

Each provider accepts zero or more options at construction time for dependency injection.

Index

Constants

View Source
const (
	EventText    = display.EventText
	EventToolUse = display.EventToolUse
)
View Source
const (
	DisplayModeDefault = display.DisplayModeDefault
	DisplayModeVerbose = display.DisplayModeVerbose
)

Variables

This section is empty.

Functions

func ClaudeToContentBlocks added in v0.11.2

func ClaudeToContentBlocks(line []byte) []transcript.ContentBlock

func CodexToContentBlocks added in v0.11.2

func CodexToContentBlocks(line []byte) []transcript.ContentBlock

CodexToContentBlocks maps a single Codex NDJSON line to transcript ContentBlocks. Raw NUL bytes (0x00) are escaped to the six-byte JSON unicode sequence before unmarshal, matching the behavior in codex_provider.go:343.

func CopilotToContentBlocks added in v0.11.2

func CopilotToContentBlocks(line []byte) []transcript.ContentBlock

CopilotToContentBlocks maps a single Copilot NDJSON line to transcript ContentBlocks. Mirrors the event-typed shape consumed by parseCopilotDisplayEvents in copilot_provider.go.

func GeminiToContentBlocks added in v0.11.2

func GeminiToContentBlocks(line []byte) []transcript.ContentBlock

func OpenAICompatibleToContentBlocks added in v0.11.2

func OpenAICompatibleToContentBlocks(line []byte) []transcript.ContentBlock

OpenAICompatibleToContentBlocks maps a single OpenAI-compatible NDJSON line to transcript ContentBlocks. Mirrors the delta/message shape consumed by translateOpenAICompatibleDisplayEvents in openai_compatible_provider.go.

func PurgeOrphanMCPRegistrations added in v0.11.2

func PurgeOrphanMCPRegistrations(ctx context.Context, exec ports.CommandExecutor, logger ports.Logger) error

PurgeOrphanMCPRegistrations removes any persistent MCP server registration whose name starts with mcpProxyNamePrefix from Gemini and OpenCode CLIs.

Both CLIs are queried via `<cli> mcp list`; matching entries are removed via `<cli> mcp remove <name>`. Each failure mode is classified and logged distinctly (see purgeForCLI) and none block startup — the function always returns nil because purge is best-effort.

Environment variables:

  • AWF_MCP_PROXY_NO_PURGE: when set to any non-empty value, returns immediately without executing any commands (for users who intentionally keep awf-proxy- prefixed registrations).
  • AWF_MCP_PROXY_LIST_TIMEOUT: overrides the per-CLI `mcp list` timeout (Go duration, e.g. "10s"). Defaults to mcpListDefaultTimeout.

Types

type AgentRegistry

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

AgentRegistry manages registered agent providers.

func NewAgentRegistry

func NewAgentRegistry() *AgentRegistry

func (*AgentRegistry) Get

func (r *AgentRegistry) Get(name string) (ports.AgentProvider, error)

func (*AgentRegistry) Has

func (r *AgentRegistry) Has(name string) bool

func (*AgentRegistry) List

func (r *AgentRegistry) List() []string

func (*AgentRegistry) Register

func (r *AgentRegistry) Register(provider ports.AgentProvider) error

func (*AgentRegistry) RegisterDefaults

func (r *AgentRegistry) RegisterDefaults(cmdExec ports.CommandExecutor, openAIOpts ...OpenAICompatibleProviderOption) error

RegisterDefaults registers all default providers. It continues registering even if individual providers fail, collecting all errors and returning them aggregated.

Pass nil for cmdExec to disable MCP proxy support for providers that require a CommandExecutor (Gemini); attempting to use mcp_proxy with such a provider will fail at step startup with a clear error rather than a nil-pointer panic. OpenCode MCP proxy uses workspace file config and does not require a CommandExecutor.

type ClaudeProvider

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

ClaudeProvider implements AgentProvider for Claude CLI. Invokes: claude -p "prompt" --output-format stream-json

func NewClaudeProvider

func NewClaudeProvider(l ...ports.Logger) *ClaudeProvider

func NewClaudeProviderWithOptions

func NewClaudeProviderWithOptions(opts ...ClaudeProviderOption) *ClaudeProvider

func (*ClaudeProvider) Execute

func (p *ClaudeProvider) Execute(ctx context.Context, prompt string, options map[string]any, stdout, stderr io.Writer) (*workflow.AgentResult, error)

func (*ClaudeProvider) ExecuteConversation

func (p *ClaudeProvider) ExecuteConversation(ctx context.Context, state *workflow.ConversationState, prompt string, options map[string]any, stdout, stderr io.Writer) (*workflow.ConversationResult, error)

ExecuteConversation invokes the Claude CLI with conversation history for multi-turn interactions.

func (*ClaudeProvider) Name

func (p *ClaudeProvider) Name() string

func (*ClaudeProvider) Preflight added in v0.11.4

func (p *ClaudeProvider) Preflight(ctx context.Context, options map[string]any) error

func (*ClaudeProvider) Validate

func (p *ClaudeProvider) Validate() error

type ClaudeProviderOption

type ClaudeProviderOption func(*ClaudeProvider)

func WithClaudeExecutor

func WithClaudeExecutor(executor ports.CLIExecutor) ClaudeProviderOption

func WithClaudeLogger added in v0.11.2

func WithClaudeLogger(l ports.Logger) ClaudeProviderOption

func WithClaudeTokenizer added in v0.11.2

func WithClaudeTokenizer(tok ports.Tokenizer) ClaudeProviderOption

type CodexProvider

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

CodexProvider implements AgentProvider for Codex CLI. Invokes: codex exec --json "prompt"

func NewCodexProvider

func NewCodexProvider() *CodexProvider

func NewCodexProviderWithOptions

func NewCodexProviderWithOptions(opts ...CodexProviderOption) *CodexProvider

func (*CodexProvider) Execute

func (p *CodexProvider) Execute(ctx context.Context, prompt string, options map[string]any, stdout, stderr io.Writer) (*workflow.AgentResult, error)

func (*CodexProvider) ExecuteConversation

func (p *CodexProvider) ExecuteConversation(ctx context.Context, state *workflow.ConversationState, prompt string, options map[string]any, stdout, stderr io.Writer) (*workflow.ConversationResult, error)

func (*CodexProvider) Name

func (p *CodexProvider) Name() string

func (*CodexProvider) Preflight added in v0.11.4

func (p *CodexProvider) Preflight(ctx context.Context, options map[string]any) error

func (*CodexProvider) Validate

func (p *CodexProvider) Validate() error

type CodexProviderOption

type CodexProviderOption func(*CodexProvider)

func WithCodexExecutor

func WithCodexExecutor(executor ports.CLIExecutor) CodexProviderOption

func WithCodexLogger

func WithCodexLogger(l ports.Logger) CodexProviderOption

func WithCodexTokenizer added in v0.11.2

func WithCodexTokenizer(tok ports.Tokenizer) CodexProviderOption

type ContentBlockNormalizer added in v0.11.2

type ContentBlockNormalizer struct{}

ContentBlockNormalizer is the infrastructure implementation of ports.AgentOutputNormalizer. It dispatches a provider's raw CLI output to the matching per-provider line normalizer (the *ToContentBlocks functions), absorbing provider divergence in this single layer (F106 SC-002).

func NewContentBlockNormalizer added in v0.11.2

func NewContentBlockNormalizer() ContentBlockNormalizer

NewContentBlockNormalizer returns a ready-to-use normalizer. It is stateless, so the zero value works too; the constructor exists for wiring symmetry.

func (ContentBlockNormalizer) Normalize added in v0.11.2

func (ContentBlockNormalizer) Normalize(provider string, rawOutput []byte) []transcript.ContentBlock

Normalize scans the provider's raw NDJSON output line-by-line and concatenates the blocks produced for each line. It returns nil for an unknown provider, empty output, or output that yields no blocks. It never panics on malformed input — each line normalizer tolerates unparseable lines by returning no blocks.

type CopilotProvider added in v0.11.2

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

CopilotProvider implements AgentProvider for GitHub Copilot CLI. Invokes: copilot -p "prompt" --output-format=json --silent

func NewCopilotProvider added in v0.11.2

func NewCopilotProvider() *CopilotProvider

func NewCopilotProviderWithOptions added in v0.11.2

func NewCopilotProviderWithOptions(opts ...CopilotProviderOption) *CopilotProvider

func (*CopilotProvider) Execute added in v0.11.2

func (p *CopilotProvider) Execute(ctx context.Context, prompt string, options map[string]any, stdout, stderr io.Writer) (*workflow.AgentResult, error)

func (*CopilotProvider) ExecuteConversation added in v0.11.2

func (p *CopilotProvider) ExecuteConversation(ctx context.Context, state *workflow.ConversationState, prompt string, options map[string]any, stdout, stderr io.Writer) (*workflow.ConversationResult, error)

func (*CopilotProvider) Name added in v0.11.2

func (p *CopilotProvider) Name() string

func (*CopilotProvider) Preflight added in v0.11.4

func (p *CopilotProvider) Preflight(ctx context.Context, options map[string]any) error

func (*CopilotProvider) Validate added in v0.11.2

func (p *CopilotProvider) Validate() error

type CopilotProviderOption added in v0.11.2

type CopilotProviderOption func(*CopilotProvider)

func WithCopilotExecutor added in v0.11.2

func WithCopilotExecutor(executor ports.CLIExecutor) CopilotProviderOption

func WithCopilotLogger added in v0.11.2

func WithCopilotLogger(l ports.Logger) CopilotProviderOption

func WithCopilotTokenizer added in v0.11.2

func WithCopilotTokenizer(tok ports.Tokenizer) CopilotProviderOption

type DisplayEvent added in v0.11.2

type DisplayEvent = display.DisplayEvent

Type aliases re-export display types for internal use within the agents package. External consumers should import pkg/display directly.

type DisplayEventParser added in v0.11.2

type DisplayEventParser = display.DisplayEventParser

Type aliases re-export display types for internal use within the agents package. External consumers should import pkg/display directly.

type DisplayEventRenderer added in v0.11.2

type DisplayEventRenderer func(events []DisplayEvent)

DisplayEventRenderer receives parsed DisplayEvents for rendering to output.

type DisplayMode added in v0.11.2

type DisplayMode = display.DisplayMode

Type aliases re-export display types for internal use within the agents package. External consumers should import pkg/display directly.

type EventKind added in v0.11.2

type EventKind = display.EventKind

Type aliases re-export display types for internal use within the agents package. External consumers should import pkg/display directly.

type ExecCLIExecutor

type ExecCLIExecutor struct{}

ExecCLIExecutor implements CLIExecutor using os/exec for direct binary execution. Unlike shell execution via detected shell ($SHELL), this executes binaries directly without shell interpretation, making it suitable for invoking external CLI tools like claude, gemini, codex, etc.

func NewExecCLIExecutor

func NewExecCLIExecutor() *ExecCLIExecutor

func (*ExecCLIExecutor) Run

func (e *ExecCLIExecutor) Run(ctx context.Context, name string, stdoutW, stderrW io.Writer, args ...string) (stdout, stderr []byte, err error)

func (*ExecCLIExecutor) RunWithEnv added in v0.11.2

func (e *ExecCLIExecutor) RunWithEnv(ctx context.Context, name string, env map[string]string, stdoutW, stderrW io.Writer, args ...string) (stdout, stderr []byte, err error)

func (*ExecCLIExecutor) Start added in v0.11.2

func (e *ExecCLIExecutor) Start(ctx context.Context, name string, args ...string) (ports.CLIProcess, error)

Start launches a binary without blocking. A background goroutine drives cmd.Wait so that Done() is closed when the process exits.

type GeminiProvider

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

GeminiProvider implements AgentProvider for Gemini CLI. Invokes: gemini -p "prompt"

func NewGeminiProvider

func NewGeminiProvider() *GeminiProvider

func NewGeminiProviderWithOptions

func NewGeminiProviderWithOptions(opts ...GeminiProviderOption) *GeminiProvider

func (*GeminiProvider) Execute

func (p *GeminiProvider) Execute(ctx context.Context, prompt string, options map[string]any, stdout, stderr io.Writer) (*workflow.AgentResult, error)

func (*GeminiProvider) ExecuteConversation

func (p *GeminiProvider) ExecuteConversation(ctx context.Context, state *workflow.ConversationState, prompt string, options map[string]any, stdout, stderr io.Writer) (*workflow.ConversationResult, error)

func (*GeminiProvider) Name

func (p *GeminiProvider) Name() string

func (*GeminiProvider) Preflight added in v0.11.4

func (p *GeminiProvider) Preflight(ctx context.Context, options map[string]any) error

func (*GeminiProvider) Validate

func (p *GeminiProvider) Validate() error

type GeminiProviderOption

type GeminiProviderOption func(*GeminiProvider)

func WithGeminiCommandExecutor added in v0.11.2

func WithGeminiCommandExecutor(executor ports.CommandExecutor) GeminiProviderOption

func WithGeminiDenyAllPolicy added in v0.11.2

func WithGeminiDenyAllPolicy(policyPath string) GeminiProviderOption

func WithGeminiExecutor

func WithGeminiExecutor(executor ports.CLIExecutor) GeminiProviderOption

func WithGeminiLogger added in v0.11.2

func WithGeminiLogger(l ports.Logger) GeminiProviderOption

func WithGeminiTokenizer added in v0.11.2

func WithGeminiTokenizer(tok ports.Tokenizer) GeminiProviderOption

type MistralVibeProvider added in v0.11.2

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

func NewMistralVibeProvider added in v0.11.2

func NewMistralVibeProvider() *MistralVibeProvider

func NewMistralVibeProviderWithOptions added in v0.11.2

func NewMistralVibeProviderWithOptions(opts ...MistralVibeProviderOption) *MistralVibeProvider

func (*MistralVibeProvider) Execute added in v0.11.2

func (p *MistralVibeProvider) Execute(ctx context.Context, prompt string, options map[string]any, stdout, stderr io.Writer) (*workflow.AgentResult, error)

func (*MistralVibeProvider) ExecuteConversation added in v0.11.2

func (p *MistralVibeProvider) ExecuteConversation(ctx context.Context, state *workflow.ConversationState, prompt string, options map[string]any, stdout, stderr io.Writer) (*workflow.ConversationResult, error)

func (*MistralVibeProvider) Name added in v0.11.2

func (p *MistralVibeProvider) Name() string

func (*MistralVibeProvider) Preflight added in v0.11.4

func (p *MistralVibeProvider) Preflight(ctx context.Context, options map[string]any) error

func (*MistralVibeProvider) Validate added in v0.11.2

func (p *MistralVibeProvider) Validate() error

type MistralVibeProviderOption added in v0.11.2

type MistralVibeProviderOption func(*MistralVibeProvider)

func WithMistralVibeExecutor added in v0.11.2

func WithMistralVibeExecutor(executor ports.CLIExecutor) MistralVibeProviderOption

func WithMistralVibeLogger added in v0.11.2

func WithMistralVibeLogger(l ports.Logger) MistralVibeProviderOption

func WithMistralVibeTokenizer added in v0.11.2

func WithMistralVibeTokenizer(tok ports.Tokenizer) MistralVibeProviderOption

type MockCall

type MockCall struct {
	Method  string
	Prompt  string
	Options map[string]any
	State   *workflow.ConversationState
}

MockCall records a call made to the mock provider.

type MockProvider

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

MockProvider provides deterministic responses for testing without external CLI calls. It implements ports.AgentProvider interface.

func NewMockProvider

func NewMockProvider(name string) *MockProvider

NewMockProvider creates a new mock provider with the given name.

func (*MockProvider) CallCount

func (m *MockProvider) CallCount() int

CallCount returns the number of calls made.

func (*MockProvider) Calls

func (m *MockProvider) Calls() []MockCall

Calls returns all recorded calls.

func (*MockProvider) ConversationCallCount

func (m *MockProvider) ConversationCallCount() int

ConversationCallCount returns the number of ExecuteConversation calls.

func (*MockProvider) Execute

func (m *MockProvider) Execute(ctx context.Context, prompt string, options map[string]any, _, _ io.Writer) (*workflow.AgentResult, error)

Execute implements ports.AgentProvider.

func (*MockProvider) ExecuteCallCount

func (m *MockProvider) ExecuteCallCount() int

ExecuteCallCount returns the number of Execute calls.

func (*MockProvider) ExecuteConversation

func (m *MockProvider) ExecuteConversation(ctx context.Context, state *workflow.ConversationState, prompt string, options map[string]any, _, _ io.Writer) (*workflow.ConversationResult, error)

ExecuteConversation implements ports.AgentProvider.

func (*MockProvider) Name

func (m *MockProvider) Name() string

Name implements ports.AgentProvider.

func (*MockProvider) Reset

func (m *MockProvider) Reset()

Reset clears all recorded calls.

func (*MockProvider) Validate

func (m *MockProvider) Validate() error

Validate implements ports.AgentProvider.

func (*MockProvider) WithConversationResponse

func (m *MockProvider) WithConversationResponse(pattern string, result *workflow.ConversationResult) *MockProvider

WithConversationResponse configures a conversation response for prompts containing the pattern.

func (*MockProvider) WithDefaultConversationResponse

func (m *MockProvider) WithDefaultConversationResponse(result *workflow.ConversationResult) *MockProvider

WithDefaultConversationResponse sets the default conversation response.

func (*MockProvider) WithDefaultResponse

func (m *MockProvider) WithDefaultResponse(result *workflow.AgentResult) *MockProvider

WithDefaultResponse sets the default response when no pattern matches.

func (*MockProvider) WithDelay

func (m *MockProvider) WithDelay(d time.Duration) *MockProvider

WithDelay sets the simulated processing delay.

func (*MockProvider) WithResponse

func (m *MockProvider) WithResponse(pattern string, result *workflow.AgentResult) *MockProvider

WithResponse configures a response for prompts containing the given pattern.

func (*MockProvider) WithValidateError

func (m *MockProvider) WithValidateError(err error) *MockProvider

WithValidateError configures the provider to return an error on Validate().

type OpenAICompatibleProvider

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

OpenAICompatibleProvider implements AgentProvider via the Chat Completions HTTP API. Compatible with OpenAI, Ollama, vLLM, Groq, and any OpenAI-compatible backend.

MCP proxy integration — divergence from CLI providers:

The CLI providers (Claude, Codex, Gemini, Opencode) wire MCP through a `mcpInjector` hook on baseCLIProvider, which appends provider-specific flags to the subprocess invocation (e.g. `--mcp-config <path>`). That path does not apply here: this provider speaks the Chat Completions HTTP API directly and has no child process to inject flags into.

Instead, MCP integration is HTTP-native and lives entirely in this file:

  • SetToolRouter installs an application/tools.Router implementation;
  • buildToolList reads the MCPProxyConfig from options and advertises tools (respecting cfg.InterceptBuiltins) in the `tools` request field;
  • dispatchToolCall routes the model's tool_calls back through the Router and feeds tool results into the next turn.

This is the documented HTTP-native MCP path; the absence of an mcpInjector here is intentional, not a missing implementation.

func (*OpenAICompatibleProvider) Execute

func (p *OpenAICompatibleProvider) Execute(ctx context.Context, prompt string, options map[string]any, stdout, _ io.Writer) (*workflow.AgentResult, error)

func (*OpenAICompatibleProvider) ExecuteConversation

func (p *OpenAICompatibleProvider) ExecuteConversation(ctx context.Context, state *workflow.ConversationState, prompt string, options map[string]any, stdout, _ io.Writer) (*workflow.ConversationResult, error)

func (*OpenAICompatibleProvider) Name

func (p *OpenAICompatibleProvider) Name() string

func (*OpenAICompatibleProvider) Preflight added in v0.11.4

func (p *OpenAICompatibleProvider) Preflight(ctx context.Context, options map[string]any) error

func (*OpenAICompatibleProvider) SetToolRouter added in v0.11.2

func (p *OpenAICompatibleProvider) SetToolRouter(r ports.ToolRouter)

func (*OpenAICompatibleProvider) Validate

func (p *OpenAICompatibleProvider) Validate() error

type OpenAICompatibleProviderOption

type OpenAICompatibleProviderOption func(*OpenAICompatibleProvider)

func WithHTTPClient

func WithHTTPClient(client *httpx.Client) OpenAICompatibleProviderOption

type OpenCodeProvider

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

OpenCodeProvider implements AgentProvider for OpenCode CLI. Invokes: opencode run "prompt"

func NewOpenCodeProvider

func NewOpenCodeProvider() *OpenCodeProvider

func NewOpenCodeProviderWithOptions

func NewOpenCodeProviderWithOptions(opts ...OpenCodeProviderOption) *OpenCodeProvider

func (*OpenCodeProvider) Execute

func (p *OpenCodeProvider) Execute(ctx context.Context, prompt string, options map[string]any, stdout, stderr io.Writer) (*workflow.AgentResult, error)

Execute invokes the OpenCode CLI with the given prompt and options.

func (*OpenCodeProvider) ExecuteConversation

func (p *OpenCodeProvider) ExecuteConversation(ctx context.Context, state *workflow.ConversationState, prompt string, options map[string]any, stdout, stderr io.Writer) (*workflow.ConversationResult, error)

ExecuteConversation invokes the OpenCode CLI with conversation history for multi-turn interactions.

func (*OpenCodeProvider) Name

func (p *OpenCodeProvider) Name() string

Name returns the provider identifier.

func (*OpenCodeProvider) Preflight added in v0.11.4

func (p *OpenCodeProvider) Preflight(ctx context.Context, options map[string]any) error

func (*OpenCodeProvider) Validate

func (p *OpenCodeProvider) Validate() error

Validate checks if the OpenCode CLI is installed and accessible.

type OpenCodeProviderOption

type OpenCodeProviderOption func(*OpenCodeProvider)

func WithOpenCodeExecutor

func WithOpenCodeExecutor(executor ports.CLIExecutor) OpenCodeProviderOption

func WithOpenCodeLogger added in v0.11.2

func WithOpenCodeLogger(l ports.Logger) OpenCodeProviderOption

func WithOpenCodeTokenizer added in v0.11.2

func WithOpenCodeTokenizer(tok ports.Tokenizer) OpenCodeProviderOption

type PreflightFailureReason added in v0.11.4

type PreflightFailureReason string
const (
	PreflightNotAuthenticated     PreflightFailureReason = "not_authenticated"
	PreflightStatusUnsupported    PreflightFailureReason = "status_unsupported"
	PreflightStatusMalformed      PreflightFailureReason = "status_malformed"
	PreflightConfigurationInvalid PreflightFailureReason = "configuration_invalid"
)

type ProviderPreflightError added in v0.11.4

type ProviderPreflightError struct {
	Provider string
	Reason   PreflightFailureReason
	Cause    error
}

func (*ProviderPreflightError) Error added in v0.11.4

func (e *ProviderPreflightError) Error() string

func (*ProviderPreflightError) Unwrap added in v0.11.4

func (e *ProviderPreflightError) Unwrap() error

type StreamFilterWriter added in v0.11.2

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

StreamFilterWriter buffers NDJSON lines and filters them. Lines exceeding 10 MB are dumped raw to prevent unbounded memory growth.

func NewStreamFilterWriter added in v0.11.2

func NewStreamFilterWriter(inner io.Writer, extract func(line []byte) string, logger ...ports.Logger) *StreamFilterWriter

NewStreamFilterWriter decorates inner with line filtering. If extract is nil, data passes through unfiltered.

func NewStreamFilterWriterWithParser added in v0.11.2

func NewStreamFilterWriterWithParser(inner io.Writer, parser DisplayEventParser, renderer DisplayEventRenderer, logger ...ports.Logger) *StreamFilterWriter

NewStreamFilterWriterWithParser decorates inner with event-aware filtering. Parsed events are forwarded to renderer; if renderer is nil events are discarded.

func (*StreamFilterWriter) Flush added in v0.11.2

func (w *StreamFilterWriter) Flush() error

Flush emits any buffered partial line.

func (*StreamFilterWriter) Write added in v0.11.2

func (w *StreamFilterWriter) Write(p []byte) (int, error)

type ToolCall added in v0.11.2

type ToolCall struct {
	ID        string
	Name      string
	Arguments map[string]any
}

ToolCall is a fully assembled tool call derived from one or more SSE deltas.

type ToolCallDelta added in v0.11.2

type ToolCallDelta struct {
	Index    int    `json:"index"`
	ID       string `json:"id"`
	Type     string `json:"type"`
	Function struct {
		Name      string `json:"name"`
		Arguments string `json:"arguments"`
	} `json:"function"`
}

ToolCallDelta is one SSE chunk contributing to a streamed tool call. Multiple deltas with the same index form a single tool call; their function.arguments fields must be concatenated in order before parsing.

type ToolDefinition added in v0.11.2

type ToolDefinition struct {
	Type     string             `json:"type"`
	Function toolFunctionSchema `json:"function"`
}

ToolDefinition is the JSON representation of a tool for the Chat Completions API.

Jump to

Keyboard shortcuts

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