package main
import (
"fmt"
"path/filepath"
"strings"
"github.com/spf13/cobra"
"github.com/sgx-labs/statelessagent/internal/config"
"github.com/sgx-labs/statelessagent/internal/hooks"
)
func pluginCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "plugin",
Short: "Manage hook extensions",
}
cmd.AddCommand(&cobra.Command{
Use: "list",
Short: "List registered plugins",
RunE: func(cmd *cobra.Command, args []string) error {
plugins := hooks.LoadPlugins()
if len(plugins) == 0 {
pluginsPath := filepath.Join(config.VaultPath(), ".same", "plugins.json")
fmt.Printf("No plugins registered.\n")
fmt.Printf("Create %s to add custom hooks.\n\n", pluginsPath)
fmt.Println("Example plugins.json:")
fmt.Println(`{
"plugins": [
{
"name": "my-custom-hook",
"event": "UserPromptSubmit",
"command": "/path/to/script.sh",
"args": [],
"timeout_ms": 5000,
"enabled": true
}
]
}`)
return nil
}
fmt.Println("Registered plugins:")
for _, p := range plugins {
status := "enabled"
if !p.Enabled {
status = "disabled"
}
fmt.Printf(" %-20s event=%-20s %s %s %s\n",
p.Name, p.Event, status, p.Command, strings.Join(p.Args, " "))
}
return nil
},
})
return cmd
}