|
19 | 19 | import sys |
20 | 20 | import tempfile |
21 | 21 | import time |
22 | | -from typing import Any, cast |
| 22 | +from typing import Any |
23 | 23 |
|
24 | 24 | from ...file_lock import exclusive_file_lock |
25 | 25 | from ..content_digest import BARE_SHA256_PATTERN |
|
29 | 29 | plan_stage_then_swap_prefetch, |
30 | 30 | ) |
31 | 31 | from .decision_capture import open_regular_capture |
| 32 | +from .host_input import ( |
| 33 | + HostInputRenderer, |
| 34 | + UNSET_HOST_INPUT_RENDERER, |
| 35 | + _safe_rendered_prompt, |
| 36 | + resolve_active_host_renderer as _resolve_active_host_renderer, |
| 37 | + resolve_host_input_renderer as resolve_host_input_renderer, |
| 38 | +) |
32 | 39 | from .quiet_turn_store import ( |
33 | 40 | QUIET_TURN_SKIP_SCHEMA_VERSION as QUIET_TURN_SKIP_SCHEMA_VERSION, |
34 | 41 | QUIET_TURN_STATE_SCHEMA_VERSION as QUIET_TURN_STATE_SCHEMA_VERSION, |
@@ -852,54 +859,6 @@ def _turn_epoch_inputs( |
852 | 859 | } |
853 | 860 |
|
854 | 861 |
|
855 | | -HostInputRenderer = Callable[[Mapping[str, Any]], str | None] |
856 | | -UNSET_HOST_INPUT_RENDERER: object = object() |
857 | | - |
858 | | - |
859 | | -def _render_codex_cli_host_input(request: Mapping[str, Any]) -> str: |
860 | | - from .codex_cli import _prompt |
861 | | - |
862 | | - return _prompt(request) |
863 | | - |
864 | | - |
865 | | -def _render_generic_cli_host_input(request: Mapping[str, Any]) -> str: |
866 | | - from .host_process_transport import serialize_generic_cli_host_input |
867 | | - |
868 | | - return serialize_generic_cli_host_input(request) |
869 | | - |
870 | | - |
871 | | -def _render_dsh_host_input(request: Mapping[str, Any]) -> str | None: |
872 | | - from .host_candidate import render_dsh_host_prompt |
873 | | - |
874 | | - return render_dsh_host_prompt(request) |
875 | | - |
876 | | - |
877 | | -def resolve_host_input_renderer(host: str | None) -> HostInputRenderer | None: |
878 | | - """Return the actual delivered host-input serializer for measurable hosts, or None.""" |
879 | | - normalized = (host or "").strip() |
880 | | - if normalized in {"codex", "codex-cli"}: |
881 | | - return _render_codex_cli_host_input |
882 | | - if normalized == "generic-cli": |
883 | | - return _render_generic_cli_host_input |
884 | | - if normalized == "dsh": |
885 | | - return _render_dsh_host_input |
886 | | - return None |
887 | | - |
888 | | - |
889 | | -def _safe_rendered_prompt( |
890 | | - request: Mapping[str, Any], |
891 | | - *, |
892 | | - renderer: HostInputRenderer | None = _render_codex_cli_host_input, |
893 | | -) -> str | None: |
894 | | - """Render the exact delivered host input when the host adapter is measurable.""" |
895 | | - if renderer is None: |
896 | | - return None |
897 | | - try: |
898 | | - return renderer(request) |
899 | | - except (ValueError, RuntimeError, TypeError, KeyError): |
900 | | - return None |
901 | | - |
902 | | - |
903 | 862 | _PROMPT_GATE_AUDIT_FIELDS = ( |
904 | 863 | "net_savings_tokens", |
905 | 864 | "cold_prefill_amortization_tokens", |
@@ -1154,18 +1113,6 @@ def _prompt_gate_policy( |
1154 | 1113 | return policy or None |
1155 | 1114 |
|
1156 | 1115 |
|
1157 | | -def _resolve_active_host_renderer( |
1158 | | - *, |
1159 | | - host: str | None, |
1160 | | - host_input_renderer: HostInputRenderer | None | object, |
1161 | | -) -> HostInputRenderer | None: |
1162 | | - if host_input_renderer is not UNSET_HOST_INPUT_RENDERER: |
1163 | | - return cast(HostInputRenderer | None, host_input_renderer) |
1164 | | - if host is not None: |
1165 | | - return resolve_host_input_renderer(host) |
1166 | | - return _render_codex_cli_host_input |
1167 | | - |
1168 | | - |
1169 | 1116 | def _adjudicate_candidate_prompt_gate( |
1170 | 1117 | *, |
1171 | 1118 | policy_cfg: Mapping[str, Any] | None, |
|
0 commit comments