feat: add session lifecycle hooks with trajectory serialization#1165
Merged
Conversation
Add session.pre, session.post, session.userQuery.pre, and session.userQuery.post plugin hooks to SessionPrompt.runLoop. Hooks fire reliably via Effect.onExit and include full trajectory data for replay. Also adds getEnvInfo/getEnvTelemetry utilities.
Remove getEnvTelemetry from env-info.ts, its export from index.ts, and the corresponding test case from env-info.test.ts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
session.pre,session.post,session.userQuery.pre,session.userQuery.postplugin hooks toSessionPrompt.runLoopEffect.onExit— guaranteed even on thrown failures/interruptionsTrajectoryMessage[]) for replay with field-level fidelitygetEnvInfo/getEnvTelemetryutilities for environment metadata collectionDetails
Plugin hooks:
session.pre— fires once before the first LLM step; supports cancellation viaoutput.cancelsession.post— fires once when runLoop ends; reportsoutcome: "completed" | "error" | "cancelled"with final text and trajectorysession.userQuery.pre— fires before each LLM step; supports per-step cancellationsession.userQuery.post— fires after each LLM step (viaEffect.onExit); includes error, finalText, and step trajectoryTrajectory types (
TrajectoryMessage,TrajectoryPart) in@mimo-ai/pluginprovide the wire format for full raw agent slice replay.Tests: unit tests for trajectory serialization, env-info, and session-loop hook integration.