11package cmd
22
33import (
4- "fmt"
5- "io/ioutil"
6- "path/filepath"
7- "strings"
8- "os"
9-
10- "github.com/charmbracelet/lipgloss"
114 "github.com/spf13/cobra"
125 "github.com/spf13/viper"
13- )
14-
15- var (
16- skillHeaderStyle = lipgloss .NewStyle ().Bold (true ).Foreground (lipgloss .Color ("#00FF00" )).MarginBottom (1 )
17- skillNameStyle = lipgloss .NewStyle ().Foreground (lipgloss .Color ("#00BFFF" )).Bold (true )
18- skillDescStyle = lipgloss .NewStyle ().Foreground (lipgloss .Color ("#AAAAAA" )).PaddingLeft (4 )
6+ "github.com/QuanuX/qxctl/pkg/skills"
197)
208
219var skillsCmd = & cobra.Command {
2210 Use : "skills" ,
23- Short : "Manage and discover Agent Skills" ,
11+ Short : "QuanuX Agent Skills Registry " ,
2412 Run : func (cmd * cobra.Command , args []string ) {
2513 cmd .Help ()
2614 },
@@ -29,88 +17,20 @@ var skillsCmd = &cobra.Command{
2917var skillsListCmd = & cobra.Command {
3018 Use : "list" ,
3119 Short : "List all available agent skills" ,
32- Run : func (cmd * cobra.Command , args []string ) {
20+ RunE : func (cmd * cobra.Command , args []string ) error {
3321 baseDir := viper .GetString ("skills.skills.list.dir" )
34-
35- fmt .Println (skillHeaderStyle .Render (fmt .Sprintf ("QuanuX Global Skills Registry (Path: %s):" , baseDir )))
36-
37- found := 0
38-
39- err := filepath .Walk (baseDir , func (path string , info os.FileInfo , err error ) error {
40- if err != nil {
41- return nil
42- }
43- if info .IsDir () && (info .Name () == ".git" || info .Name () == "venv" || info .Name () == "node_modules" || info .Name () == "__pycache__" ) {
44- return filepath .SkipDir
45- }
46-
47- nameLower := strings .ToLower (info .Name ())
48- if ! info .IsDir () && (nameLower == "skill.md" || nameLower == "skills.md" ) {
49- skillName := filepath .Base (filepath .Dir (path ))
50-
51- fmt .Println (skillNameStyle .Render ("► " + strings .ReplaceAll (strings .Title (skillName ), "_" , " " )))
52-
53- content , _ := ioutil .ReadFile (path )
54- lines := strings .Split (string (content ), "\n " )
55- desc := "No description provided."
56- for _ , line := range lines {
57- if strings .HasPrefix (line , "description: " ) {
58- desc = strings .TrimPrefix (line , "description: " )
59- break
60- }
61- }
62-
63- fmt .Println (skillDescStyle .Render (desc ) + "\n " )
64- found ++
65- }
66- return nil
67- })
68-
69- if err != nil {
70- fmt .Printf ("Error walking skills directory: %v\n " , err )
71- return
72- }
73-
74- if found == 0 {
75- fmt .Println ("No active skills mapped in the directory." )
76- } else {
77- fmt .Println (skillHeaderStyle .Render (fmt .Sprintf ("%d Active Skills Loaded." , found )))
78- }
22+ return skills .ListSkills (baseDir )
7923 },
8024}
8125
8226var skillsReadCmd = & cobra.Command {
8327 Use : "read [skill_name]" ,
84- Short : "Read the content of a specific skill" ,
28+ Short : "Read the SKILL.md for a specific skill" ,
8529 Args : cobra .ExactArgs (1 ),
86- Run : func (cmd * cobra.Command , args []string ) {
30+ RunE : func (cmd * cobra.Command , args []string ) error {
8731 skillName := args [0 ]
8832 baseDir := viper .GetString ("skills.skills.read.dir" )
89-
90- var foundPath string
91- _ = filepath .Walk (baseDir , func (path string , info os.FileInfo , err error ) error {
92- if err != nil {
93- return nil
94- }
95- if info .IsDir () && (info .Name () == ".git" || info .Name () == "venv" || info .Name () == "node_modules" || info .Name () == "__pycache__" ) {
96- return filepath .SkipDir
97- }
98- nameLower := strings .ToLower (info .Name ())
99- if ! info .IsDir () && (nameLower == "skill.md" || nameLower == "skills.md" ) && filepath .Base (filepath .Dir (path )) == skillName {
100- foundPath = path
101- }
102- return nil
103- })
104-
105- if foundPath == "" {
106- fmt .Printf ("Error: Could not find skill '%s' in any directory.\n " , skillName )
107- return
108- }
109-
110- content , _ := ioutil .ReadFile (foundPath )
111-
112- fmt .Println (skillHeaderStyle .Render (fmt .Sprintf ("--- %s ---\n " , strings .ToUpper (skillName ))))
113- fmt .Println (string (content ))
33+ return skills .ReadSkill (baseDir , skillName )
11434 },
11535}
11636
@@ -125,4 +45,3 @@ func init() {
12545 skillsReadCmd .Flags ().String ("dir" , "." , "Base directory to crawl" )
12646 viper .BindPFlag ("skills.skills.read.dir" , skillsReadCmd .Flags ().Lookup ("dir" ))
12747}
128-
0 commit comments