3232
3333import importlib .util
3434from collections .abc import Mapping , Sequence
35+ from pathlib import Path
3536from typing import Any , Callable
3637
3738from ..operator_credential import (
@@ -185,16 +186,27 @@ def _with_operation_transport(
185186 sandbox : str ,
186187 model : str | None ,
187188 reasoning_effort : str | None ,
188- dsh_operation_module_configured : bool = False ,
189+ dsh_operation_module_configured : bool ,
190+ dsh_operation_module_path : str | None ,
191+ dsh_runner_configured : bool ,
189192) -> dict [str , Any ]:
190- if codex_operation_tools or dsh_operation_module_configured :
193+ if codex_operation_tools or dsh_operation_module_configured or dsh_operation_module_path :
191194 from ..effect_runtime import effect_runtime_result
192195
193196 observed = effect_runtime_result (
194197 "operation.managed_transport.project" ,
195- {"host" : host , "sandbox" : sandbox , "codex_operation_tools" : codex_operation_tools ,
196- "dsh_operation_module_configured" : dsh_operation_module_configured ,
197- "model" : model , "reasoning_effort" : reasoning_effort },
198+ {
199+ "host" : host ,
200+ "sandbox" : sandbox ,
201+ "codex_operation_tools" : codex_operation_tools ,
202+ "dsh_operation_module_configured" : dsh_operation_module_configured or bool (dsh_operation_module_path ),
203+ "dsh_operation_module_absolute" : (
204+ Path (dsh_operation_module_path ).is_absolute () if dsh_operation_module_path else None
205+ ),
206+ "dsh_runner_configured" : dsh_runner_configured ,
207+ "model" : model ,
208+ "reasoning_effort" : reasoning_effort ,
209+ },
198210 )
199211 binding ["operation_transport" ] = observed ["transport" ]
200212 if observed ["reason" ]:
@@ -216,6 +228,7 @@ def managed_executor_binding(
216228 max_tokens : int | None = None ,
217229 codex_operation_tools : bool = False ,
218230 dsh_operation_module_configured : bool = False ,
231+ dsh_operation_module_path : str | None = None ,
219232 codex_sandbox : str = "read-only" ,
220233) -> dict [str , Any ]:
221234 """Project the executor one planned Turn would run on.
@@ -286,6 +299,7 @@ def managed_executor_binding(
286299 binding , codex_operation_tools = codex_operation_tools , host = host ,
287300 sandbox = codex_sandbox , model = profile ["model" ], reasoning_effort = profile ["reasoning_effort" ],
288301 dsh_operation_module_configured = dsh_operation_module_configured ,
302+ dsh_operation_module_path = dsh_operation_module_path , dsh_runner_configured = dsh_runner_configured ,
289303 )
290304 individual_profile : str | None = None
291305 if host == INDIVIDUAL_TURN_HOST and (model or reasoning_effort ):
@@ -315,28 +329,27 @@ def managed_executor_binding(
315329 binding , codex_operation_tools = codex_operation_tools , host = host ,
316330 sandbox = codex_sandbox , model = model , reasoning_effort = reasoning_effort ,
317331 dsh_operation_module_configured = dsh_operation_module_configured ,
332+ dsh_operation_module_path = dsh_operation_module_path , dsh_runner_configured = dsh_runner_configured ,
318333 )
319334
320335
321- def turn_host_arg_option (host_args : Sequence [str ], name : str ) -> str | None :
336+ def turn_host_arg_option (host_args : Sequence [str ], name : str , * , strip : bool = True ) -> str | None :
322337 """Return the value the Turn CLI will use for one repeatable argv option."""
323338 args = [str (value ) for value in host_args ]
324339 selected : str | None = None
325340 for index , value in enumerate (args ):
326- if value .startswith (f"{ name } =" ):
327- candidate = value .partition ("=" )[2 ].strip ()
328- if not candidate :
329- return None
330- selected = candidate
331341 if value == name :
332342 if index + 1 >= len (args ):
333343 return None
334- candidate = args [index + 1 ].strip ()
335- # argparse treats another option token as a missing value for this
336- # option. Keep the read model fail-closed in the same case.
337- if not candidate or candidate .startswith ("--" ):
338- return None
339- selected = candidate
344+ raw = args [index + 1 ]
345+ elif value .startswith (f"{ name } =" ):
346+ raw = value .partition ("=" )[2 ]
347+ else :
348+ continue
349+ candidate = raw .strip () if strip else raw
350+ if (strip and not candidate ) or (value == name and candidate .startswith ("--" )):
351+ return None
352+ selected = candidate or None
340353 return selected
341354
342355
@@ -355,6 +368,7 @@ def managed_executor_binding_from_host_args(
355368 """
356369
357370 host = turn_host_arg_option (host_args , "--host" ) or "unknown"
371+ module_path = turn_host_arg_option (host_args , "--dsh-operation-module" , strip = False )
358372 return managed_executor_binding (
359373 host ,
360374 environ = environ ,
@@ -379,7 +393,10 @@ def managed_executor_binding_from_host_args(
379393 else None
380394 ),
381395 codex_operation_tools = "--codex-operation-tools" in host_args ,
382- dsh_operation_module_configured = bool (turn_host_arg_option (host_args , "--dsh-operation-module" )),
396+ dsh_operation_module_path = module_path ,
397+ # A custom runner conflicts with the native module. Leave ordinary
398+ # delegation readiness on its existing probe and credential checks.
399+ dsh_runner_configured = bool (module_path and turn_host_arg_option (host_args , "--dsh-runner" , strip = False )),
383400 codex_sandbox = turn_host_arg_option (host_args , "--codex-sandbox" ) or "read-only" ,
384401 )
385402
0 commit comments