Mostly-complete Client Agent

Though not 100% up to what the specs say, this Client Agent implementation should be full-featured enough to pull back into master.

@kestred: Please double-check my implementation of your new protocol, particularly the client-side bits.