List 列出所有可用命令
(ctx context.Context)
| 101 | |
| 102 | // List 列出所有可用命令 |
| 103 | func (cl *CommandLoader) List(ctx context.Context) ([]string, error) { |
| 104 | // 使用 Glob 匹配所有 .md 文件 |
| 105 | pattern := "*.md" |
| 106 | files, err := cl.fs.Glob(ctx, pattern, &sandbox.GlobOptions{ |
| 107 | CWD: cl.baseDir, |
| 108 | Absolute: false, |
| 109 | }) |
| 110 | if err != nil { |
| 111 | return nil, fmt.Errorf("glob commands: %w", err) |
| 112 | } |
| 113 | |
| 114 | commands := make([]string, 0, len(files)) |
| 115 | for _, file := range files { |
| 116 | // 去掉 .md 后缀 |
| 117 | name := strings.TrimSuffix(filepath.Base(file), ".md") |
| 118 | commands = append(commands, name) |
| 119 | } |
| 120 | |
| 121 | return commands, nil |
| 122 | } |
| 123 | |
| 124 | // LoadLocal 从本地文件系统加载(用于开发) |
| 125 | func LoadLocal(baseDir, commandName string) (*CommandDefinition, error) { |