@@ -7,6 +7,7 @@ import { z } from "zod";
77import { approveAll , defineTool } from "../../src/index.js" ;
88import type {
99 ErrorOccurredHookInput ,
10+ PostUserPromptSubmittedHookInput ,
1011 PostToolUseFailureHookInput ,
1112 PostToolUseHookInput ,
1213 PreToolUseHookInput ,
@@ -149,6 +150,42 @@ describe("Extended session hooks", async () => {
149150 await session . disconnect ( ) ;
150151 } ) ;
151152
153+ it ( "should invoke postUserPromptSubmitted hook and modify transformed prompt" , async ( ) => {
154+ const inputs : PostUserPromptSubmittedHookInput [ ] = [ ] ;
155+ const session = await client . createSession ( {
156+ onPermissionRequest : approveAll ,
157+ hooks : {
158+ onPostUserPromptSubmitted : async ( input , invocation ) => {
159+ inputs . push ( input ) ;
160+ expect ( invocation . sessionId ) . toBeTruthy ( ) ;
161+ expect ( input . prompt ) . toContain ( "Say something after prompt transformation" ) ;
162+ expect ( input . transformedPrompt ) . toContain (
163+ "Say something after prompt transformation"
164+ ) ;
165+ expect ( input . transformedPrompt ) . toContain ( "<current_datetime>" ) ;
166+
167+ return {
168+ modifiedTransformedPrompt : input . transformedPrompt . replace (
169+ / < c u r r e n t _ d a t e t i m e > .* ?< \/ c u r r e n t _ d a t e t i m e > \n * / s,
170+ "POST_USER_PROMPT_SUBMITTED_HOOK\n"
171+ ) ,
172+ } ;
173+ } ,
174+ } ,
175+ } ) ;
176+
177+ const response = await session . sendAndWait ( {
178+ prompt : "Say something after prompt transformation" ,
179+ } ) ;
180+
181+ expect ( inputs . length ) . toBeGreaterThan ( 0 ) ;
182+ expect ( inputs [ 0 ] . timestamp ) . toBeInstanceOf ( Date ) ;
183+ expect ( inputs [ 0 ] . workingDirectory ) . toBeDefined ( ) ;
184+ expect ( response ?. data . content ?? "" ) . toContain ( "POST_USER_PROMPT_SUBMITTED_HOOK" ) ;
185+
186+ await session . disconnect ( ) ;
187+ } ) ;
188+
152189 it ( "should invoke sessionStart hook" , async ( ) => {
153190 const inputs : SessionStartHookInput [ ] = [ ] ;
154191 const session = await client . createSession ( {
0 commit comments