Skip to content

Commit b8544ac

Browse files
authored
Merge pull request #82 from dwash96/v0.88.5
V0.88.5
2 parents 6752d11 + 00992d4 commit b8544ac

13 files changed

Lines changed: 187 additions & 82 deletions

File tree

aider/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from packaging import version
22

3-
__version__ = "0.88.4.dev"
3+
__version__ = "0.88.5.dev"
44
safe_version = __version__
55

66
try:

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: 72 additions & 3 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:
@@ -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

aider/commands.py

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def __init__(
8484

8585
# Store the original read-only filenames provided via args.read
8686
self.original_read_only_fnames = set(original_read_only_fnames or [])
87+
self.cmd_running = False
8788

8889
def cmd_model(self, args):
8990
"Switch the Main Model to a new LLM"
@@ -256,6 +257,9 @@ async def cmd_web(self, args, return_content=False):
256257
def is_command(self, inp):
257258
return inp[0] in "/!"
258259

260+
def is_run_command(self, inp):
261+
return inp and (inp[0] in "!" or inp[:5] == "/test" or inp[:4] == "/run")
262+
259263
def get_raw_completions(self, cmd):
260264
assert cmd.startswith("/")
261265
cmd = cmd[1:]
@@ -1151,51 +1155,61 @@ async def cmd_test(self, args):
11511155

11521156
async def cmd_run(self, args, add_on_nonzero_exit=False):
11531157
"Run a shell command and optionally add the output to the chat (alias: !)"
1154-
exit_status, combined_output = await asyncio.to_thread(
1155-
run_cmd,
1156-
args,
1157-
verbose=self.verbose,
1158-
error_print=self.io.tool_error,
1159-
cwd=self.coder.root,
1160-
)
1158+
try:
1159+
self.cmd_running = True
1160+
exit_status, combined_output = await asyncio.to_thread(
1161+
run_cmd,
1162+
args,
1163+
verbose=self.verbose,
1164+
error_print=self.io.tool_error,
1165+
cwd=self.coder.root,
1166+
)
1167+
self.cmd_running = False
11611168

1162-
if combined_output is None:
1163-
return
1169+
# This print statement, for whatever reason,
1170+
# allows the thread to properly yield control of the terminal
1171+
# to the main program
1172+
print("")
11641173

1165-
# Calculate token count of output
1166-
token_count = self.coder.main_model.token_count(combined_output)
1167-
k_tokens = token_count / 1000
1174+
if combined_output is None:
1175+
return
11681176

1169-
if add_on_nonzero_exit:
1170-
add = exit_status != 0
1171-
else:
1172-
add = await self.io.confirm_ask(
1173-
f"Add {k_tokens:.1f}k tokens of command output to the chat?"
1174-
)
1177+
# Calculate token count of output
1178+
token_count = self.coder.main_model.token_count(combined_output)
1179+
k_tokens = token_count / 1000
11751180

1176-
if add:
1177-
num_lines = len(combined_output.strip().splitlines())
1178-
line_plural = "line" if num_lines == 1 else "lines"
1179-
self.io.tool_output(f"Added {num_lines} {line_plural} of output to the chat.")
1181+
if add_on_nonzero_exit:
1182+
add = exit_status != 0
1183+
else:
1184+
add = await self.io.confirm_ask(
1185+
f"Add {k_tokens:.1f}k tokens of command output to the chat?"
1186+
)
11801187

1181-
msg = prompts.run_output.format(
1182-
command=args,
1183-
output=combined_output,
1184-
)
1188+
if add:
1189+
num_lines = len(combined_output.strip().splitlines())
1190+
line_plural = "line" if num_lines == 1 else "lines"
1191+
self.io.tool_output(f"Added {num_lines} {line_plural} of output to the chat.")
11851192

1186-
self.coder.cur_messages += [
1187-
dict(role="user", content=msg),
1188-
dict(role="assistant", content="Ok."),
1189-
]
1193+
msg = prompts.run_output.format(
1194+
command=args,
1195+
output=combined_output,
1196+
)
1197+
1198+
self.coder.cur_messages += [
1199+
dict(role="user", content=msg),
1200+
dict(role="assistant", content="Ok."),
1201+
]
11901202

1191-
if add_on_nonzero_exit and exit_status != 0:
1192-
# Return the formatted output message for test failures
1193-
return msg
1194-
elif add and exit_status != 0:
1195-
self.io.placeholder = "What's wrong? Fix"
1203+
if add_on_nonzero_exit and exit_status != 0:
1204+
# Return the formatted output message for test failures
1205+
return msg
1206+
elif add and exit_status != 0:
1207+
self.io.placeholder = "What's wrong? Fix"
11961208

1197-
# Return None if output wasn't added or command succeeded
1198-
return None
1209+
# Return None if output wasn't added or command succeeded
1210+
return None
1211+
finally:
1212+
self.cmd_running = False
11991213

12001214
def cmd_exit(self, args):
12011215
"Exit the application"

0 commit comments

Comments
 (0)