Refactor runtime around world core

This commit is contained in:
lpf
2026-03-15 23:46:06 +08:00
parent ba95aeed35
commit afae9076df
79 changed files with 6526 additions and 6960 deletions

View File

@@ -0,0 +1 @@
camera-bytes

View File

@@ -0,0 +1 @@
video-bytes

View File

@@ -0,0 +1 @@
screen-video

View File

@@ -0,0 +1 @@
‰PNG

View File

@@ -223,8 +223,8 @@ func gatewayCmd() {
}
return out
})
registryServer.SetSubagentHandler(func(cctx context.Context, action string, args map[string]interface{}) (interface{}, error) {
return loop.HandleSubagentRuntime(cctx, action, args)
registryServer.SetRuntimeAdminHandler(func(cctx context.Context, action string, args map[string]interface{}) (interface{}, error) {
return loop.HandleRuntimeAdmin(cctx, action, args)
})
registryServer.SetNodeDispatchHandler(func(cctx context.Context, req nodes.Request, mode string) (nodes.Response, error) {
return loop.DispatchNodeRequest(cctx, req, mode)

View File

@@ -26,7 +26,6 @@ import (
"github.com/YspCoder/clawgo/pkg/nodes"
"github.com/YspCoder/clawgo/pkg/providers"
"github.com/YspCoder/clawgo/pkg/runtimecfg"
"github.com/YspCoder/clawgo/pkg/tools"
"github.com/gorilla/websocket"
"github.com/pion/webrtc/v4"
)
@@ -384,8 +383,8 @@ func nodeAgentsFromConfig(cfg *config.Config) []nodes.AgentInfo {
if cfg == nil {
return nil
}
items := make([]nodes.AgentInfo, 0, len(cfg.Agents.Subagents))
for agentID, subcfg := range cfg.Agents.Subagents {
items := make([]nodes.AgentInfo, 0, len(cfg.Agents.Agents))
for agentID, subcfg := range cfg.Agents.Agents {
id := strings.TrimSpace(agentID)
if id == "" || !subcfg.Enabled {
continue
@@ -394,7 +393,7 @@ func nodeAgentsFromConfig(cfg *config.Config) []nodes.AgentInfo {
ID: id,
DisplayName: strings.TrimSpace(subcfg.DisplayName),
Role: strings.TrimSpace(subcfg.Role),
Type: strings.TrimSpace(subcfg.Type),
Type: firstNonEmptyString(strings.TrimSpace(subcfg.Kind), strings.TrimSpace(subcfg.Type), "agent"),
Transport: strings.TrimSpace(subcfg.Transport),
ParentAgentID: strings.TrimSpace(subcfg.ParentAgentID),
})
@@ -833,23 +832,11 @@ func executeNodeAgentTask(ctx context.Context, info nodes.NodeInfo, req nodes.Re
}, nil
}
out, err := loop.HandleSubagentRuntime(ctx, "dispatch_and_wait", map[string]interface{}{
"task": strings.TrimSpace(req.Task),
"agent_id": remoteAgentID,
"channel": "node",
"chat_id": info.ID,
"wait_timeout_sec": float64(120),
})
sessionKey := fmt.Sprintf("node:%s:%s", info.ID, remoteAgentID)
result, err := loop.ProcessDirectWithOptions(ctx, strings.TrimSpace(req.Task), sessionKey, "node", info.ID, remoteAgentID, nil)
if err != nil {
return nodes.Response{}, err
}
payload, _ := out.(map[string]interface{})
result := strings.TrimSpace(fmt.Sprint(payload["merged"]))
if result == "" {
if reply, ok := payload["reply"].(*tools.RouterReply); ok {
result = strings.TrimSpace(reply.Result)
}
}
artifacts, err := collectNodeArtifacts(executor.workspace, req.Args)
if err != nil {
return nodes.Response{}, err
@@ -862,7 +849,7 @@ func executeNodeAgentTask(ctx context.Context, info nodes.NodeInfo, req nodes.Re
Payload: map[string]interface{}{
"transport": "clawgo-local",
"agent_id": remoteAgentID,
"result": result,
"result": strings.TrimSpace(result),
"artifacts": artifacts,
},
}, nil

View File

@@ -139,21 +139,21 @@ func TestNodeAgentsFromConfigCollectsEnabledAgents(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Agents.Subagents["main"] = config.SubagentConfig{
cfg.Agents.Agents["main"] = config.AgentConfig{
Enabled: true,
Type: "router",
Type: "agent",
DisplayName: "Main Agent",
Role: "orchestrator",
}
cfg.Agents.Subagents["coder"] = config.SubagentConfig{
cfg.Agents.Agents["coder"] = config.AgentConfig{
Enabled: true,
Type: "worker",
Type: "agent",
DisplayName: "Code Agent",
Role: "code",
}
cfg.Agents.Subagents["tester"] = config.SubagentConfig{
cfg.Agents.Agents["tester"] = config.AgentConfig{
Enabled: false,
Type: "worker",
Type: "agent",
DisplayName: "Test Agent",
Role: "test",
}
@@ -211,9 +211,9 @@ func TestExecuteNodeRequestRunsLocalMainAgentTask(t *testing.T) {
cfg := config.DefaultConfig()
cfg.Agents.Defaults.Workspace = filepath.Join(t.TempDir(), "workspace")
cfg.Agents.Subagents["main"] = config.SubagentConfig{
cfg.Agents.Agents["main"] = config.AgentConfig{
Enabled: true,
Type: "router",
Type: "agent",
Role: "orchestrator",
}
if err := config.SaveConfig(globalConfigPathOverride, cfg); err != nil {
@@ -236,7 +236,7 @@ func TestExecuteNodeRequestRunsLocalMainAgentTask(t *testing.T) {
}
}
func TestExecuteNodeRequestRunsLocalSubagentTask(t *testing.T) {
func TestExecuteNodeRequestRunsLocalAgentTask(t *testing.T) {
prevCfg := globalConfigPathOverride
prevProviderFactory := nodeProviderFactory
prevLoopFactory := nodeAgentLoopFactory
@@ -256,14 +256,14 @@ func TestExecuteNodeRequestRunsLocalSubagentTask(t *testing.T) {
cfg := config.DefaultConfig()
cfg.Agents.Defaults.Workspace = filepath.Join(t.TempDir(), "workspace")
cfg.Agents.Subagents["main"] = config.SubagentConfig{
cfg.Agents.Agents["main"] = config.AgentConfig{
Enabled: true,
Type: "router",
Type: "agent",
Role: "orchestrator",
}
cfg.Agents.Subagents["coder"] = config.SubagentConfig{
cfg.Agents.Agents["coder"] = config.AgentConfig{
Enabled: true,
Type: "worker",
Type: "agent",
Role: "code",
}
if err := os.MkdirAll(filepath.Join(cfg.Agents.Defaults.Workspace, "out"), 0755); err != nil {

View File

@@ -113,14 +113,14 @@ func statusCmd() {
sessionsDir := filepath.Join(filepath.Dir(configPath), "sessions")
if kinds, err := collectSessionKindCounts(sessionsDir); err == nil && len(kinds) > 0 {
fmt.Println("Session Kinds:")
for _, k := range []string{"main", "cron", "subagent", "hook", "node", "other"} {
for _, k := range []string{"main", "cron", "agent", "hook", "node", "other"} {
if v, ok := kinds[k]; ok {
fmt.Printf(" %s: %d\n", k, v)
}
}
}
if recent, err := collectRecentSubagentSessions(sessionsDir, 5); err == nil && len(recent) > 0 {
fmt.Println("Recent Subagent Sessions:")
if recent, err := collectRecentAgentSessions(sessionsDir, 5); err == nil && len(recent) > 0 {
fmt.Println("Recent Agent Sessions:")
for _, key := range recent {
fmt.Printf(" - %s\n", key)
}
@@ -389,7 +389,7 @@ func collectSkillExecStats(path string) (int, int, int, float64, string, error)
return total, okCnt, failCnt, reasonCoverage, topSkill, nil
}
func collectRecentSubagentSessions(sessionsDir string, limit int) ([]string, error) {
func collectRecentAgentSessions(sessionsDir string, limit int) ([]string, error) {
indexPath := filepath.Join(sessionsDir, "sessions.json")
data, err := os.ReadFile(indexPath)
if err != nil {
@@ -408,7 +408,7 @@ func collectRecentSubagentSessions(sessionsDir string, limit int) ([]string, err
}
items := make([]item, 0)
for key, row := range index {
if strings.ToLower(strings.TrimSpace(row.Kind)) != "subagent" {
if strings.ToLower(strings.TrimSpace(row.Kind)) != "agent" {
continue
}
items = append(items, item{key: key, updated: row.UpdatedAt})