opencode

package
v0.0.0-...-345d077 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const EnvOpencodeAWConfig = "OPENCODE_AW_CONFIG"

EnvOpencodeAWConfig is the environment variable that can explicitly override the path to opencode.aw.yaml.

Variables

This section is empty.

Functions

func ConfigPath

func ConfigPath() string

ConfigPath discovers the path to opencode.aw.yaml according to the resolution order: 1. OPENCODE_AW_CONFIG environment variable if set. 2. Directory of awconfig.Path() (e.g. /session/opencode.aw.yaml or ~/.config/aw/opencode.aw.yaml). 3. Fall back to standard ~/.config/aw/opencode.aw.yaml (or $XDG_CONFIG_HOME/aw/opencode.aw.yaml). If the discovered file does not exist, ConfigPath returns "" (unless explicitly set via OPENCODE_AW_CONFIG).

func LoadEnv

func LoadEnv() (map[string]string, error)

LoadEnv loads environment variables defined in opencode.aw.yaml. If the config file does not exist, it returns empty/nil without error (fallback mode).

func Models

func Models(ctx context.Context, opts types.UsageOptions) ([]string, error)

Models runs "opencode models", parses the list of models, and returns them.

func ParseEnvConfig

func ParseEnvConfig(data []byte) (map[string]string, error)

ParseEnvConfig parses YAML configuration bytes supporting both:

  1. Nested env mapping: env: KEY: "val"
  2. Flat key-value pairs: KEY: "val"

If both formats are present, keys inside the "env" section take precedence. Scalar values (string, integer, float, boolean) are converted to string values.

func PrepareAgent

func PrepareAgent() (string, func(), error)

PrepareAgent materializes the CLI-native opencode agent definition from the AW_AGENTS.md contract and returns the agent name to pass to `opencode run --agent`, plus a cleanup function that restores the sandbox config state (generated agent file and any neutralized ambient file are removed / restored). Call cleanup after the run, e.g. via defer.

When no contract is mounted (plain `aw opencode` usage outside the Asgard sandbox), PrepareAgent returns ("", no-op, nil) and the caller runs opencode with its native defaults.

func Prompt

func Prompt(ctx context.Context, prompt string, opts types.PromptOptions) (*types.PromptResult, error)

Prompt sends a prompt to opencode and parses its JSONL output in real-time. If opts.ReportCallback is set, it is called for each meaningful output line.

When the AW_AGENTS.md contract is mounted (Asgard sandbox runs), the contract is first materialized into a CLI-native primary agent definition (see PrepareAgent) so the agent identity and tool permissions are enforced by opencode itself instead of arriving as weak ambient instructions.

func SplitModelVariant

func SplitModelVariant(model string) (string, string)

SplitModelVariant parses a model string that may contain a variant suffix (e.g. "zai-coding-plan/glm-5.3/low" -> "zai-coding-plan/glm-5.3", "low") or ("openai/gpt-5/high" -> "openai/gpt-5", "high"). Only a trailing segment matching a known variant is treated as a variant, so models with multi-segment provider paths (e.g. "openrouter/deepseek/deepseek-chat") are left intact. If no variant suffix is present, it returns (model, "").

func Usage

func Usage(ctx context.Context, opts types.UsageOptions) ([]types.ModelUsage, error)

Usage runs "opencode models", parses the list of models, and returns a ModelUsage list.

Types

type Client

type Client struct{}

func NewClient

func NewClient() *Client

func (*Client) AuthDirectory

func (c *Client) AuthDirectory(home string) string

func (*Client) AuthFiles

func (c *Client) AuthFiles(home string) []string

func (*Client) ExtraArgs

func (c *Client) ExtraArgs() []string

func (*Client) ExtraEnv

func (c *Client) ExtraEnv(home string) map[string]string

func (*Client) Models

func (c *Client) Models(ctx context.Context, opts types.UsageOptions) ([]string, error)

func (*Client) MountDirectories

func (c *Client) MountDirectories(home string) []string

func (*Client) Prompt

func (c *Client) Prompt(ctx context.Context, prompt string, opts types.PromptOptions) (*types.PromptResult, error)

func (*Client) SkillsMountPath

func (c *Client) SkillsMountPath(home string) string

func (*Client) SystemPromptHeader

func (c *Client) SystemPromptHeader() string

func (*Client) SystemPromptPeerHeader

func (c *Client) SystemPromptPeerHeader() string

func (*Client) Usage

func (c *Client) Usage(ctx context.Context, opts types.UsageOptions) ([]types.ModelUsage, error)

Jump to

Keyboard shortcuts

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