mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
* hacky solution for interactive commands * add more behavior * debug * fix continue functionality * remove prints * refactor a bit * reduce test sleep * fix python version * fix pre-commit issue * Regenerate integration tests * Update openhands/runtime/client/client.py * revert some prompt stuff * several integration mock files regenerated * execute_action: remove duplicate exception logging --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: tobitege <10787084+tobitege@users.noreply.github.com>
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
import bashlex
|
|
|
|
from openhands.core.logger import openhands_logger as logger
|
|
|
|
|
|
def split_bash_commands(commands):
|
|
if not commands.strip():
|
|
return ['']
|
|
try:
|
|
parsed = bashlex.parse(commands)
|
|
except bashlex.errors.ParsingError as e:
|
|
logger.debug(
|
|
f'Failed to parse bash commands\n'
|
|
f'[input]: {commands}\n'
|
|
f'[warning]: {e}\n'
|
|
f'The original command will be returned as is.'
|
|
)
|
|
# If parsing fails, return the original commands
|
|
return [commands]
|
|
|
|
result: list[str] = []
|
|
last_end = 0
|
|
|
|
for node in parsed:
|
|
start, end = node.pos
|
|
|
|
# Include any text between the last command and this one
|
|
if start > last_end:
|
|
between = commands[last_end:start]
|
|
logger.debug(f'BASH PARSING between: {between}')
|
|
if result:
|
|
result[-1] += between.rstrip()
|
|
elif between.strip():
|
|
# THIS SHOULD NOT HAPPEN
|
|
result.append(between.rstrip())
|
|
|
|
# Extract the command, preserving original formatting
|
|
command = commands[start:end].rstrip()
|
|
logger.debug(f'BASH PARSING command: {command}')
|
|
result.append(command)
|
|
|
|
last_end = end
|
|
|
|
# Add any remaining text after the last command to the last command
|
|
remaining = commands[last_end:].rstrip()
|
|
logger.debug(f'BASH PARSING remaining: {remaining}')
|
|
if last_end < len(commands) and result:
|
|
result[-1] += remaining
|
|
logger.debug(f'BASH PARSING result[-1] += remaining: {result[-1]}')
|
|
elif last_end < len(commands):
|
|
if remaining:
|
|
result.append(remaining)
|
|
logger.debug(f'BASH PARSING result.append(remaining): {result[-1]}')
|
|
return result
|