opencode

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package opencode reads opencode's project definitions, with opencode's meaning (ADR 0002): agents (.opencode/agents/*.md), commands (.opencode/commands/*.md) and skills (SKILL.md under .opencode/skills, .claude/skills and .agents/skills). It only reads and expands; the runtime decides what they do, and records it (invariant 2).

Index

Constants

This section is empty.

Variables

View Source
var BuiltinAgents = []string{"build", "plan"}

BuiltinAgents are the agents there are without any definition (build does the work, plan only reads); only opencode's definitions change them.

Functions

func Agents

func Agents(dirs []string) (map[string]Agent, error)

Agents reads the agent definitions of dirs. A name defined in several files takes each field from the last file that sets it, and the permission layers of all of them in order.

func Commands

func Commands(dirs []string) (map[string]Command, error)

Commands reads the command definitions of dirs; a later file of a name replaces the fields it sets.

func DefinitionDirs

func DefinitionDirs(dir string) []string

DefinitionDirs are where agents and commands are read from, in the order they apply, the last winning: the user's Claude Code (~/.claude), ~/.agents and opencode's (as Dirs); then, from the repository's root down to dir, each directory's .claude, .agents and .opencode. Those that do not exist are left out.

func Dirs

func Dirs(dir string) []string

Dirs are opencode's configuration directories for a working directory, in the order their definitions apply, the last winning: the user's ($XDG_CONFIG_HOME/opencode or ~/.config/opencode), then each .opencode from the repository's root (the nearest directory above holding .git) down to dir, the nearest last. Those that do not exist are left out.

opencode walks up from dir and applies what it finds in that order, so there a .opencode higher up wins over a nearer one; here the nearer one wins, as for its settings files (opencode.json).

func Expand

func Expand(c Command, args, dir string, run func(cmd string) (string, error), may func(tool, subject string) bool) (string, error)

Expand makes the prompt of command c run with args, as opencode does, in this order:

  1. args split into words; a quoted group is one word, its quotes cut;
  2. $1, $2, ... are the words; the highest of them in the template takes the rest of the words too, and one past the last word is empty;
  3. $ARGUMENTS is args as they came;
  4. a template with neither gets args after it, on its own paragraph;
  5. each !`command` is replaced with what run prints (args can hold one: opencode runs those too);
  6. the text is trimmed;
  7. each @path of a file under dir is followed by the file, appended.

may says whether the project's permission rules let a tool (bash, read) act on a subject; one they deny is not run or read, as a tool call would not be.

func ProjectDirs

func ProjectDirs(dir string) []string

ProjectDirs are the directories from the repository's root down to dir (dir alone outside a repository).

func SkillDirs

func SkillDirs(dir string) []string

SkillDirs are where skills are looked for, in the order they apply (a later skill of a name wins), as opencode looks: the user's ~/.claude/skills and ~/.agents/skills; .claude/skills and .agents/skills from the repository's root down to dir; skills/ and skill/ in each configuration directory (Dirs); then KairoCode's own, the user's (~/.config/kairocode/skills) and .kairocode/skills from the root down (ADR 0002).

func SkillList

func SkillList(skills map[string]Skill) string

SkillList is the list of skills for the system prompt, as opencode writes it: those with a description, by name.

func Skills

func Skills(dirs []string) (map[string]Skill, error)

Skills reads every SKILL.md under dirs (at any depth). One whose frontmatter has no name is not a skill, as in opencode, and is skipped.

func Split

func Split(md []byte) (front, body string, err error)

Split separates a Markdown file's frontmatter (between "---" lines at its top; a byte order mark and spaces after the dashes are let be) from its body. A file without one has an empty frontmatter; one that opens a frontmatter and never closes it is an error, not a body: its rules must not be dropped unseen.

Types

type Agent

type Agent struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	// Mode is "primary", "subagent" or "all" (the default).
	Mode string `json:"mode,omitempty"`
	// Model is "provider/model".
	Model string `json:"model,omitempty"`
	// Prompt, if not empty, takes the place of the default system prompt.
	Prompt string `json:"prompt,omitempty"`
	// Steps caps the model calls of a turn (0: the default).
	Steps   int  `json:"steps,omitempty"`
	Disable bool `json:"disable,omitempty"`
	Hidden  bool `json:"hidden,omitempty"`
	// Workflow is a flow of .kairocode/workflows that runs the agent's turns
	// in place of the model loop (KairoCode's, ADR 0003).
	Workflow string `json:"workflow,omitempty"`
	// Only, if not nil, are the only tools the agent is given (Claude
	// Code's tools list): the others are neither shown nor allowed.
	Only []string `json:"only,omitempty"`
	// Permission are permission rules in kairocode.json's form, each object
	// a layer after the one before (tools first, then permission, file by
	// file): of the rules that match a call, the last wins.
	Permission []json.RawMessage `json:"permission,omitempty"`
}

Agent is an agent definition (opencode's agents/*.md).

type Command

type Command struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	// Agent and Model, if set, run the command's turn.
	Agent string `json:"agent,omitempty"`
	Model string `json:"model,omitempty"`
	// Subtask asks for the command to run as a subagent (M3; for now it
	// runs as a turn of the session).
	Subtask  bool   `json:"subtask,omitempty"`
	Template string `json:"template"`
	// Hint: what to give it, for the input (Claude Code's argument-hint).
	Hint string `json:"hint,omitempty"`
	// NoShell: its !`…` are not run (Claude Code's, whose allowed-tools
	// do not allow Bash).
	NoShell bool `json:"no_shell,omitempty"`
	// Skill: not a command but a skill, run as /name (its SKILL.md is
	// the turn's instructions).
	Skill bool `json:"skill,omitempty"`
}

Command is a command definition (opencode's commands/*.md).

type Plugin

type Plugin struct {
	Name    string
	Dir     string
	Project bool
}

Plugin is a plugin's folder (ADR 0025): the user's ($XDG_CONFIG_HOME/kairocode/plugins/<name>, or ~/.config/...), or a project's (.kairocode/plugins/<name> from the repository's root down to dir).

func PluginDirs

func PluginDirs(dir string) []Plugin

PluginDirs are the plugins of dir, the user's first; a project's of a name taken comes after it, and is told apart by Project.

type Skill

type Skill struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	// Path is the SKILL.md.
	Path string `json:"path"`
}

Skill is a skill: a SKILL.md, named in its frontmatter, and the directory around it.

func (Skill) Content

func (s Skill) Content() (string, error)

Content is what the skill tool gives the model for a skill: its body, where it lives, and up to ten of its other files.

type SkillProblem

type SkillProblem struct {
	Path string `json:"path"`
	Why  string `json:"why"`
}

SkillProblem is a SKILL.md that is not taken, or a skill another of its name takes the place of, and why.

func CheckedSkills

func CheckedSkills(dirs []string) (map[string]Skill, []SkillProblem, error)

CheckedSkills is Skills, and what of them is not taken, and why: a SKILL.md that cannot be read, has no name, or a name not as opencode has it (lowercase words joined by -, at most 64 characters, the name of its directory); and a skill a later one of its name takes the place of.

type Value

type Value struct {
	Scalar string
	Quoted bool
	Keys   []string
	Map    map[string]*Value
}

Value is a frontmatter value: a scalar (Scalar, with Quoted if it was a quoted string) or a map whose keys keep their order (Keys, Map). Order matters: permission rules are matched last-first.

func Parse

func Parse(front string) (*Value, error)

Parse reads frontmatter: the YAML that opencode's definitions use in practice. Maps nest by indentation; values are plain, single- or double-quoted scalars, or block scalars (| and >); # starts a comment. Flow maps ({}), anchors and tags are refused, not misread. A list of scalars (- a, or [a, b] on one line) is taken as one scalar: the items joined by ", ", or the brackets as written (Claude Code's "tools: [Read, Grep]" and "argument-hint: [env]"). As opencode does for Claude-style frontmatter, a top-level plain value that holds ": " is taken whole.

func (*Value) Bool

func (v *Value) Bool() (bool, bool)

Bool is a scalar's truth (YAML's true/false), and whether it is one.

func (*Value) Get

func (v *Value) Get(key string) *Value

Get is the value of key, or nil.

func (*Value) Int

func (v *Value) Int() (int, bool)

Int is a scalar's integer, and whether it is one.

func (*Value) IsMap

func (v *Value) IsMap() bool

IsMap reports whether v is a map.

func (*Value) JSON

func (v *Value) JSON() json.RawMessage

JSON is v as JSON, with map keys in their order.

func (*Value) String

func (v *Value) String() string

String is a scalar's text ("" for a map or nil).

Jump to

Keyboard shortcuts

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