I have seen a few remotes in the past had an IR receiver built into them as well. To learn a new command, you would put the remote into "learn mode" and then point the remote you want to copy at it and push the button on the remote that you want it to learn.
It would effectively record the IR pattern and replay it later. This probably isnt quite as sophisticated as what you're looking for, but it could work. I've also heard of more expensive remotes that let you program new codes into them via USB, not sure specifcally what the remote was called though.