@@ -10,7 +10,7 @@ import {
1010 TransportError ,
1111 type LLMRequest ,
1212} from "@opencode/ai/effect"
13- import { OpenAIChat } from "@opencode/ai/protocols"
13+ import { OpenAIChat , OpenAIResponses } from "@opencode/ai/protocols"
1414import { Agent } from "@opencode/core/agent"
1515import { Database } from "@opencode/core/database/database"
1616import { AppNodeBuilder } from "@opencode/core/effect/app-node-builder"
@@ -35,7 +35,7 @@ import { Model } from "@opencode/core/model"
3535import { Provider } from "@opencode/core/provider"
3636import { AbsolutePath } from "@opencode/core/schema"
3737import { Money } from "@opencode/schema/money"
38- import { Deferred , Effect , Fiber , Layer , Stream } from "effect"
38+ import { Deferred , Effect , Fiber , Layer , Schema , Stream } from "effect"
3939import { testEffect } from "./lib/effect"
4040
4141let requests : LLMRequest [ ] = [ ]
@@ -84,11 +84,11 @@ const successfulTitle = () =>
8484 reason : { normalized : "stop" } ,
8585 } ) ,
8686 )
87- let titleStream : ( ) => Stream . Stream < LLMEvent , AIError > = successfulTitle
87+ let titleStream : ( request : LLMRequest ) => Stream . Stream < LLMEvent , AIError > = successfulTitle
8888const client = Layer . mock ( LLMClient . Service ) ( {
8989 stream : ( request : LLMRequest ) => {
9090 requests . push ( request )
91- return titleStream ( )
91+ return titleStream ( request )
9292 } ,
9393 generate : ( ) => Effect . die ( "unused" ) ,
9494} )
@@ -237,6 +237,50 @@ it.effect("generates a title from the sole user message and renames the session"
237237 } ) ,
238238)
239239
240+ for ( const timing of [ "start" , "end" ] as const )
241+ it . effect ( `excludes commentary from titles when the response phase arrives at ${ timing } ` , ( ) =>
242+ Effect . gen ( function * ( ) {
243+ yield * enableTitleAgent
244+ const sessionID = Session . ID . make ( `ses_title_phase_${ timing } ` )
245+ yield * insertSession ( sessionID )
246+ yield * prompt ( sessionID , "Investigate performance across four hosts without making changes" )
247+ // Sanitized shape of a live Luna response: both messages are output_text, not reasoning.
248+ titleStream = ( request ) =>
249+ Stream . fromIterable ( [
250+ {
251+ type : "response.output_item.added" ,
252+ item : { type : "message" , id : "commentary" , ...( timing === "start" ? { phase : "commentary" } : { } ) } ,
253+ } ,
254+ {
255+ type : "response.output_text.delta" ,
256+ item_id : "commentary" ,
257+ delta : "We need title only. Need capture investigation four machines performance read-only. Title concise." ,
258+ } ,
259+ {
260+ type : "response.output_item.done" ,
261+ item : { type : "message" , id : "commentary" , phase : "commentary" } ,
262+ } ,
263+ { type : "response.output_item.added" , item : { type : "message" , id : "final" , phase : "final_answer" } } ,
264+ { type : "response.output_text.delta" , item_id : "final" , delta : "Read-only performance investigation" } ,
265+ { type : "response.output_item.done" , item : { type : "message" , id : "final" , phase : "final_answer" } } ,
266+ { type : "response.completed" , response : { id : "response_title" } } ,
267+ ] ) . pipe (
268+ Stream . map ( ( event ) => Schema . decodeUnknownSync ( OpenAIResponses . protocol . stream . event ) ( JSON . stringify ( event ) ) ) ,
269+ Stream . mapAccumEffect (
270+ ( ) => OpenAIResponses . protocol . stream . initial ( request ) ,
271+ OpenAIResponses . protocol . stream . step ,
272+ ) ,
273+ )
274+
275+ const title = yield * SessionTitle . Service
276+ yield * title . generate ( sessionID )
277+
278+ const store = yield * SessionStore . Service
279+ expect ( requests ) . toHaveLength ( 1 )
280+ expect ( ( yield * store . get ( sessionID ) ) ?. title ) . toBe ( "Read-only performance investigation" )
281+ } ) ,
282+ )
283+
240284it . effect ( "runs title hooks instead of context hooks" , ( ) =>
241285 Effect . gen ( function * ( ) {
242286 yield * enableTitleAgent
0 commit comments