usercommands

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package usercommands loads user-defined slash commands from markdown files.

A user drops a file at `.zero/commands/<name>.md` (project, checked into the repo and shared with the team) or `<userConfigDir>/zero/commands/<name>.md` (personal), with optional YAML-style frontmatter:

---
description: Open a PR for the current branch
model: claude-sonnet-4.5
---
Create a pull request for the current branch. Title: $1. Summarize: $ARGUMENTS

Typing `/<name> some args` expands the body template ($ARGUMENTS, $1..$N) and submits it as a normal prompt. This turns Zero's model-pulled skills into user-invokable, repo-checked-in team workflows. Project commands override user commands of the same name (mirrors the specialist scope precedence).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Expand

func Expand(template, args string) string

Expand substitutes the argument placeholders in a command template:

$ARGUMENTS      → all args, space-joined (the whole arg string)
$1 .. $9        → the Nth whitespace-separated positional arg ("" if absent)
$$              → a literal "$"

A template with no placeholders is returned with the raw arg string appended on its own line, so a trivial command still receives the user's input.

Types

type Command

type Command struct {
	Name        string // the `/name` (file basename, lowercased, sans .md)
	Description string // frontmatter `description:`, for help + autocomplete
	Model       string // optional frontmatter `model:` override
	Agent       string // optional frontmatter `agent:`/`mode:` routing
	Template    string // the markdown body, expanded on invocation
	Path        string // source file, for diagnostics
	Project     bool   // true if from the project `.zero/commands` dir
}

Command is a user-defined slash command parsed from a markdown file.

func Load

func Load(paths Paths) []Command

Load reads every `*.md` command file under the given paths and returns them keyed by lowercased name, sorted by name. A project command shadows a user command of the same name. Unreadable files are skipped (best-effort); directories that do not exist are simply empty.

type Paths

type Paths struct {
	ProjectDir string
	UserDir    string
}

Paths are the directories scanned for command files, project first.

func DefaultPaths

func DefaultPaths(workspaceRoot, userConfigDir string) Paths

DefaultPaths returns the project and user command directories. workspaceRoot is the repo root; userConfigDir is the OS config dir (os.UserConfigDir).

Jump to

Keyboard shortcuts

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