71 lines
1.9 KiB
Go
71 lines
1.9 KiB
Go
package skill
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/samcharles93/archie-core/internal/tools"
|
|
)
|
|
|
|
// ActivateTool returns a single skill_activate tool over catalog, or nil when
|
|
// the catalog is empty.
|
|
func ActivateTool(dir string, catalog []CatalogEntry) *tools.ToolEntry {
|
|
if len(catalog) == 0 {
|
|
return nil
|
|
}
|
|
|
|
names := make([]any, len(catalog))
|
|
descByName := make(map[string]string, len(catalog))
|
|
dirByName := make(map[string]string, len(catalog))
|
|
rootByName := make(map[string]string, len(catalog))
|
|
bodyByName := make(map[string]string, len(catalog))
|
|
for i, e := range catalog {
|
|
bodyByName[e.Name] = e.Body
|
|
names[i] = e.Name
|
|
descByName[e.Name] = e.Description
|
|
dirByName[e.Name] = e.Dir
|
|
if e.Root != "" {
|
|
rootByName[e.Name] = e.Root
|
|
}
|
|
}
|
|
|
|
return &tools.ToolEntry{
|
|
Name: "skill_activate",
|
|
Toolset: "skill",
|
|
Description: "Load the full instructions for a named skill. Call this before attempting a task a cataloged skill covers.",
|
|
Schema: tools.JSONSchema{
|
|
"type": "object",
|
|
"properties": map[string]any{
|
|
"name": map[string]any{
|
|
"type": "string",
|
|
"description": "The skill name to activate, from the catalog below.",
|
|
"enum": names,
|
|
},
|
|
},
|
|
"required": []any{"name"},
|
|
},
|
|
Handler: func(_ context.Context, input map[string]any) (any, error) {
|
|
name, _ := input["name"].(string)
|
|
if name == "" {
|
|
return nil, fmt.Errorf("skill_activate: %q is required", "name")
|
|
}
|
|
skillDir, ok := dirByName[name]
|
|
if !ok {
|
|
return nil, fmt.Errorf("skill_activate: unknown skill %q", name)
|
|
}
|
|
if body := bodyByName[name]; body != "" {
|
|
return body, nil
|
|
}
|
|
root := dir
|
|
if catalogRoot := rootByName[name]; catalogRoot != "" {
|
|
root = catalogRoot
|
|
}
|
|
body := LoadBody(root, skillDir)
|
|
if body == "" {
|
|
return nil, fmt.Errorf("skill_activate: %q has no body (SKILL.md missing or empty)", name)
|
|
}
|
|
return body, nil
|
|
},
|
|
}
|
|
}
|