mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
777230dcd1
- Added `/subagents` platform command to visualize the active task tree. - Implemented GetAllActiveTurns and FormatTree in AgentLoop to support cross-session observability. - Fixed a bug where sub-turns spawned via tools were not registered in the global `activeTurnStates` map, making them invisible to system queries. - Enhanced tree rendering logic to identify and display "orphaned" subagents (children that outlive their parent turns). - Registered the new command in `builtin.go` and injected the turn state provider into the commands runtime. Modified Files: - pkg/agent/turn_state.go: Added TurnInfo snapshotting and recursive tree formatting. - pkg/agent/loop.go: Injected GetActiveTurn hook and implemented multi-root forest rendering. - pkg/agent/subturn.go: Added child turn registration into activeTurnStates. - pkg/commands/cmd_subagents.go: New command implementation. - pkg/commands/builtin.go: Command registration.
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// TurnInfo is a mirrored struct from agent.TurnInfo to avoid circular dependencies.
|
|
type TurnInfo struct {
|
|
TurnID string
|
|
ParentTurnID string
|
|
Depth int
|
|
ChildTurnIDs []string
|
|
IsFinished bool
|
|
}
|
|
|
|
func subagentsCommand() Definition {
|
|
return Definition{
|
|
Name: "subagents",
|
|
Description: "Show running subagents and task tree",
|
|
Handler: func(ctx context.Context, req Request, rt *Runtime) error {
|
|
getTurnFn := rt.GetActiveTurn
|
|
if getTurnFn == nil {
|
|
return req.Reply("Runtime does not support querying active turns.")
|
|
}
|
|
|
|
turnRaw := getTurnFn()
|
|
if turnRaw == nil {
|
|
return req.Reply("No active tasks running in this session.")
|
|
}
|
|
|
|
if treeStr, ok := turnRaw.(string); ok {
|
|
if treeStr == "" {
|
|
return req.Reply("No active tasks running in this session.")
|
|
}
|
|
return req.Reply(fmt.Sprintf("🤖 **Active Subagents Tree**\n```text\n%s\n```", treeStr))
|
|
}
|
|
|
|
return req.Reply(fmt.Sprintf("🤖 **Active Subagents List**\n```text\n%+v\n```", turnRaw))
|
|
},
|
|
}
|
|
}
|