@@ -51,6 +51,8 @@ use crate::sandbox_cli::{
5151 resolve_effective_sandbox_state_with_defaults, sandbox_plan_requests_inherited_state,
5252 validate_sandbox_plan_with_defaults,
5353} ;
54+ use crate :: stdin_payload:: prepare_worker_stdin_payload;
55+ pub ( crate ) use crate :: stdin_payload:: { WriteStdinControlAction , split_write_stdin_control_prefix} ;
5456use crate :: worker_protocol:: {
5557 ContentOrigin , TextStream , WORKER_MODE_ARG , WorkerContent , WorkerErrorCode , WorkerReply ,
5658} ;
@@ -276,7 +278,14 @@ fn prechecked_follow_up_requires_meta_error() -> WorkerError {
276278}
277279
278280trait BackendDriver : Send {
279- fn prepare_input_payload ( & self , text : & str ) -> Vec < u8 > ;
281+ fn prepare_input_text ( & self , text : String ) -> String {
282+ text
283+ }
284+
285+ fn prepare_input_payload ( & self , text : & str ) -> Vec < u8 > {
286+ prepare_worker_stdin_payload ( text)
287+ }
288+
280289 fn on_input_start (
281290 & mut self ,
282291 text : & str ,
@@ -474,13 +483,8 @@ fn driver_refresh_worker_ready(
474483}
475484
476485impl BackendDriver for RBackendDriver {
477- fn prepare_input_payload ( & self , text : & str ) -> Vec < u8 > {
478- let normalized = normalize_input_newlines ( text) ;
479- let mut payload = normalized. into_bytes ( ) ;
480- if !payload. is_empty ( ) && !payload. ends_with ( b"\n " ) {
481- payload. push ( b'\n' ) ;
482- }
483- payload
486+ fn prepare_input_text ( & self , text : String ) -> String {
487+ normalize_input_newlines ( & text)
484488 }
485489
486490 fn on_input_start (
@@ -852,14 +856,6 @@ fn strip_one_line_ending(text: &str) -> Option<&str> {
852856
853857#[ cfg( not( target_family = "unix" ) ) ]
854858impl BackendDriver for PythonBackendDriver {
855- fn prepare_input_payload ( & self , text : & str ) -> Vec < u8 > {
856- let mut payload = text. as_bytes ( ) . to_vec ( ) ;
857- if !payload. is_empty ( ) && !payload. ends_with ( b"\n " ) {
858- payload. push ( b'\n' ) ;
859- }
860- payload
861- }
862-
863859 fn on_input_start (
864860 & mut self ,
865861 text : & str ,
@@ -936,14 +932,6 @@ impl ProtocolBackendDriver {
936932}
937933
938934impl BackendDriver for ProtocolBackendDriver {
939- fn prepare_input_payload ( & self , text : & str ) -> Vec < u8 > {
940- let mut payload = text. as_bytes ( ) . to_vec ( ) ;
941- if !payload. is_empty ( ) && !payload. ends_with ( b"\n " ) {
942- payload. push ( b'\n' ) ;
943- }
944- payload
945- }
946-
947935 fn on_input_start (
948936 & mut self ,
949937 _text : & str ,
@@ -1198,12 +1186,6 @@ fn completion_info_from_ipc(
11981186
11991187const DEFERRED_SANDBOX_UPDATE_TIMEOUT : Duration = Duration :: from_secs ( 5 ) ;
12001188
1201- #[ derive( Clone , Copy ) ]
1202- pub ( crate ) enum WriteStdinControlAction {
1203- Interrupt ,
1204- Restart ,
1205- }
1206-
12071189#[ derive( Debug , Clone , Default ) ]
12081190pub ( crate ) struct WriteStdinOptions {
12091191 pub page_bytes_override : Option < u64 > ,
@@ -1225,19 +1207,6 @@ impl WriteStdinOptions {
12251207 }
12261208}
12271209
1228- pub ( crate ) fn split_write_stdin_control_prefix (
1229- input : & str ,
1230- ) -> Option < ( WriteStdinControlAction , & str ) > {
1231- let first = input. chars ( ) . next ( ) ?;
1232- let action = match first {
1233- '\u{3}' => WriteStdinControlAction :: Interrupt ,
1234- '\u{4}' => WriteStdinControlAction :: Restart ,
1235- _ => return None ,
1236- } ;
1237-
1238- Some ( ( action, & input[ first. len_utf8 ( ) ..] ) )
1239- }
1240-
12411210fn worker_context_event_payload (
12421211 worker_launch : & WorkerLaunch ,
12431212 backend : Backend ,
@@ -2566,6 +2535,7 @@ impl WorkerManager {
25662535 worker_timeout : Duration ,
25672536 server_timeout : Duration ,
25682537 ) -> Result < RequestState , WorkerError > {
2538+ let text = self . driver . prepare_input_text ( text) ;
25692539 let started_at = std:: time:: Instant :: now ( ) ;
25702540 let prompt = self . current_prompt_hint ( ) ;
25712541 self . remember_prompt ( prompt) ;
0 commit comments