@@ -494,3 +494,119 @@ it.effect.each(deliveries)(
494494 ) ,
495495 ) ,
496496) ;
497+
498+ it . effect ( "applies an effort change to the running Claude query without waiting for a turn" , ( ) =>
499+ Effect . scoped (
500+ Effect . gen ( function * ( ) {
501+ const cwd = yield * checkpointWorkspace ( "claude-live-effort" ) ;
502+ const sdkMessages = yield * Queue . unbounded < SDKMessage > ( ) ;
503+ const flagSettings : unknown [ ] = [ ] ;
504+ const adapter = yield * ClaudeAdapterV2 . makeClaudeAdapterV2 ( {
505+ instanceId : modelSelection . instanceId ,
506+ settings,
507+ environment : { } ,
508+ attachmentsDir : cwd ,
509+ fileSystem : yield * FileSystem . FileSystem ,
510+ path : yield * Path . Path ,
511+ random : yield * SecureRandom . SecureRandom ,
512+ idAllocator : yield * IdAllocator . IdAllocatorV2 ,
513+ queryRunner : {
514+ allocateSessionId : Effect . succeed ( sessionId ) ,
515+ open : ( ) =>
516+ Effect . succeed ( {
517+ messages : Stream . fromQueue ( sdkMessages ) ,
518+ offer : ( ) => Effect . void ,
519+ setModel : ( ) => Effect . void ,
520+ applyFlagSettings : ( flags ) =>
521+ Effect . sync ( ( ) => {
522+ flagSettings . push ( flags ) ;
523+ } ) ,
524+ setPermissionMode : ( ) => Effect . void ,
525+ backgroundTasks : ( ) => Effect . succeed ( false ) ,
526+ mcpServerStatus : Effect . succeed ( [ ] ) ,
527+ readMcpResource : ( ) => Effect . die ( "unexpected MCP resource read" ) ,
528+ callMcpTool : ( ) => Effect . die ( "unexpected MCP tool call" ) ,
529+ listPermissionRules : Effect . die ( "unexpected permission rules read" ) ,
530+ stopTask : ( ) => Effect . void ,
531+ interrupt : Effect . die ( "an effort change must not interrupt the turn" ) ,
532+ close : Effect . void ,
533+ } ) ,
534+ forkSession : ( ) => Effect . die ( "unused" ) ,
535+ subagentLaunchToolUseId : ( ) => Effect . succeed ( null ) ,
536+ assertComplete : Effect . void ,
537+ } ,
538+ } ) ;
539+ yield * Effect . gen ( function * ( ) {
540+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
541+ const worker = yield * EffectWorker . OrchestrationEffectWorkerV2 ;
542+ const threadId = ThreadId . make ( "thread:live-effort" ) ;
543+ const high = { ...modelSelection , options : [ { id : "effort" , value : "high" } ] } ;
544+ const running = yield * orchestrator . streamDomainEvents . pipe (
545+ Stream . filter (
546+ ( event ) => event . type === "provider-turn.updated" && event . payload . status === "running" ,
547+ ) ,
548+ Stream . take ( 1 ) ,
549+ Stream . runDrain ,
550+ Effect . forkScoped ,
551+ ) ;
552+ yield * orchestrator . dispatch ( {
553+ type : "thread.create" ,
554+ commandId : CommandId . make ( "create" ) ,
555+ threadId,
556+ projectId : ProjectId . make ( "project:live-effort" ) ,
557+ title : "Live effort" ,
558+ modelSelection : high ,
559+ runtimeMode : "full-access" ,
560+ interactionMode : "default" ,
561+ branch : null ,
562+ worktreePath : cwd ,
563+ createdBy : "user" ,
564+ creationSource : "web" ,
565+ } ) ;
566+ yield * orchestrator . dispatch ( {
567+ type : "message.dispatch" ,
568+ commandId : CommandId . make ( "first" ) ,
569+ threadId,
570+ messageId : MessageId . make ( "first" ) ,
571+ text : "Keep working." ,
572+ attachments : [ ] ,
573+ dispatchMode : { type : "start_immediately" } ,
574+ createdBy : "user" ,
575+ creationSource : "web" ,
576+ } ) ;
577+ yield * worker . drain ( ) ;
578+ yield * Fiber . join ( running ) ;
579+ assert . deepEqual ( flagSettings , [ ] ) ;
580+
581+ yield * orchestrator . dispatch ( {
582+ type : "thread.model-selection.set" ,
583+ commandId : CommandId . make ( "medium" ) ,
584+ threadId,
585+ modelSelection : { ...modelSelection , options : [ { id : "effort" , value : "medium" } ] } ,
586+ } ) ;
587+ yield * worker . drain ( ) ;
588+
589+ assert . deepEqual ( flagSettings , [
590+ { effortLevel : "medium" , fastMode : null , ultracode : null } ,
591+ ] ) ;
592+ } ) . pipe (
593+ Effect . provide (
594+ ProviderReplayHarness . layerWithRegistry (
595+ { name : "claude-live-effort" } ,
596+ ProviderAdapterRegistry . layerSingle ( adapter ) ,
597+ { runEffectWorker : false } ,
598+ ) ,
599+ ) ,
600+ ) ;
601+ } ) . pipe (
602+ Effect . provide (
603+ Layer . mergeAll (
604+ IdAllocator . layer ,
605+ McpProviderSessions . layer ,
606+ NodeServices . layer ,
607+ NodeCrypto . layer ,
608+ ) ,
609+ ) ,
610+ ) ,
611+ ) ,
612+ ) ;
0 commit comments