@@ -50,6 +50,9 @@ type HookAction =
5050 kind : "wake" ;
5151 text : string ;
5252 mode : "now" | "next-heartbeat" ;
53+ agentId ?: string ;
54+ sessionKey ?: string ;
55+ sessionKeySource ?: "static" | "templated" ;
5356 }
5457 | {
5558 kind : "agent" ;
@@ -270,6 +273,9 @@ function buildActionFromMapping(
270273 kind : "wake" ,
271274 text,
272275 mode : mapping . wakeMode ?? "now" ,
276+ agentId : mapping . agentId ,
277+ sessionKey : renderOptional ( mapping . sessionKey , ctx ) ,
278+ sessionKeySource : getSessionKeyTemplateSource ( mapping . sessionKey ) ,
273279 } ,
274280 } ;
275281 }
@@ -309,7 +315,14 @@ function mergeAction(
309315 const baseWake = base . kind === "wake" ? base : undefined ;
310316 const text = typeof override . text === "string" ? override . text : ( baseWake ?. text ?? "" ) ;
311317 const mode = override . mode === "next-heartbeat" ? "next-heartbeat" : ( baseWake ?. mode ?? "now" ) ;
312- return validateAction ( { kind : "wake" , text, mode } ) ;
318+ return validateAction ( {
319+ kind : "wake" ,
320+ text,
321+ mode,
322+ agentId : override . agentId ?? baseWake ?. agentId ,
323+ sessionKey : override . sessionKey ?? baseWake ?. sessionKey ,
324+ sessionKeySource : resolveMergedSessionKeySource ( baseWake , override ) ,
325+ } ) ;
313326 }
314327 const baseAgent = base . kind === "agent" ? base : undefined ;
315328 const message =
@@ -339,10 +352,19 @@ function mergeAction(
339352}
340353
341354function validateAction ( action : HookAction ) : HookMappingResult {
355+ if ( action . sessionKeySource === "templated" && ! action . sessionKey ?. trim ( ) ) {
356+ return { ok : false , error : "hook mapping sessionKey template rendered empty" } ;
357+ }
342358 if ( action . kind === "wake" ) {
343359 if ( ! action . text ?. trim ( ) ) {
344360 return { ok : false , error : "hook mapping requires text" } ;
345361 }
362+ if ( action . mode === "next-heartbeat" && action . sessionKey ) {
363+ return {
364+ ok : false ,
365+ error : "hook mapping sessionKey requires wakeMode=now" ,
366+ } ;
367+ }
346368 return { ok : true , action } ;
347369 }
348370 if ( ! action . message ?. trim ( ) ) {
@@ -365,7 +387,7 @@ function getSessionKeyTemplateSource(
365387}
366388
367389function resolveMergedSessionKeySource (
368- baseAgent : Extract < HookAction , { kind : "agent" } > | undefined ,
390+ baseAction : HookAction | undefined ,
369391 override : Exclude < HookTransformResult , null > ,
370392) : HookSessionKeyTemplateSource | undefined {
371393 if ( typeof override . sessionKey === "string" ) {
@@ -377,7 +399,7 @@ function resolveMergedSessionKeySource(
377399 }
378400 return override . sessionKeySource === "static" ? "static" : "templated" ;
379401 }
380- return baseAgent ?. sessionKeySource ;
402+ return baseAction ?. sessionKeySource ;
381403}
382404
383405export function hasHookTemplateExpressions ( template : string ) : boolean {
0 commit comments