| 1 | package skill |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "sync" |
| 6 | |
| 7 | "reasonix/internal/skill/builtincontent" |
| 8 | ) |
| 9 | |
| 10 | var ( |
| 11 | embeddedOnce sync.Once |
| 12 | embeddedSkills []Skill |
| 13 | embeddedErr error |
| 14 | ) |
| 15 | |
| 16 | // loadEmbeddedBuiltins returns skills compiled into the binary via go:embed. |
| 17 | // Failures are sticky for the process so a corrupt embed fails loudly once. |
| 18 | func loadEmbeddedBuiltins() []Skill { |
| 19 | embeddedOnce.Do(func() { |
| 20 | items, err := builtincontent.All() |
| 21 | if err != nil { |
| 22 | embeddedErr = err |
| 23 | return |
| 24 | } |
| 25 | out := make([]Skill, 0, len(items)) |
| 26 | for _, item := range items { |
| 27 | out = append(out, skillFromEmbedded(item)) |
| 28 | } |
| 29 | embeddedSkills = out |
| 30 | }) |
| 31 | if embeddedErr != nil { |
| 32 | // Panic in development/tests; production binaries always ship valid embeds. |
| 33 | panic(fmt.Sprintf("embedded builtin skills: %v", embeddedErr)) |
| 34 | } |
| 35 | return append([]Skill(nil), embeddedSkills...) |
| 36 | } |
| 37 | |
| 38 | func skillFromEmbedded(item builtincontent.SkillMarkdown) Skill { |
| 39 | return Skill{ |
| 40 | Name: item.Name, |
| 41 | Description: item.Description, |
| 42 | Body: item.Body, |
| 43 | Scope: ScopeBuiltin, |
| 44 | Path: "(builtin:" + item.Path + ")", |
| 45 | RunAs: parseRunAs(item.RunAs, item.Context, item.Agent), |
| 46 | } |
| 47 | } |
| 48 |