@@ -53,7 +53,7 @@ import {
5353} from "./session-reset-prompt.js" ;
5454import { resolveSessionStableReplyMode } from "./session-stable-reply-mode.js" ;
5555import {
56- isExplicitSourceReplyCommand ,
56+ isDirectedSourceReplyTurn ,
5757 isSyntheticSourceReplyTurn ,
5858} from "./source-reply-delivery-mode.js" ;
5959import { shouldApplyStartupContext , buildSessionStartupContextPrelude } from "./startup-context.js" ;
@@ -223,11 +223,18 @@ export async function prepareReplyRunContext(params: RunPreparedReplyParams) {
223223 sourceConversationContextByMode [ sessionPromptSourceReplyDeliveryMode ?? "automatic" ] ;
224224 // Claude CLI fixes the system prompt at session creation; group intro must stay session-stable.
225225 const groupIntro = isGroupChat ? buildGroupIntro ( { sessionEntry, defaultActivation } ) : "" ;
226- const isDirectedTurn =
227- isExplicitSourceReplyCommand ( ctx , cfg ) ||
228- ( inboundEventKind !== "room_event" && ( isDirectChat || ctx . WasMentioned === true ) ) ;
226+ const isDirectedTurn = isDirectedSourceReplyTurn ( ctx , cfg , isDirectChat , inboundEventKind ) ;
227+ const isAmbientRoomEvent = inboundEventKind === "room_event" && ! isDirectedTurn ;
229228 const allowEmptyAssistantReplyAsSilent =
230- isGroupChat && ! isDirectedTurn && silentReplySettings . policy === "allow" ;
229+ isGroupChat &&
230+ ! isDirectedTurn &&
231+ ( isAmbientRoomEvent || silentReplySettings . policy === "allow" ) ;
232+ // Heartbeats retain the embedded runner's trigger-owned optional default.
233+ const terminalReplyExpectation = isHeartbeat
234+ ? undefined
235+ : isAmbientRoomEvent
236+ ? "optional"
237+ : "required" ;
231238 const groupSystemPrompt = normalizeOptionalString ( promptSessionCtx . GroupSystemPrompt ) ?? "" ;
232239 const inboundMetaPrompt = buildInboundMetaSystemPrompt (
233240 isNewSession ? sessionCtx : { ...sessionCtx , ThreadStarterBody : undefined } ,
@@ -476,6 +483,7 @@ export async function prepareReplyRunContext(params: RunPreparedReplyParams) {
476483 getInboundContext : ( ) => ( { activeGoalContext, inboundUserContext } ) ,
477484 refreshInboundContextAfterAdmissionWait,
478485 allowEmptyAssistantReplyAsSilent,
486+ terminalReplyExpectation,
479487 } as const ;
480488}
481489
0 commit comments