feat(headless): wire lifecycle hooks (Stop, SessionStart, SessionEnd, UserPromptSubmit)#1974
Open
SARP4 wants to merge 1 commit intoletta-ai:mainfrom
Open
feat(headless): wire lifecycle hooks (Stop, SessionStart, SessionEnd, UserPromptSubmit)#1974SARP4 wants to merge 1 commit intoletta-ai:mainfrom
SARP4 wants to merge 1 commit intoletta-ai:mainfrom
Conversation
684a0e8 to
1994a2e
Compare
… UserPromptSubmit) Lifecycle hooks (Stop, UserPromptSubmit, SessionStart, SessionEnd) only fired in interactive CLI (App.tsx). This wires them into headless mode so SDK consumers (lettabot, PM2) can use hooks for analytics, logging, and external integrations. Changes: - Import runStopHooks, runSessionStartHooks, runSessionEndHooks, runUserPromptSubmitHooks from ./hooks - SessionStart: fire-and-forget after agent resolution - Stop (bidirectional): run after end_turn, with blocking semantics (exit 2 → inject <stop-hook> feedback and continue conversation loop) - Stop (one-shot): run after end_turn, with blocking semantics (exit 2 → continue turn loop with hook feedback) - SessionEnd: fire-and-forget before exitHeadless/exitBidirectional - UserPromptSubmit (bidirectional): run after parsing user input, blocked → emit error event and skip All hook extraction patterns match App.tsx exactly. Tested: 88 headless tests pass, 27 hook executor tests pass. Fixes letta-ai#1282
92d4889 to
736afe0
Compare
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
Lifecycle hooks (
Stop,UserPromptSubmit,SessionStart,SessionEnd) only fired in the interactive CLI (App.tsx). This PR wires them into headless mode so SDK consumers (lettabot, PM2, etc.) can use hooks for analytics, logging, policy enforcement, and external integrations.Fixes #1282
Problem
As described in #1282, headless mode had zero integration for lifecycle hooks. Tool hooks (
PreToolUse,PostToolUse,PostToolUseFailure) already worked because they execute viatools/manager.tsregardless of mode. But lifecycle hooks were only called fromApp.tsx.Changes
src/headless.tsrunStopHooks,runSessionStartHooks,runSessionEndHooks,runUserPromptSubmitHooksend_turn, with blocking semantics — if exit code 2, inject<stop-hook>feedback and continue conversation loopend_turn, with blocking semantics — if exit code 2, continue turn loop with hook feedbackexitHeadless/exitBidirectionalAll hook extraction patterns match
App.tsxexactly.Testing
Checklist
bun run build)