feat: sistema de prompts externos y mejoras en runtime de agentes
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>
This commit is contained in:
@@ -39,6 +39,11 @@ func Builtins() []Spec {
|
||||
Description: "Limpia ventana de conversacion del room actual",
|
||||
Usage: "!clear",
|
||||
},
|
||||
{
|
||||
Name: "prompts",
|
||||
Description: "Lista prompt-commands disponibles (archivos .md en prompts/)",
|
||||
Usage: "!prompts",
|
||||
},
|
||||
{
|
||||
Name: "version",
|
||||
Aliases: []string{"v"},
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
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, " ")
|
||||
}
|
||||
Reference in New Issue
Block a user