feat(code): add /clear command to reset conversation history#1248
feat(code): add /clear command to reset conversation history#1248jonathanlab merged 3 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.
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(). |
|
Note: This PR does not offer support for |
|
heads up, I reverted this PR after merging it. Upon closer look, you modified |
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