68 lines
1.8 KiB
Python
Executable File
68 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
OpenHands CLI wrapper for n8n integration
|
|
Usage: python3 /home/bam/run-openhands.py "task description"
|
|
"""
|
|
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
|
|
def run_openhands(task):
|
|
"""Run OpenHands with the given task"""
|
|
print(f"Running OpenHands with task: {task}")
|
|
|
|
# Start the openhands process
|
|
process = subprocess.Popen(
|
|
['/home/bam/.local/bin/openhands', '-t', task],
|
|
stdin=subprocess.PIPE,
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.STDOUT,
|
|
text=True,
|
|
bufsize=1
|
|
)
|
|
|
|
output_lines = []
|
|
confirming = False
|
|
|
|
try:
|
|
while True:
|
|
line = process.stdout.readline()
|
|
if not line and process.poll() is not None:
|
|
break
|
|
|
|
output_lines.append(line)
|
|
print(line, end='')
|
|
|
|
# Check if we're at a confirmation prompt
|
|
if 'Choose an option:' in line or 'Yes, proceed' in line:
|
|
confirming = True
|
|
time.sleep(1)
|
|
|
|
# Send auto-confirmation
|
|
if confirming:
|
|
print("Sending auto-confirmation...")
|
|
process.stdin.write("Always proceed (don't ask again)\n")
|
|
process.stdin.flush()
|
|
confirming = False
|
|
time.sleep(1)
|
|
|
|
process.wait()
|
|
return process.returncode
|
|
|
|
except KeyboardInterrupt:
|
|
process.terminate()
|
|
return 1
|
|
except Exception as e:
|
|
print(f"Error: {e}", file=sys.stderr)
|
|
process.terminate()
|
|
return 1
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) < 2:
|
|
print("Usage: python3 /home/bam/run-openhands.py 'task description'")
|
|
sys.exit(1)
|
|
|
|
task = sys.argv[1]
|
|
exit_code = run_openhands(task)
|
|
sys.exit(exit_code) |