@@ -50,6 +50,7 @@ export interface AcpSessionRuntimeOptions {
5050 } ;
5151 readonly authMethodId : string ;
5252 readonly mcpServers ?: ReadonlyArray < EffectAcpSchema . McpServer > ;
53+ readonly suppressSessionUpdatesUntilPrompt ?: boolean ;
5354 readonly requestLogger ?: ( event : AcpSessionRequestLogEvent ) => Effect . Effect < void , never > ;
5455 readonly protocolLogging ?: {
5556 readonly logIncoming ?: boolean ;
@@ -171,6 +172,9 @@ const makeAcpSessionRuntime = (
171172 const assistantSegmentRef = yield * Ref . make < AcpAssistantSegmentState > ( { nextSegmentIndex : 0 } ) ;
172173 const configOptionsRef = yield * Ref . make ( sessionConfigOptionsFromSetup ( undefined ) ) ;
173174 const startStateRef = yield * Ref . make < AcpStartState > ( { _tag : "NotStarted" } ) ;
175+ const suppressSessionUpdatesRef = yield * Ref . make (
176+ options . suppressSessionUpdatesUntilPrompt === true ,
177+ ) ;
174178
175179 const logRequest = ( event : AcpSessionRequestLogEvent ) =>
176180 options . requestLogger ? options . requestLogger ( event ) : Effect . void ;
@@ -249,6 +253,7 @@ const makeAcpSessionRuntime = (
249253 modeStateRef,
250254 toolCallsRef,
251255 assistantSegmentRef,
256+ suppressSessionUpdatesRef,
252257 params : notification ,
253258 } ) ,
254259 ) ;
@@ -407,15 +412,35 @@ const makeAcpSessionRuntime = (
407412 | EffectAcpSchema . NewSessionResponse
408413 | EffectAcpSchema . ResumeSessionResponse ;
409414 if ( options . resumeSessionId ) {
410- const loadPayload = {
411- sessionId : options . resumeSessionId ,
412- cwd : options . cwd ,
413- mcpServers : options . mcpServers ?? [ ] ,
414- } satisfies EffectAcpSchema . LoadSessionRequest ;
415- const resumed = yield * runLoggedRequest (
416- "session/load" ,
417- loadPayload ,
418- acp . agent . loadSession ( loadPayload ) ,
415+ const supportsResume = initializeResult . agentCapabilities ?. sessionCapabilities ?. resume ;
416+ const resumed = yield * (
417+ supportsResume
418+ ? runLoggedRequest (
419+ "session/resume" ,
420+ {
421+ sessionId : options . resumeSessionId ,
422+ cwd : options . cwd ,
423+ mcpServers : options . mcpServers ?? [ ] ,
424+ } satisfies EffectAcpSchema . ResumeSessionRequest ,
425+ acp . agent . resumeSession ( {
426+ sessionId : options . resumeSessionId ,
427+ cwd : options . cwd ,
428+ mcpServers : options . mcpServers ?? [ ] ,
429+ } ) ,
430+ )
431+ : runLoggedRequest (
432+ "session/load" ,
433+ {
434+ sessionId : options . resumeSessionId ,
435+ cwd : options . cwd ,
436+ mcpServers : options . mcpServers ?? [ ] ,
437+ } satisfies EffectAcpSchema . LoadSessionRequest ,
438+ acp . agent . loadSession ( {
439+ sessionId : options . resumeSessionId ,
440+ cwd : options . cwd ,
441+ mcpServers : options . mcpServers ?? [ ] ,
442+ } ) ,
443+ )
419444 ) . pipe ( Effect . exit ) ;
420445 if ( Exit . isSuccess ( resumed ) ) {
421446 sessionId = options . resumeSessionId ;
@@ -518,10 +543,13 @@ const makeAcpSessionRuntime = (
518543 sessionId : started . sessionId ,
519544 ...payload ,
520545 } satisfies EffectAcpSchema . PromptRequest ;
521- return closeActiveAssistantSegment ( {
522- queue : eventQueue ,
523- assistantSegmentRef,
524- } ) . pipe (
546+ return Ref . set ( suppressSessionUpdatesRef , false ) . pipe (
547+ Effect . andThen (
548+ closeActiveAssistantSegment ( {
549+ queue : eventQueue ,
550+ assistantSegmentRef,
551+ } ) ,
552+ ) ,
525553 Effect . andThen (
526554 runLoggedRequest (
527555 "session/prompt" ,
@@ -608,12 +636,14 @@ const handleSessionUpdate = ({
608636 modeStateRef,
609637 toolCallsRef,
610638 assistantSegmentRef,
639+ suppressSessionUpdatesRef,
611640 params,
612641} : {
613642 readonly queue : Queue . Queue < AcpParsedSessionEvent > ;
614643 readonly modeStateRef : Ref . Ref < AcpSessionModeState | undefined > ;
615644 readonly toolCallsRef : Ref . Ref < Map < string , AcpToolCallState > > ;
616645 readonly assistantSegmentRef : Ref . Ref < AcpAssistantSegmentState > ;
646+ readonly suppressSessionUpdatesRef : Ref . Ref < boolean > ;
617647 readonly params : EffectAcpSchema . SessionNotification ;
618648} ) : Effect . Effect < void > =>
619649 Effect . gen ( function * ( ) {
@@ -623,6 +653,9 @@ const handleSessionUpdate = ({
623653 current === undefined ? current : updateModeState ( current , parsed . modeId ! ) ,
624654 ) ;
625655 }
656+ if ( yield * Ref . get ( suppressSessionUpdatesRef ) ) {
657+ return ;
658+ }
626659 for ( const event of parsed . events ) {
627660 if ( event . _tag === "ToolCallUpdated" ) {
628661 yield * closeActiveAssistantSegment ( {
@@ -672,6 +705,8 @@ const handleSessionUpdate = ({
672705 }
673706 } ) ;
674707
708+ export const handleSessionUpdateForTest = handleSessionUpdate ;
709+
675710function updateModeState ( modeState : AcpSessionModeState , nextModeId : string ) : AcpSessionModeState {
676711 const normalized = nextModeId . trim ( ) ;
677712 if ( ! normalized ) {
0 commit comments