[bug] Pi hook extension removed after /new — séance cleans up session directory on session-end
What happened
When using /new inside a pi session to start a fresh conversation, the séance pi hook stops working. The hook extension file (~/.cache/seance-pi/$SURFACE_ID/seance-hook.js) is deleted, so pi can no longer load it for the new session.
Expected behavior
The hook file should persist for the lifetime of the pi process, not the pi session. /new resets the conversation but pi remains the same process and reloads its extensions — including --extension paths.
Actual behavior
/new triggers pi's session_shutdown event → the hook sends seance ctl pi-hook session-end → séance deletes ~/.cache/seance-pi/$SURFACE_ID/ → pi reloads extensions → the --extension file is gone → the hook is silently dropped.
Root cause
The séance session-end hook handler appears to clean up the per-surface cache directory. But session-end does not mean the pi process has exited — it can also mean an in-process session reset (/new). The wrapper script (~/.local/share/seance/bin/pi) already has its own cleanup after the pi process exits:
# ── Session-end cleanup ─────────────────────────────────────────────────
seance ctl pi-hook session-end <<< "{}" 2>/dev/null || true
rm -rf "$SESSION_DIR"
exit $rc
So the directory removal on the séance side is redundant and premature.
Suggested fix
Either:
- Don't delete the session directory on session-end — let the wrapper's post-exit cleanup handle it, or
- Distinguish session reset from process exit — e.g. add a session-reset hook that séance handles without cleanup, and only clean up on the final session-end sent by the wrapper after pi exits, or
- Move the hook file outside the cache directory — write it somewhere séance won't clean up (e.g. ~/.pi/agent/extensions/seance-hook.js), so it survives regardless.
Steps to reproduce
- Launch pi inside a séance terminal (so the séance wrapper injects the hook)
- Verify the hook is working (séance tracks the session)
- Run /new in pi
- Observe that ~/.cache/seance-pi/$SURFACE_ID/seance-hook.js no longer exists
- Séance no longer tracks the session
Séance version
7bb5f3736423bbf1dd7e8e0ae83e0a4eef313651
How did you install it?
Built from source
Distro and desktop
Fedora
Relevant logs