mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-13 05:37:29 +08:00
Enhance spec-driven coding workflow
This commit is contained in:
@@ -1226,8 +1226,36 @@ func (s *Server) webUINodesPayload(ctx context.Context) map[string]interface{} {
|
||||
if s.mgr != nil {
|
||||
list = s.mgr.List()
|
||||
}
|
||||
localRegistry := s.fetchRegistryItems(ctx)
|
||||
localAgents := make([]nodes.AgentInfo, 0, len(localRegistry))
|
||||
for _, item := range localRegistry {
|
||||
agentID := strings.TrimSpace(stringFromMap(item, "agent_id"))
|
||||
if agentID == "" {
|
||||
continue
|
||||
}
|
||||
localAgents = append(localAgents, nodes.AgentInfo{
|
||||
ID: agentID,
|
||||
DisplayName: strings.TrimSpace(stringFromMap(item, "display_name")),
|
||||
Role: strings.TrimSpace(stringFromMap(item, "role")),
|
||||
Type: strings.TrimSpace(stringFromMap(item, "type")),
|
||||
Transport: fallbackString(strings.TrimSpace(stringFromMap(item, "transport")), "local"),
|
||||
})
|
||||
}
|
||||
host, _ := os.Hostname()
|
||||
local := nodes.NodeInfo{ID: "local", Name: "local", Endpoint: "gateway", Version: gatewayBuildVersion(), LastSeenAt: time.Now(), Online: true}
|
||||
local := nodes.NodeInfo{
|
||||
ID: "local",
|
||||
Name: "local",
|
||||
Endpoint: "gateway",
|
||||
Version: gatewayBuildVersion(),
|
||||
OS: runtime.GOOS,
|
||||
Arch: runtime.GOARCH,
|
||||
LastSeenAt: time.Now(),
|
||||
Online: true,
|
||||
Capabilities: nodes.Capabilities{Run: true, Invoke: true, Model: true, Camera: true, Screen: true, Location: true, Canvas: true},
|
||||
Actions: []string{"run", "agent_task", "camera_snap", "camera_clip", "screen_snapshot", "screen_record", "location_get", "canvas_snapshot", "canvas_action"},
|
||||
Models: []string{"local-sim"},
|
||||
Agents: localAgents,
|
||||
}
|
||||
if strings.TrimSpace(host) != "" {
|
||||
local.Name = host
|
||||
}
|
||||
|
||||
@@ -486,6 +486,59 @@ func TestHandleWebUINodesIncludesP2PSummary(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleWebUINodesEnrichesLocalNodeMetadata(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
srv := NewServer("127.0.0.1", 0, "", nodes.NewManager())
|
||||
srv.SetSubagentHandler(func(ctx context.Context, action string, args map[string]interface{}) (interface{}, error) {
|
||||
if action != "registry" {
|
||||
return map[string]interface{}{"items": []map[string]interface{}{}}, nil
|
||||
}
|
||||
return map[string]interface{}{
|
||||
"items": []map[string]interface{}{
|
||||
{
|
||||
"agent_id": "coder",
|
||||
"display_name": "Code Agent",
|
||||
"role": "coding",
|
||||
"type": "worker",
|
||||
"transport": "local",
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
})
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/webui/api/nodes", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
srv.handleWebUINodes(rec, req)
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("expected 200, got %d", rec.Code)
|
||||
}
|
||||
|
||||
var body map[string]interface{}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
|
||||
t.Fatalf("decode body: %v", err)
|
||||
}
|
||||
items, _ := body["nodes"].([]interface{})
|
||||
if len(items) == 0 {
|
||||
t.Fatalf("expected local node in payload")
|
||||
}
|
||||
local, _ := items[0].(map[string]interface{})
|
||||
if strings.TrimSpace(fmt.Sprint(local["id"])) != "local" {
|
||||
t.Fatalf("expected first node to be local, got %+v", local)
|
||||
}
|
||||
if strings.TrimSpace(fmt.Sprint(local["os"])) == "" || strings.TrimSpace(fmt.Sprint(local["arch"])) == "" {
|
||||
t.Fatalf("expected local os/arch, got %+v", local)
|
||||
}
|
||||
actions, _ := local["actions"].([]interface{})
|
||||
if len(actions) == 0 {
|
||||
t.Fatalf("expected local actions, got %+v", local)
|
||||
}
|
||||
agents, _ := local["agents"].([]interface{})
|
||||
if len(agents) != 1 {
|
||||
t.Fatalf("expected local agents from registry, got %+v", local)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleWebUINodeDispatchReplay(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user