feat: complete swarm engine implementation
1. Implemented missing /swarm status and /swarm viz commands. 2. Made DelegateTool roles dynamic based on configuration. 3. Aligned codebase with README documentation.
This commit is contained in:
parent
6bdf30a777
commit
5bfea8687a
2 changed files with 39 additions and 3 deletions
|
|
@ -31,13 +31,21 @@ func (t *DelegateTool) Description() string {
|
|||
}
|
||||
|
||||
func (t *DelegateTool) Parameters() map[string]interface{} {
|
||||
roles := make([]string, 0)
|
||||
for roleName := range t.orchestrator.config.Roles {
|
||||
roles = append(roles, roleName)
|
||||
}
|
||||
if len(roles) == 0 {
|
||||
roles = []string{"Researcher", "Analyst", "Writer", "Critic"} // Fallback
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"type": "object",
|
||||
"properties": map[string]interface{}{
|
||||
"role": map[string]interface{}{
|
||||
"type": "string",
|
||||
"description": "The role of the worker (Researcher, Analyst, Writer, Critic)",
|
||||
"enum": []string{"Researcher", "Analyst", "Writer", "Critic"},
|
||||
"description": "The role of the worker to spawn",
|
||||
"enum": roles,
|
||||
},
|
||||
"task": map[string]interface{}{
|
||||
"type": "string",
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ func (s *Service) listen() {
|
|||
|
||||
func (s *Service) HandleCommand(ctx context.Context, input string) string {
|
||||
args := strings.Fields(input)
|
||||
if len(args) < 2 { return "Usage: /swarm <spawn|list|stop> [goal]" }
|
||||
if len(args) < 2 { return "Usage: /swarm <spawn|list|stop|status|viz> [goal/id]" }
|
||||
|
||||
switch args[1] {
|
||||
case "spawn":
|
||||
|
|
@ -80,6 +80,34 @@ func (s *Service) HandleCommand(ctx context.Context, input string) string {
|
|||
if len(args) < 3 { return "ID required" }
|
||||
s.Orchestrator.StopSwarm(core.SwarmID(args[2]))
|
||||
return "Stopped."
|
||||
case "status":
|
||||
if len(args) < 3 { return "ID required" }
|
||||
sid := core.SwarmID(args[2])
|
||||
sw, err := s.Store.GetSwarm(ctx, sid)
|
||||
if err != nil { return "Swarm not found" }
|
||||
nodes, _ := s.Store.GetSwarmNodes(ctx, sid)
|
||||
|
||||
out := fmt.Sprintf("📊 Swarm Status: %s\nGoal: %s\nNodes (%d):\n", sw.Status, sw.Goal, len(nodes))
|
||||
for _, n := range nodes {
|
||||
out += fmt.Sprintf("- [%s] %s: %s (%s)\n", n.ID[:4], n.Role.Name, n.Status, n.Task)
|
||||
}
|
||||
return out
|
||||
case "viz":
|
||||
if len(args) < 3 { return "ID required" }
|
||||
sid := core.SwarmID(args[2])
|
||||
nodes, _ := s.Store.GetSwarmNodes(ctx, sid)
|
||||
if len(nodes) == 0 { return "No nodes found" }
|
||||
|
||||
out := "```mermaid\ngraph TD\n"
|
||||
for _, n := range nodes {
|
||||
nodeLabel := fmt.Sprintf("%s[%s: %s]", n.ID[:8], n.Role.Name, n.Status)
|
||||
out += fmt.Sprintf(" %s\n", nodeLabel)
|
||||
if n.ParentID != "" {
|
||||
out += fmt.Sprintf(" %s --> %s\n", n.ParentID[:8], n.ID[:8])
|
||||
}
|
||||
}
|
||||
out += "```"
|
||||
return out
|
||||
}
|
||||
return "Unknown command"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue