package app func visibleSessionTree(children []*Child, focusID string) []*Child { rootID := activeRootID(children, focusID) if rootID == "" { return nil } out := make([]*Child, 0, len(children)) for _, c := range children { if c.Status() != StatusRunning { continue } if c.ID == rootID || c.ParentID == rootID { out = append(out, c) } } return out } func activeRootID(children []*Child, focusID string) string { if focusID != "" { for _, c := range children { if c.ID != focusID { continue } if c.ParentID == "" { return c.ID } if parent := findChildInSnapshot(children, c.ParentID); parent != nil { return parent.ID } return "" } } for _, c := range children { if c.ParentID == "" && c.Status() == StatusRunning { return c.ID } } return "" } func findChildInSnapshot(children []*Child, id string) *Child { for _, c := range children { if c.ID == id { return c } } return nil } func firstRunningTopLevel(children []*Child) *Child { for _, c := range children { if c.ParentID == "" && c.Status() == StatusRunning { return c } } return nil }