What's the best way of shipping this type of code? How can one best
delineate the client-owned-code and the me-owned-code in a way that
keeps the client happy and protect my assets?
There are two ways to achieve this that I know of:
- Draw a licensing agreement (or better yet, have a lawyer do it) and have your employer sign it if you ever want to bring such code into their codebase.
This has the obvious downside of almost every employer going "what the hell" and the mere idea of signing such document swiftly dies in legal, assuming that it even gets that far. And I say assuming as what will likely happen is that this will be a non-starter, having agreements like this attached to product you create is a minefield, and the only reason they would consider anything like that if your project would save very substantial amount of money to justify the mess.
To make matters worse while employees are here for some amount of time, this mess would likely stay in forever - it's a proper minefield.
- Opensource your tools.
If it's opensource and with an appropriate license (MIT/BSD are the easiest ones, GPL will likely be a no-no in most companies) you can use it with any amount of employers, clients and projects you want while preserving authorship. You can then also make a pretty easy case of being able to contribute to your opensource tool during paid for work time whenever it would help the company achieve it's goals, so the tool can keep growing as you go through clients/employers.
Of course the downside is that then anyone can just grab your tools and use them, having to only satisfy license needs, but on the upside if the tool will turn out to be popular those things do tend to lead to actual workplace perk - including job offers and easier interviews.
Update: Just to clarify one thing. While you can license your work as opensource, that doesn't mean that you have to publish it on GitHub, you can just shove it together with your normal work package. Of course with permissive license there is nothing stopping anyone else from grabbing this code and putting it on GitHub, unless you will put such clauses into the license but then look at point 1 of all the complications that brings.