Still, when we're creating any infantry formation (especially shield wall), AI should try to put units with shields on the front and units with spears in 2nd-3rd rank. I think it's a very good idea to suggest the devs. Also I will try to do it by hand as you suggested, I will make 2 infantry groups (shields/spears) and see how it will work. Btw AI is always charging your archers with its cavalry so I'm thinking about creating a group of 10-15 pikemen just to protect the archers from cavalry.
If I was coding the shield wall things would be somewhat different. The outside positions of each formation would be hardcoded to fill with shields first and the second layer to fill with shields and then spears/pikes I'd also change the code so that when an enemy is within range, the individual unit would change to 'hold position' until the enemy is gone whence they return to 'shield wall'.
It's 2020 and I know how easy that code would be to write. A couple of bits are mind-bending but it's fairly straight forward.