Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
71 lines
2.3 KiB
Go
71 lines
2.3 KiB
Go
package agentcontext
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
agentservice "github.com/tutti-os/tutti/services/tuttid/service/agent"
|
|
cliservice "github.com/tutti-os/tutti/services/tuttid/service/cli"
|
|
"github.com/tutti-os/tutti/services/tuttid/service/cli/framework"
|
|
)
|
|
|
|
func (p Provider) newActivePeersCommand() cliservice.Command {
|
|
return framework.Register(framework.CommandSpec[struct{}]{
|
|
ID: appID + ".agent.active-peers",
|
|
Path: []string{"agent", "active-peers"},
|
|
Summary: "Show active peer agents",
|
|
Description: "Show logical active peer agents and their execution cwd in the current workspace before editing files.",
|
|
Kind: framework.KindList,
|
|
Workspace: framework.WorkspaceRequired,
|
|
Workspaces: p.workspaces,
|
|
Inputs: framework.FromStruct[struct{}](),
|
|
Output: framework.OutputSpec{
|
|
DefaultMode: cliservice.OutputModeJSON,
|
|
DefaultView: framework.ViewSummary,
|
|
JSON: true,
|
|
JSONViews: map[framework.OutputView]func(any) map[string]any{framework.ViewSummary: activePeersValue},
|
|
ListCompact: true,
|
|
},
|
|
Run: p.runActivePeers,
|
|
})
|
|
}
|
|
|
|
func (p Provider) runActivePeers(ctx context.Context, invoke framework.InvokeContext, _ struct{}) (any, error) {
|
|
if err := p.requireSessions(); err != nil {
|
|
return nil, err
|
|
}
|
|
return p.sessions.ListActivePeers(ctx, invoke.WorkspaceID)
|
|
}
|
|
|
|
func activePeersValue(result any) map[string]any {
|
|
peers := result.(agentservice.ActivePeers)
|
|
return map[string]any{
|
|
"agents": activePeerValues(peers.Agents),
|
|
"selfKnown": peers.SelfKnown,
|
|
"mayIncludeSelf": peers.MayIncludeSelf,
|
|
"warning": peers.Warning,
|
|
}
|
|
}
|
|
|
|
func activePeerValues(peers []agentservice.ActivePeer) []any {
|
|
values := make([]any, 0, len(peers))
|
|
for _, peer := range peers {
|
|
value := map[string]any{
|
|
"agentSessionId": peer.Session.ID,
|
|
"provider": peer.Session.Provider,
|
|
"cwd": strings.TrimSpace(peer.Session.Cwd),
|
|
"activeTurnId": strings.TrimSpace(peer.Session.ActiveTurnID),
|
|
"title": "",
|
|
}
|
|
if peer.Session.ActiveTurn != nil {
|
|
value["activeTurnPhase"] = peer.Session.ActiveTurn.Phase
|
|
}
|
|
if peer.Session.Title != nil {
|
|
value["title"] = *peer.Session.Title
|
|
}
|
|
value["selfRelation"] = peer.SelfRelation
|
|
values = append(values, value)
|
|
}
|
|
return values
|
|
}
|