81d6af04c2
Claude stages always get the Skill tool (bare Skill allow rule) and no longer pass --disable-slash-commands or the disableBundledSkills settings layer, so Claude Code's bundled skills are available. --setting-sources "" stays, so the operator's personal (~/.claude/skills), claude.ai synced and enabled-plugin skill folders are discovered per visit and passed as generated skills-only session plugins (plugin.json plus skills/<name> symlinks; no hooks, MCP servers or commands) after the skills block's own plugin. The ambient-skill stream guard is removed. Pi stages keep --no-skills (Pi's own discovery) and add --skill for each block skill, then each operator skill folder, with read access to those folders. OpenCode tool-using stages allow OpenCode's own skill tool for exactly the personal and synced Claude skill names it discovers, plus external_directory reads of their folders. Bundled Claude Code skills have no folder and stay unavailable to Pi and OpenCode (documented). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
115 lines
3.3 KiB
Go
115 lines
3.3 KiB
Go
package stage
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/skills"
|
|
)
|
|
|
|
// SkillRef is one entry of a model stage's `skills` block: a server skill
|
|
// library name, pinned to Version when it is positive and otherwise resolved to
|
|
// the library's latest version when the run starts.
|
|
type SkillRef struct {
|
|
Name string
|
|
Version int
|
|
}
|
|
|
|
// String renders the entry as written in a definition: name or name@N.
|
|
func (r SkillRef) String() string {
|
|
if r.Version > 0 {
|
|
return r.Name + "@" + strconv.Itoa(r.Version)
|
|
}
|
|
return r.Name
|
|
}
|
|
|
|
// ParseSkillRef parses one `name` or `name@N` entry. N must be a positive
|
|
// integer without sign or leading zeros.
|
|
func ParseSkillRef(text string) (SkillRef, error) {
|
|
text = strings.TrimSpace(text)
|
|
name, version, pinned := strings.Cut(text, "@")
|
|
if err := skills.ValidateName(name); err != nil {
|
|
return SkillRef{}, fmt.Errorf("invalid skill %q: %w", text, err)
|
|
}
|
|
ref := SkillRef{Name: name}
|
|
if pinned {
|
|
n, err := strconv.Atoi(version)
|
|
if err != nil || n <= 0 || strconv.Itoa(n) != version {
|
|
return SkillRef{}, fmt.Errorf("invalid skill %q: the version after @ must be a positive integer", text)
|
|
}
|
|
ref.Version = n
|
|
}
|
|
return ref, nil
|
|
}
|
|
|
|
// SkillRefs parses a model stage's optional `skills` block, one entry per
|
|
// line. An absent or empty block configures no skills. A skill may appear
|
|
// only once, pinned or not.
|
|
func SkillRefs(def Definition) ([]SkillRef, error) {
|
|
text, present := def.Blocks["skills"]
|
|
if !present {
|
|
return nil, nil
|
|
}
|
|
var refs []SkillRef
|
|
seen := map[string]bool{}
|
|
for _, line := range strings.Split(text, "\n") {
|
|
if strings.TrimSpace(line) == "" {
|
|
continue
|
|
}
|
|
ref, err := ParseSkillRef(line)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if seen[ref.Name] {
|
|
return nil, fmt.Errorf("duplicate skill %s", ref.Name)
|
|
}
|
|
seen[ref.Name] = true
|
|
refs = append(refs, ref)
|
|
}
|
|
return refs, nil
|
|
}
|
|
|
|
// errSkillsModelOnly is the clear diagnostic for a skills block on a stage that
|
|
// has no model session to load skills into.
|
|
func errSkillsModelOnly(kind string) error {
|
|
return fmt.Errorf("skills blocks are supported only on model stages, not %s stages", kind)
|
|
}
|
|
|
|
// ClaudeSkillPlugin is the name of the per-visit plugin a Claude stage's
|
|
// configured skills are loaded from; Claude Code names its skills
|
|
// ClaudeSkillPlugin:<skill>.
|
|
const ClaudeSkillPlugin = "pipelines-stage"
|
|
|
|
// SkillBundle is one resolved skill copied for a single stage visit. Dir holds
|
|
// the bundle (SKILL.md and its references/, scripts/ and assets/).
|
|
type SkillBundle struct {
|
|
Name string
|
|
Version int
|
|
Dir string
|
|
}
|
|
|
|
// SkillSet is the runtime-provided skill material for one model visit. Root is
|
|
// the visit's private skills directory: it is also a Claude Code plugin root
|
|
// (.claude-plugin/plugin.json) whose skills/<name>/ entries are the bundles.
|
|
// A nil or empty set means the stage configured no skills.
|
|
type SkillSet struct {
|
|
Root string
|
|
Bundles []SkillBundle
|
|
}
|
|
|
|
// Empty reports whether the set configures no skills.
|
|
func (s *SkillSet) Empty() bool { return s == nil || len(s.Bundles) == 0 }
|
|
|
|
// Names lists name@version for every bundle, in definition order.
|
|
func (s *SkillSet) Names() []string {
|
|
if s.Empty() {
|
|
return nil
|
|
}
|
|
names := make([]string, 0, len(s.Bundles))
|
|
for _, b := range s.Bundles {
|
|
names = append(names, b.Name+"@"+strconv.Itoa(b.Version))
|
|
}
|
|
return names
|
|
}
|