Is there a terminal app that can record commands?
Terminal.app (the default macOS terminal application) can be scripted using AppleScript but a better option may be iTerm2, which can be scripted using Python (AppleScript is also supported but it's deprecated).

If you'd like to save ssh sessions your most portable option is to use the OpenSSH client configuration file (typically named ~/.ssh/config). Using it you can configure per connection settings like key, username, etc.