feat(code): add /clear command to reset conversation history#1248
feat(code): add /clear command to reset conversation history#1248littlekirkycode wants to merge 2 commits intoPostHog:mainfrom
Conversation
Adds /clear slash command that resets conversation history and starts a fresh session. Suppresses the SDK's built-in /clear (which doesn't work in our context) and replaces it with our own implementation. resetSession() now clears UI history by skipping log replay on reconnect.
There was a problem hiding this comment.
Thanks for taking a stab at this! Clearing this way will only clear the in memory logs, but the actual S3 logs will not be reset.
This means that if you run /clear, and then reload the application, you'll see your old logs. (Attachment shows an example of this. I ran /clear after each message, then restarted PostHog Code)
We'll have to create a new task run (Each task run has an associated S3 log) or maybe filter for logs after the /clear command. We already have comparable functionality for this in createNewLocalSession.
| const { getSessionService } = await import( | ||
| "@features/sessions/service/service" | ||
| ); |
There was a problem hiding this comment.
nit: no inline imports please
There was a problem hiding this comment.
Your welcome, and thanks for taking the time to provide feedback! Will amend, and stay aware of this in future.
Remove inline import in commands.ts. Rewrite resetSession() to create a new task run via createNewLocalSession() instead of clearing in-memory logs, ensuring old messages don't reappear on app restart.
|
Both changes applied — removed the inline import and rewrote resetSession() to tear down the old session and create a fresh task run via the suggested createNewLocalSession(), so old messages won't come back after a restart. Also rebased #1249 on top of this as its clear-and-continue flow goes through resetSession(). |
Summary
Adds a
/clearslash command that wipes conversation history andreconnects with a fresh session. Useful when context is cluttered or the
agent is stuck in a loop.
Implementation
Client-side command in the message editor — delegates to
SessionService.resetSession():resetSession()callsreconnectInPlacewith a newclearHistoryflag. When true, log replay is skipped entirely — the session reconnects
with empty event history instead of replaying from the log file:
SDK's built-in
/clearis suppressed — it doesn't work in our ACPcontext, so it's added to
UNSUPPORTED_COMMANDSand replaced by our own.Changes
commands.ts(message-editor)/clearcommand definitioncommands.ts(session)"clear"toUNSUPPORTED_COMMANDSservice.tsresetSession()passesclearHistory=true,reconnectInPlaceskips log fetch when clearingTest plan
/clearin message editor → conversation history is cleared/clearappears in slash command autocomplete