Skip to content

Commit 00992d4

Browse files
committed
#48: Add linear_output mode because it is theorhetically more accessible
1 parent 860804a commit 00992d4

5 files changed

Lines changed: 77 additions & 5 deletions

File tree

aider/args.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,12 @@ def get_parser(default_config_files, git_root):
315315
" (default: current directory)"
316316
),
317317
)
318-
318+
group.add_argument(
319+
"--map-memory-cache",
320+
action="store_true",
321+
help="Store repo map in memory (default: False)",
322+
default=False,
323+
)
319324
##########
320325
group = parser.add_argument_group("History Files")
321326
default_input_history_file = (
@@ -745,7 +750,14 @@ def get_parser(default_config_files, git_root):
745750
help="Print the system prompts and exit (debug)",
746751
default=False,
747752
)
748-
753+
group.add_argument(
754+
"--linear-output",
755+
action="store_true",
756+
help=(
757+
"Run input and output sequentially instead of us simultaneous streams (default: False)"
758+
),
759+
default=False,
760+
)
749761
##########
750762
group = parser.add_argument_group("Voice settings")
751763
group.add_argument(

aider/coders/base_coder.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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:

aider/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def is_command(self, inp):
258258
return inp[0] in "/!"
259259

260260
def is_run_command(self, inp):
261-
return inp[0] in "!" or inp[:5] == "/test" or inp[:4] == "/run"
261+
return inp and (inp[0] in "!" or inp[:5] == "/test" or inp[:4] == "/run")
262262

263263
def get_raw_completions(self, cmd):
264264
assert cmd.startswith("/")

aider/io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ async def cancel_input_task(self):
941941
try:
942942
input_task.cancel()
943943
await input_task
944-
except asyncio.CancelledError:
944+
except (asyncio.CancelledError, IndexError):
945945
pass
946946

947947
async def cancel_processing_task(self):
@@ -951,7 +951,7 @@ async def cancel_processing_task(self):
951951
try:
952952
processing_task.cancel()
953953
await processing_task
954-
except asyncio.CancelledError:
954+
except (asyncio.CancelledError, IndexError):
955955
pass
956956

957957
def add_to_input_history(self, inp):

aider/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,9 @@ def get_io(pretty):
10571057
context_compaction_max_tokens=args.context_compaction_max_tokens,
10581058
context_compaction_summary_tokens=args.context_compaction_summary_tokens,
10591059
map_cache_dir=args.map_cache_dir,
1060+
repomap_in_memory=args.map_memory_cache,
1061+
preserve_todo_list=args.preserve_todo_list,
1062+
linear_output=args.linear_output,
10601063
)
10611064
except UnknownEditFormat as err:
10621065
io.tool_error(str(err))

0 commit comments

Comments
 (0)