@@ -50,6 +50,7 @@ import * as ServerSettings from "../serverSettings.ts";
5050import * as ScheduledTasks from "../scheduledTasks/ScheduledTaskService.ts" ;
5151import * as SecretRequests from "../secrets/SecretRequests.ts" ;
5252import * as TextGeneration from "../textGeneration/TextGeneration.ts" ;
53+ import { ClaudeProviderCapabilitiesV2 } from "./Adapters/ClaudeAdapterV2.ts" ;
5354import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts" ;
5455import * as CommandReceiptStore from "./CommandReceiptStore.ts" ;
5556import * as EffectOutbox from "./EffectOutbox.ts" ;
@@ -96,6 +97,18 @@ const adapter = {
9697 openSession : ( ) => Effect . die ( "provider execution is disabled in launch tests" ) ,
9798} as ProviderAdapter . ProviderAdapterV2 [ "Service" ] ;
9899
100+ const claudeModelSelection = {
101+ instanceId : ProviderInstanceId . make ( "claudeAgent" ) ,
102+ model : "claude-opus-5-5" ,
103+ } as const ;
104+ const claudeAdapter = {
105+ instanceId : claudeModelSelection . instanceId ,
106+ driver : ProviderDriverKind . make ( "claudeAgent" ) ,
107+ getCapabilities : ( ) => Effect . succeed ( ClaudeProviderCapabilitiesV2 ) ,
108+ planSelectionTransition : ( ) => Effect . succeed ( { type : "apply_on_next_turn" as const } ) ,
109+ openSession : ( ) => Effect . die ( "provider execution is disabled in launch tests" ) ,
110+ } as ProviderAdapter . ProviderAdapterV2 [ "Service" ] ;
111+
99112interface HarnessOptions {
100113 readonly managedFolders ?: Layer . Layer < ManagedProjectFolders . ManagedProjectFolders > ;
101114 readonly createWorktree ?: GitWorkflow . GitWorkflowService [ "Service" ] [ "createWorktree" ] ;
@@ -112,7 +125,7 @@ interface HarnessOptions {
112125
113126function makeHarness ( options : HarnessOptions = { } ) {
114127 const layerDatabase = SqlitePersistence . layerMemory ;
115- const layerRegistry = ProviderAdapterRegistry . layerFromAdapters ( [ adapter ] ) ;
128+ const layerRegistry = ProviderAdapterRegistry . layerFromAdapters ( [ adapter , claudeAdapter ] ) ;
116129 const layerOrchestrator = ProviderReplayHarness . layerWithRegistry (
117130 { name : "thread-launch" } ,
118131 layerRegistry ,
@@ -365,6 +378,59 @@ it.effect.each(
365378 } ,
366379) ;
367380
381+ it . effect ( "runs a thread-bound automation on the provider the thread uses now" , ( ) => {
382+ const harness = makeHarness ( ) ;
383+ const layerScheduledTasks = ScheduledTasks . layer . pipe (
384+ Layer . provide (
385+ Layer . mergeAll (
386+ harness . layer ,
387+ NodeCrypto . layer ,
388+ Scheduler . layer ,
389+ Layer . mock ( SecretRequests . SecretRequests ) ( { } ) ,
390+ ) ,
391+ ) ,
392+ ) ;
393+ return Effect . gen ( function * ( ) {
394+ const tasks = yield * ScheduledTasks . ScheduledTaskService ;
395+ const launches = yield * ThreadLaunch . ThreadLaunchService ;
396+ const threads = yield * ThreadManagement . ThreadManagementService ;
397+ const launched = yield * launches . launch (
398+ launchInput ( { command : "command:switched" , thread : "thread:switched" } ) ,
399+ ) ;
400+ // The task is created while the thread is on Codex...
401+ const { task } = yield * tasks . upsert ( {
402+ id : ScheduledTaskId . make ( "scheduled-task:switched" ) ,
403+ title : "Hourly check" ,
404+ prompt : "Check on the delegated workers." ,
405+ enabled : false ,
406+ schedule : { type : "interval" , everyMs : 3_600_000 } ,
407+ projectId,
408+ threadId : launched . threadId ,
409+ workspaceStrategy : { type : "root" } ,
410+ modelSelection,
411+ runtimeMode : "full-access" ,
412+ interactionMode : "default" ,
413+ createdBy : "agent" ,
414+ creationSource : "mcp" ,
415+ } ) ;
416+ // ...and the user then switches the thread to Claude.
417+ yield * threads . dispatch ( {
418+ type : "thread.model-selection.set" ,
419+ commandId : CommandId . make ( "command:switch-to-claude" ) ,
420+ threadId : launched . threadId ,
421+ modelSelection : claudeModelSelection ,
422+ } ) ;
423+
424+ const result = yield * tasks . runNow ( { id : task . id } ) ;
425+ assert . equal ( result . task . lastRunStatus , "succeeded" ) ;
426+ const projection = yield * threads . getThreadProjection ( launched . threadId ) ;
427+ const message = projection . messages . find ( ( item ) => item . scheduledTaskId === task . id ) ;
428+ const run = projection . runs . find ( ( item ) => item . id === message ?. runId ) ;
429+ assert . deepStrictEqual ( run ?. modelSelection , claudeModelSelection ) ;
430+ assert . deepStrictEqual ( projection . thread . modelSelection , claudeModelSelection ) ;
431+ } ) . pipe ( Effect . provide ( Layer . mergeAll ( harness . layer , layerScheduledTasks ) ) ) ;
432+ } ) ;
433+
368434it . effect ( "retains automation and sender attribution while a message waits in the queue" , ( ) => {
369435 const harness = makeHarness ( { runSetup : ( ) => Effect . never } ) ;
370436 return Effect . gen ( function * ( ) {
0 commit comments