This repository has been archived on 2026-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
ollie-core/tools/skill_load.go

38 lines
998 B
Go

package tools
import (
"context"
"encoding/json"
"fmt"
"ollie/toolsrv"
)
// SkillLoad loads a skill into the current session.
func SkillLoad(ctx context.Context, srv *toolsrv.Server, args json.RawMessage) (string, error) {
var a struct {
Name string `json:"name"`
}
if err := json.Unmarshal(args, &a); err != nil {
return "", fmt.Errorf("skill_load: bad args: %w", err)
}
if a.Name == "" {
return "", fmt.Errorf("skill_load: name is required")
}
reg := srv.SkillsRegistry()
sid := srv.SessionID()
if reg == nil || sid == "" {
return "", fmt.Errorf("skill_load: no session registry")
}
if err := reg.Load(sid, a.Name); err != nil {
return "", fmt.Errorf("skill_load: %w", err)
}
content, err := reg.SkillContent(a.Name)
if err != nil {
return "", fmt.Errorf("skill_load: %w", err)
}
injectMsg := fmt.Sprintf("[system: loaded skill %s]\n\n%s", a.Name, content)
srv.InjectContent(injectMsg)
return fmt.Sprintf("loaded: %s (%d bytes)", a.Name, len(content)), nil
}