I wrote something small and simple to scratch an itch. It's the UNIX philosophy: small "one-trick ponies", each *really* good at their one trick, then the user can hook them together to solve actual problems. I'm a CLI guy, and for almost everything, I already have this. But not for debugging. The itch I scratched was the connector that enables this philosophy for debugging. That thing is dap-mux. A DAP multiplexer turning a one-to-one protocol into a cooperating session of as many tools as you need to get it done!
How it started: Helix and Python for me (and sometimes IPython), with the rest of my team using PyCharm (which I have long loved!). My team's problem is that they want the PyCharm debugger, and so must be satisfied with the JetBrains editor. *My* problem was I could use a full-blown debugger *or* I could have IPython *or* I could have Helix (or sometimes an unsatisfying combination of Helix and the debugger). That was my "itch".
DAP (Debug Adapter Protocol) is the tantalizing answer, except it isn't. DAP is what editors (that don't want to write their own debuggers) are starting to adopt. The problem with DAP is it's one-to-one. One editor connects to one debugger. Done. Not a solution to my problem. And then suddenly, it *was* the solution. I realized that a DAP multiplexer would let you connect any DAP-aware editor to any debugger for any language, and simultaneously to a REPL, another session of your editor (or a different editor)! With the side benefit that now, like screen or tmux, since each process is its own thing: sessions are durable. Just restart whatever crashed and you're back where you were!
There were hard parts: sequencing, late joiners, state management. Different end-points working on different actions in different sequences but with the same message ids. I solved these problems something like how NAT works. Instead of translating network addresses, though, I'm translating the sequence numbers of each client into something global and ordered, then correctly routing replies back to the end-point awaiting them, while mapping the sequence numbers for those replies back into the space of that end-point. Knowing the current state of the debugger, and replaying that as a message sequence to late joiners lets you start/connect the clients in any order. I chose Python: asyncio fits the I/O-router pattern perfectly, and it lets the IPython extension run in-process rather than over IPC.
There are problems not yet solved: for instance, I think configuration in the clients and/or the startup sequence is too complicated. But it functions! I got what I wanted!
The combination I use every day: Python + debugpy + Helix + IPython, all connected simultaneously. Step with `%n` or `%s`, evaluate expressions with `%eval`, watch Helix track the current line in real time. Rust with codelldb is the second confirmed combination — I debugged a Dijkstra implementation with Helix and a third-party DAP observer tool both connected to the same codelldb session. A community member, Sean Perry, has already built [dap-observer](https://github.com/shaleh/dap-observer), which renders the current frame's variables as a navigable terminal tree. *This* was my exact dream! Small, focused, connectable tools all playing together!
There's so much left to try: other editors, other debug adapters, Windows, other languages. None of this has been touched yet. The most helpful thing now is people testing it with their own setup and reporting what they find. It's time to play!
`uv tool install 'dap-mux[ipython]'` for Python + IPython. `uv tool install dap-mux` for headless use with any language and adapter. No need for any part of the Python ecosystem.
1 comments