mirror of
https://github.com/hanzoai/agent.git
synced 2026-09-11 21:08:51 +00:00
The bulk rename from agentfield to hanzo-agents introduced hyphens into Go variable names (e.g. hanzo-agentsHome), which are not valid Go identifiers. Fixed 361 occurrences across 36 files to use camelCase (e.g. hanzoAgentsHome). String literals like ".hanzo-agents" are preserved as-is.
83 lines
2.1 KiB
Go
83 lines
2.1 KiB
Go
package cli
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/hanzoai/agents/control-plane/internal/packages"
|
|
"github.com/spf13/cobra"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
// NewListCommand creates the list command
|
|
func NewListCommand() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "list",
|
|
Short: "List installed HanzoAgents agent node packages",
|
|
Long: `Display all installed HanzoAgents agent node packages with their status.
|
|
|
|
Shows package name, version, status (running/stopped), and port if running.
|
|
|
|
Examples:
|
|
af list`,
|
|
Run: runListCommand,
|
|
}
|
|
|
|
return cmd
|
|
}
|
|
|
|
func runListCommand(cmd *cobra.Command, args []string) {
|
|
hanzoAgentsHome := getHanzoAgentsHomeDir()
|
|
registryPath := filepath.Join(hanzoAgentsHome, "installed.yaml")
|
|
|
|
// Load registry
|
|
registry := &packages.InstallationRegistry{
|
|
Installed: make(map[string]packages.InstalledPackage),
|
|
}
|
|
|
|
if data, err := os.ReadFile(registryPath); err == nil {
|
|
if err := yaml.Unmarshal(data, registry); err != nil {
|
|
cmd.PrintErrf("failed to parse registry: %v\n", err)
|
|
return
|
|
}
|
|
} else if !errors.Is(err, os.ErrNotExist) {
|
|
cmd.PrintErrf("failed to read registry: %v\n", err)
|
|
return
|
|
}
|
|
|
|
if len(registry.Installed) == 0 {
|
|
fmt.Println("đĻ No agent node packages installed")
|
|
fmt.Println("đĄ Install packages with: hanzo-agents install <package-path>")
|
|
return
|
|
}
|
|
|
|
fmt.Printf("đĻ Installed Agent Node Packages (%d total):\n\n", len(registry.Installed))
|
|
|
|
for name, pkg := range registry.Installed {
|
|
status := pkg.Status
|
|
statusIcon := "âšī¸"
|
|
if status == "running" {
|
|
statusIcon = "đĸ"
|
|
} else if status == "error" {
|
|
statusIcon = "đ´"
|
|
}
|
|
|
|
fmt.Printf("%s %s (v%s)\n", statusIcon, name, pkg.Version)
|
|
fmt.Printf(" %s\n", pkg.Description)
|
|
|
|
if status == "running" && pkg.Runtime.Port != nil {
|
|
fmt.Printf(" đ Running on port %d (PID: %d)\n", *pkg.Runtime.Port, *pkg.Runtime.PID)
|
|
}
|
|
|
|
fmt.Printf(" đ %s\n", pkg.Path)
|
|
fmt.Println()
|
|
}
|
|
|
|
fmt.Println("đĄ Commands:")
|
|
fmt.Println(" af run <name> - Start an agent node")
|
|
fmt.Println(" af stop <name> - Stop a running agent node")
|
|
fmt.Println(" af logs <name> - View agent node logs")
|
|
}
|