DEV Community

imper
imper

Posted on

I stopped spawning a second Pi just to switch sessions

I use the Pi coding agent from several project folders. After a while, pi --resume became a long list of sessions with similar first prompts. I kept reopening the wrong one.

I made pisesh to add the things I wanted in that list: favorites, search, custom names, a current-project view, and optional title generation. It is a single Node script with no runtime dependencies.

The first /sesh implementation

The first version took a direct route. It paused Pi's TUI, opened the pisesh picker, then started another Pi process for the selected session.

That was useful because leaving the child process returned me to the original session. It also meant the process tree looked like this:

Pi session A
  pisesh
    Pi session B
Enter fullscreen mode Exit fullscreen mode

The nested process eventually became the problem. Tools were running in session B, but anything watching the outer Pi process could still see session A as idle. The terminal looked right while the runtime lifecycle was wrong.

Switching the existing runtime

Pi already exposes ctx.switchSession() to extensions. In pisesh 0.3.0, the picker no longer starts Pi when it was opened through /sesh.

The picker writes one small JSON selection to a private file descriptor. It includes the absolute session path and the selected model behavior. The extension reads that result and asks Pi to switch the current runtime:

Pi session A
  /sesh picker
  ctx.switchSession(sessionB)
Pi session B
Enter fullscreen mode Exit fullscreen mode

Standalone pisesh still starts pi --session, so the shell command keeps its old behavior. Only the extension path changed.

There were two details I did not want to lose. Enter still resumes with the current default model and thinking level, while o restores the values recorded in the selected session. Interrupted tool calls are also repaired before the handoff when Pi would otherwise load an incomplete transcript.

Install

pi install npm:pisesh
Enter fullscreen mode Exit fullscreen mode

Then run /sesh inside Pi. The package is MIT licensed and works on Node 18 or newer.

Repo: https://github.com/Blue-B/pisesh

Top comments (1)

Collapse
 
dennison_bertram profile image
Dennison Bertram

Very cool!