bb1e11f456
Añade pkg/command/prompts.go para cargar prompts desde archivos .md externos en el directorio prompts/. Mejoras en agents/runtime.go para el manejo de herramientas y flujo de ejecución. Nuevos comandos en agents/commands.go. Ajustes menores en pkg/command/builtins.go para integrar las nuevas capacidades. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package command
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// PromptCommand maps a command name to its prompt content loaded from a .md file.
|
|
type PromptCommand struct {
|
|
Name string // filename without .md extension
|
|
Content string // file content (the prompt text)
|
|
}
|
|
|
|
// LoadPromptCommands scans dir for .md files and returns one PromptCommand per file.
|
|
// Returns nil (no error) if the directory does not exist.
|
|
func LoadPromptCommands(dir string) ([]PromptCommand, error) {
|
|
entries, err := os.ReadDir(dir)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
return nil, nil
|
|
}
|
|
return nil, err
|
|
}
|
|
|
|
var prompts []PromptCommand
|
|
for _, e := range entries {
|
|
if e.IsDir() || !strings.HasSuffix(e.Name(), ".md") {
|
|
continue
|
|
}
|
|
data, err := os.ReadFile(filepath.Join(dir, e.Name()))
|
|
if err != nil {
|
|
continue
|
|
}
|
|
name := strings.TrimSuffix(e.Name(), ".md")
|
|
prompts = append(prompts, PromptCommand{
|
|
Name: name,
|
|
Content: strings.TrimSpace(string(data)),
|
|
})
|
|
}
|
|
return prompts, nil
|
|
}
|
|
|
|
// ExpandPrompt builds the final message by concatenating the prompt content
|
|
// with any extra arguments the user provided after the command.
|
|
func ExpandPrompt(content string, args []string) string {
|
|
if len(args) == 0 {
|
|
return content
|
|
}
|
|
return content + "\n\n" + strings.Join(args, " ")
|
|
}
|