@@ -381,6 +381,7 @@ def __init__(
381381 map_cache_dir = "." ,
382382 repomap_in_memory = False ,
383383 preserve_todo_list = False ,
384+ linear_output = False ,
384385 ):
385386 # initialize from args.map_cache_dir
386387 self .map_cache_dir = map_cache_dir
@@ -469,6 +470,7 @@ def __init__(
469470
470471 self .dry_run = dry_run
471472 self .pretty = self .io .pretty
473+ self .linear_output = linear_output
472474
473475 self .main_model = main_model
474476
@@ -1058,12 +1060,67 @@ async def run(self, with_message=None, preproc=True):
10581060 while self .io .confirmation_in_progress :
10591061 await asyncio .sleep (0.1 ) # Yield control and wait briefly
10601062
1063+ if self .linear_output :
1064+ return await self ._run_linear (with_message , preproc )
1065+
10611066 if self .io .prompt_session :
10621067 with patch_stdout (raw = True ):
10631068 return await self ._run_patched (with_message , preproc )
10641069 else :
10651070 return await self ._run_patched (with_message , preproc )
10661071
1072+ async def _run_linear (self , with_message = None , preproc = True ):
1073+ try :
1074+ if with_message :
1075+ self .io .user_input (with_message )
1076+ await self .run_one (with_message , preproc )
1077+ return self .partial_response_content
1078+
1079+ user_message = None
1080+ await self .io .cancel_input_task ()
1081+ await self .io .cancel_processing_task ()
1082+
1083+ while True :
1084+ try :
1085+ if self .commands .cmd_running :
1086+ await asyncio .sleep (0.1 )
1087+ continue
1088+
1089+ if not self .suppress_announcements_for_next_prompt :
1090+ self .show_announcements ()
1091+ self .suppress_announcements_for_next_prompt = True
1092+
1093+ self .io .input_task = asyncio .create_task (self .get_input ())
1094+ await asyncio .sleep (0 )
1095+ await self .io .input_task
1096+ user_message = self .io .input_task .result ()
1097+
1098+ self .io .processing_task = asyncio .create_task (
1099+ self ._processing_logic (user_message , preproc )
1100+ )
1101+
1102+ await self .io .processing_task
1103+
1104+ self .io .ring_bell ()
1105+ user_message = None
1106+ except KeyboardInterrupt :
1107+ if self .io .input_task :
1108+ self .io .set_placeholder ("" )
1109+ await self .io .cancel_input_task ()
1110+
1111+ if self .io .processing_task :
1112+ await self .io .cancel_processing_task ()
1113+ self .io .stop_spinner ()
1114+
1115+ self .keyboard_interrupt ()
1116+ except (asyncio .CancelledError , IndexError ):
1117+ pass
1118+ except EOFError :
1119+ return
1120+ finally :
1121+ await self .io .cancel_input_task ()
1122+ await self .io .cancel_processing_task ()
1123+
10671124 async def _run_patched (self , with_message = None , preproc = True ):
10681125 try :
10691126 if with_message :
@@ -1077,6 +1134,10 @@ async def _run_patched(self, with_message=None, preproc=True):
10771134
10781135 while True :
10791136 try :
1137+ if self .commands .cmd_running :
1138+ await asyncio .sleep (0.1 )
1139+ continue
1140+
10801141 if (
10811142 not self .io .confirmation_in_progress
10821143 and not user_message
@@ -1134,6 +1195,10 @@ async def _run_patched(self, with_message=None, preproc=True):
11341195 try :
11351196 user_message = self .io .input_task .result ()
11361197 await self .io .cancel_input_task ()
1198+
1199+ if self .commands .is_run_command (user_message ):
1200+ self .commands .cmd_running = True
1201+
11371202 except (asyncio .CancelledError , KeyboardInterrupt ):
11381203 user_message = None
11391204
@@ -1170,7 +1235,6 @@ async def _run_patched(self, with_message=None, preproc=True):
11701235 user_message = None
11711236
11721237 except (asyncio .CancelledError , KeyboardInterrupt ):
1173- print ("error of some sort" )
11741238 pass
11751239
11761240 # Stop spinner when processing task completes
@@ -1180,6 +1244,7 @@ async def _run_patched(self, with_message=None, preproc=True):
11801244 self .io .processing_task = asyncio .create_task (
11811245 self ._processing_logic (user_message , preproc )
11821246 )
1247+
11831248 # Start spinner for processing task
11841249 self .io .start_spinner ("Processing..." )
11851250
@@ -1243,6 +1308,12 @@ async def preproc_user_input(self, inp):
12431308 return
12441309
12451310 if self .commands .is_command (inp ):
1311+ if inp [0 ] in "!" :
1312+ inp = f"/run { inp [1 :]} "
1313+
1314+ if self .commands .is_run_command (inp ):
1315+ self .commands .cmd_running = True
1316+
12461317 return await self .commands .run (inp )
12471318
12481319 await self .check_for_file_mentions (inp )
@@ -1254,8 +1325,6 @@ async def run_one(self, user_message, preproc):
12541325 self .init_before_message ()
12551326
12561327 if preproc :
1257- if user_message [0 ] in "!" :
1258- user_message = f"/run { user_message [1 :]} "
12591328 message = await self .preproc_user_input (user_message )
12601329 else :
12611330 message = user_message
0 commit comments