Documentation
¶
Index ¶
- Constants
- func ConfigPath() string
- func LoadEnv() (map[string]string, error)
- func Models(ctx context.Context, opts types.UsageOptions) ([]string, error)
- func ParseEnvConfig(data []byte) (map[string]string, error)
- func PrepareAgent() (string, func(), error)
- func Prompt(ctx context.Context, prompt string, opts types.PromptOptions) (*types.PromptResult, error)
- func SplitModelVariant(model string) (string, string)
- func Usage(ctx context.Context, opts types.UsageOptions) ([]types.ModelUsage, error)
- type Client
- func (c *Client) AuthDirectory(home string) string
- func (c *Client) AuthFiles(home string) []string
- func (c *Client) ExtraArgs() []string
- func (c *Client) ExtraEnv(home string) map[string]string
- func (c *Client) Models(ctx context.Context, opts types.UsageOptions) ([]string, error)
- func (c *Client) MountDirectories(home string) []string
- func (c *Client) Prompt(ctx context.Context, prompt string, opts types.PromptOptions) (*types.PromptResult, error)
- func (c *Client) SkillsMountPath(home string) string
- func (c *Client) SystemPromptHeader() string
- func (c *Client) SystemPromptPeerHeader() string
- func (c *Client) Usage(ctx context.Context, opts types.UsageOptions) ([]types.ModelUsage, error)
Constants ¶
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 ¶
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 ParseEnvConfig ¶
ParseEnvConfig parses YAML configuration bytes supporting both:
- Nested env mapping: env: KEY: "val"
- 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 ¶
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 ¶
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 (*Client) AuthDirectory ¶
func (*Client) MountDirectories ¶
func (*Client) Prompt ¶
func (c *Client) Prompt(ctx context.Context, prompt string, opts types.PromptOptions) (*types.PromptResult, error)
func (*Client) SkillsMountPath ¶
func (*Client) SystemPromptHeader ¶
func (*Client) SystemPromptPeerHeader ¶
func (*Client) Usage ¶
func (c *Client) Usage(ctx context.Context, opts types.UsageOptions) ([]types.ModelUsage, error)