Documentation
¶
Overview ¶
Package skillgen generates agent skill files from a cobra command tree.
The default output is a single Markdown file with YAML frontmatter that describes the whole CLI — name, description, and a section per subcommand. A large CLI can opt into split mode (one skill per leaf command) but that is not yet implemented.
Typical integration mirrors cobra's own completion command:
root.AddCommand(skillgen.NewSkillsCmd(root))
See PRD.md in the repository root for the full design.
Index ¶
Constants ¶
const ( // AnnotationTrigger adds trigger phrases to the skill's description. // // Two forms are accepted: // // - Fragment (preferred): "deploy, promote, ship a service". The // library wraps it into "Use when the user asks to <fragment>." // - Full sentence: "Use when the user asks to deploy the service." // (case-insensitive prefix detection). Used as-is. // // Trailing punctuation is normalized so both forms produce a single // terminating period. AnnotationTrigger = "skill.trigger" // AnnotationDescription replaces the generated description wholesale. AnnotationDescription = "skill.description" // AnnotationName overrides the skill's name. In single-skill mode, only // the root command's annotation is consulted. AnnotationName = "skill.name" // AnnotationSkip, when set to "true", excludes the command and its subtree. AnnotationSkip = "skill.skip" // AnnotationExamples appends free-form example text to a command's body section. AnnotationExamples = "skill.examples" // AnnotationAvoid is free-form Markdown that appears under an "Avoid" // heading. Use it to tell the agent what not to do — the single highest- // value content in most real skills. AnnotationAvoid = "skill.avoid" // AnnotationPreferOver is free-form Markdown that appears under a "Prefer // over" heading. Use it to point the agent away from alternative tools or // commands this one supersedes (e.g. "Use instead of raw `kubectl delete`"). AnnotationPreferOver = "skill.prefer-over" // AnnotationAllowedTools populates the Claude Code `allowed-tools` // frontmatter field (comma- or space-separated list of tool names, e.g. // "Bash, Read, Edit"). Only emitted under TargetClaudeCode. AnnotationAllowedTools = "skill.allowed-tools" // AnnotationLicense populates the agentskills.io `license` frontmatter // field. Kept short per the spec — either a SPDX name ("Apache-2.0") or a // reference to a bundled license file ("LICENSE.txt has complete terms"). AnnotationLicense = "skill.license" // AnnotationCompatibility populates the agentskills.io `compatibility` // frontmatter field (max 500 chars). Only use it when the skill has // specific environment requirements. AnnotationCompatibility = "skill.compatibility" // AnnotationMetadataPrefix is the prefix for arbitrary metadata entries // that populate the agentskills.io `metadata:` frontmatter map. Set // cmd.Annotations["skill.metadata.<key>"] = "<value>" for each entry. AnnotationMetadataPrefix = "skill.metadata." )
Annotation keys an author can set on a cobra.Command to shape its skill output.
Variables ¶
This section is empty.
Functions ¶
func NewSkillsCmd ¶
NewSkillsCmd returns a `skills` subcommand authors can attach to their root command, analogous to cobra's `completion`. It exposes:
- `skills generate --dir <path>` — write skill files to disk.
- `skills print` — write the skill(s) to stdout.
The same opts apply to both subcommands. The returned command is marked with skill.skip so it never appears in its own generated skill.
Types ¶
type CommandData ¶
type CommandData struct {
Name string // leaf name, e.g. "deploy"
Path string // full path, e.g. "mytool deploy"
UseLine string // cobra's UseLine, e.g. "mytool deploy <service>"
Short string
Long string
Example string
Aliases []string // cobra.Command.Aliases
Deprecated string // cobra.Command.Deprecated (empty if not deprecated)
Flags []FlagData
Avoid string // skill.avoid annotation contents
PreferOver string // skill.prefer-over annotation contents
Extra string // skill.examples annotation contents
Depth int // 1 for direct child of root, 2 for grandchild, ...
HasSubs bool // true if this command has at least one visible subcommand
// identical local flag sets. The parent's section emits these once and
// each child's section skips its local-flags block to avoid duplication.
SharedChildrenFlags []FlagData
// SkipFlagsInRender is set on children whose parent owns the shared-flags
// block — render suppresses the per-child "Flags:" list in that case.
SkipFlagsInRender bool
}
CommandData describes one cobra command for rendering.
type FlagData ¶
type FlagData struct {
Name string
Shorthand string
Type string
DefValue string
Usage string
Required bool
Persistent bool
}
FlagData describes one pflag.Flag.
type FrontmatterField ¶ added in v0.4.0
type FrontmatterField struct {
Key string
Value string
Map map[string]string // when non-nil, Value is ignored
}
FrontmatterField is a frontmatter key/value emitted alongside name + description. A scalar field uses Value; a map field (e.g. the spec `metadata:` key) uses Map. Exactly one of Value and Map should be set.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator emits skills for a cobra command tree.
func (*Generator) Lint ¶ added in v0.3.0
Lint walks the command tree and lints the resulting skills. Findings combine two passes:
- Cobra-tree rules ("cmd-*") that inspect cobra metadata — these produce findings keyed by command path, which is more actionable for authors than the generated skill path.
- Spec-compliance rules from the skilllint library, run against each generated skill's bytes. These cover name format, description length, body size, vague descriptions, and so on.
The generator's skip rules (Hidden, skill.skip, WithSkip predicate, cobra builtins) apply in both passes so lint stays in sync with what the generator would actually emit.
type Option ¶
type Option func(*Generator)
Option configures a Generator.
func WithFilenamePrefix ¶
WithFilenamePrefix prepends a prefix to every generated filename.
func WithIncludeBuiltins ¶
func WithIncludeBuiltins() Option
WithIncludeBuiltins keeps cobra's auto-injected `help` and `completion` commands in the output. They are excluded by default because agents don't need them to use the tool.
func WithOverview ¶
WithOverview controls whether an overview skill is emitted in split mode. Has no effect in SplitNone.
func WithSkip ¶
WithSkip installs a predicate that excludes commands (and their subtrees). Runs in addition to Hidden and the skill.skip annotation.
func WithTarget ¶ added in v0.4.0
WithTarget selects which host's frontmatter conventions to follow. Default is TargetGeneric (strict name + description).
func WithTemplate ¶
WithTemplate replaces the default body renderer with a text/template. The template receives a TemplateData value.
type Skill ¶
type Skill struct {
Name string
Description string
Body string
// Path is the relative file path within the output directory, e.g.
// "mytool/SKILL.md". Use filepath.Dir(Path) to get the skill directory.
Path string
// Frontmatter is spec-standard and target-specific frontmatter fields
// emitted after name + description.
Frontmatter []FrontmatterField
}
Skill is a single generated skill file. The spec layout is a directory named after the skill with a SKILL.md inside; Path is the relative path used by WriteTo (always `<name>/SKILL.md` with the FilenamePrefix applied to the directory name).
type Target ¶ added in v0.4.0
type Target int
Target controls which host's conventions the generated frontmatter follows. Hosts vary in which optional fields they support; TargetGeneric stays strict (name + description only) while richer targets opt in to host-specific keys.
type TemplateData ¶
type TemplateData struct {
Name string
Description string
// TriggerClause is the "Use when the user asks to …" sentence alone,
// separate from Description (which embeds it). Empty when no trigger
// signal is available — renderers must omit the "When to use" section
// in that case rather than restating Description.
TriggerClause string
Root CommandData
Commands []CommandData // flattened, depth-first, sorted by name at each level; root not included
}
TemplateData is the value passed to a custom template via WithTemplate.