Resurrecting this thread because I think I maybe have a slightly better solution than I can see here. The key line in my code is:
The exclude indirect possessions from take all rule does nothing when the item described is contained by the pockets and the current action is removing.
This solves the problem referenced above, that the command “take all” takes things out of containers (in many cases not what the player will want). I’m often loathe to just nuke standard rules because you never know what other useful things they might be doing; this more targeted solution seems better in this case. Full code in other other thread.