Skip to content

feat: add session lifecycle hooks with trajectory serialization#1165

Merged
MiMoHardFather merged 3 commits into
mainfrom
post-agent-hook
Jun 21, 2026
Merged

feat: add session lifecycle hooks with trajectory serialization#1165
MiMoHardFather merged 3 commits into
mainfrom
post-agent-hook

Conversation

@MiMoHardFather

Copy link
Copy Markdown
Collaborator

Summary

  • Add session.pre, session.post, session.userQuery.pre, session.userQuery.post plugin hooks to SessionPrompt.runLoop
  • Hooks fire reliably via Effect.onExit — guaranteed even on thrown failures/interruptions
  • Include full trajectory data (TrajectoryMessage[]) for replay with field-level fidelity
  • Add getEnvInfo / getEnvTelemetry utilities for environment metadata collection

Details

Plugin hooks:

  • session.pre — fires once before the first LLM step; supports cancellation via output.cancel
  • session.post — fires once when runLoop ends; reports outcome: "completed" | "error" | "cancelled" with final text and trajectory
  • session.userQuery.pre — fires before each LLM step; supports per-step cancellation
  • session.userQuery.post — fires after each LLM step (via Effect.onExit); includes error, finalText, and step trajectory

Trajectory types (TrajectoryMessage, TrajectoryPart) in @mimo-ai/plugin provide the wire format for full raw agent slice replay.

Tests: unit tests for trajectory serialization, env-info, and session-loop hook integration.

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.
@MiMoHardFather MiMoHardFather merged commit 75ee051 into main Jun 21, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant