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 ¶
- Variables
- func Agents(dirs []string) (map[string]Agent, error)
- func Commands(dirs []string) (map[string]Command, error)
- func DefinitionDirs(dir string) []string
- func Dirs(dir string) []string
- func Expand(c Command, args, dir string, run func(cmd string) (string, error), ...) (string, error)
- func ProjectDirs(dir string) []string
- func SkillDirs(dir string) []string
- func SkillList(skills map[string]Skill) string
- func Skills(dirs []string) (map[string]Skill, error)
- func Split(md []byte) (front, body string, err error)
- type Agent
- type Command
- type Plugin
- type Skill
- type SkillProblem
- type Value
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
Commands reads the command definitions of dirs; a later file of a name replaces the fields it sets.
func DefinitionDirs ¶
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 ¶
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:
- args split into words; a quoted group is one word, its quotes cut;
- $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;
- $ARGUMENTS is args as they came;
- a template with neither gets args after it, on its own paragraph;
- each !`command` is replaced with what run prints (args can hold one: opencode runs those too);
- the text is trimmed;
- 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 ¶
ProjectDirs are the directories from the repository's root down to dir (dir alone outside a repository).
func SkillDirs ¶
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 ¶
SkillList is the list of skills for the system prompt, as opencode writes it: those with a description, by name.
func Skills ¶
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 ¶
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 ¶
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 ¶
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.
type SkillProblem ¶
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 ¶
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 ¶
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) JSON ¶
func (v *Value) JSON() json.RawMessage
JSON is v as JSON, with map keys in their order.