Help us shape the future of Go! Take the 2026 Go Developer Survey

opencode

package
v1.233.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package opencode provides an AI provider that invokes the opencode CLI (https://opencode.ai) as a subprocess, reusing the user's opencode setup and whichever model provider they have configured/authenticated there.

Index

Constants

View Source
const (
	// ProviderName is the name of this provider for configuration lookup.
	ProviderName = "opencode"
	// DefaultBinary is the default binary name for the opencode CLI.
	DefaultBinary = "opencode"
	// ConfigEnvVar points opencode at a specific config file. Its precedence sits between
	// the global and project configs, and opencode deep-merges it, so pointing it at a
	// temp file that only defines `mcp` servers adds those servers without disturbing the
	// user's own opencode.json.
	ConfigEnvVar = "OPENCODE_CONFIG"
)

Variables

This section is empty.

Functions

func ExtractResult

func ExtractResult(output []byte) (string, error)

ExtractResult extracts the final text response from opencode's output. The default `run` output carries the assistant's plain-text response on stdout.

Types

type Client

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

Client invokes the opencode CLI in non-interactive ("run") mode. Authentication and model-provider selection are handled by opencode itself (`opencode auth login`), the same way Atmos relies on the user's existing `terraform`/`tofu` installation.

func NewClient

func NewClient(atmosConfig *schema.AtmosConfiguration) (*Client, error)

NewClient creates a new opencode CLI client from Atmos configuration.

func (*Client) GetMaxTokens

func (c *Client) GetMaxTokens() int

GetMaxTokens returns 0 — managed by opencode internally.

func (*Client) GetModel

func (c *Client) GetModel() string

GetModel returns the configured model name.

func (*Client) SendMessage

func (c *Client) SendMessage(ctx context.Context, message string) (string, error)

SendMessage sends a prompt to opencode and returns the response.

func (*Client) SendMessageWithHistory

func (c *Client) SendMessageWithHistory(ctx context.Context, messages []types.Message) (string, error)

SendMessageWithHistory concatenates history into a single prompt.

func (*Client) SendMessageWithSystemPromptAndTools

func (c *Client) SendMessageWithSystemPromptAndTools(
	ctx context.Context,
	systemPrompt string,
	atmosMemory string,
	messages []types.Message,
	_ []tools.Tool,
) (*types.Response, error)

SendMessageWithSystemPromptAndTools sends with system prompt and memory prepended.

func (*Client) SendMessageWithTools

func (c *Client) SendMessageWithTools(_ context.Context, _ string, _ []tools.Tool) (*types.Response, error)

SendMessageWithTools is not supported — opencode manages its own tools.

func (*Client) SendMessageWithToolsAndHistory

func (c *Client) SendMessageWithToolsAndHistory(_ context.Context, _ []types.Message, _ []tools.Tool) (*types.Response, error)

SendMessageWithToolsAndHistory is not supported.

Jump to

Keyboard shortcuts

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