@@ -126,11 +126,11 @@ export const aoActivity: Plugin = async ({ directory, client }) => {
126126 if ( msg . sessionID && switchedSession ( msg . sessionID ) ) {
127127 callHookSync ( "session-start" , { session_id : msg . sessionID } )
128128 }
129- messageStore . set ( msg . id , msg )
130129 if ( msg . role === "assistant" && msg . modelID ) currentModel = msg . modelID
131130 // Fallback: some `opencode run` flows never deliver message.part.updated
132131 // for the prompt, so start the turn from the user message itself.
133132 if ( msg . role === "user" ) {
133+ messageStore . set ( msg . id , msg )
134134 const sessionID = msg . sessionID ?? currentSessionID
135135 if ( sessionID ) reportUserPrompt ( sessionID , msg . id , "" )
136136 }
@@ -143,14 +143,19 @@ export const aoActivity: Plugin = async ({ directory, client }) => {
143143 const msg = messageStore . get ( part . messageID )
144144 if ( msg ?. role === "user" && part . type === "text" ) {
145145 const sessionID = msg . sessionID ?? currentSessionID
146- if ( sessionID ) reportUserPrompt ( sessionID , msg . id , part . text ?? "" )
146+ const prompt = part . text ?? ""
147+ if ( sessionID ) reportUserPrompt ( sessionID , msg . id , prompt )
148+ if ( prompt . length > 0 ) messageStore . delete ( part . messageID )
147149 }
148150 break
149151 }
150152
151153 case "session.status" : {
152154 // session.status fires in both TUI and `opencode run`; session.idle
153155 // is deprecated and not reliably emitted in run mode.
156+ // AO's "stop" hook means "the current turn is idle/finished", not
157+ // "the whole native session has terminated", so multi-turn TUI
158+ // sessions intentionally emit one stop per idle transition.
154159 const props = ( event as any ) . properties
155160 if ( props ?. status ?. type !== "idle" ) break
156161 const sessionID = props ?. sessionID ?? currentSessionID
0 commit comments