|
1 | 1 | # OpenHands CLI |
2 | 2 |
|
3 | | -A command-line interface for OpenHands AI Agent with Terminal User Interface (TUI) support. |
| 3 | +A lightweight CLI/TUI to interact with the OpenHands agent (powered by agent-sdk). Build and run locally or as a single executable. |
4 | 4 |
|
5 | | -## Development |
| 5 | +## Quickstart |
6 | 6 |
|
7 | | -### Setup |
8 | | - |
9 | | -1. Install dependencies: |
10 | | - ```bash |
11 | | - make install-dev |
12 | | - ``` |
13 | | - |
14 | | -2. Install pre-commit hooks: |
15 | | - ```bash |
16 | | - make install-pre-commit-hooks |
17 | | - ``` |
18 | | - |
19 | | -### Code Quality |
20 | | - |
21 | | -This project uses pre-commit hooks to ensure code quality. The following tools are configured: |
22 | | - |
23 | | -- **Ruff**: Fast Python linter and formatter |
24 | | -- **MyPy**: Static type checking |
25 | | -- **Pre-commit hooks**: Various code quality checks |
26 | | - |
27 | | -#### Running Linters |
28 | | - |
29 | | -```bash |
30 | | -# Run all pre-commit hooks |
31 | | -make lint |
32 | | - |
33 | | -# Format code |
34 | | -make format # Format code with ruff |
35 | | -``` |
36 | | - |
37 | | -#### Pre-commit Hooks |
38 | | - |
39 | | -Pre-commit hooks will automatically run on every commit. To run them manually: |
| 7 | +- Prerequisites: Python 3.12+, curl |
| 8 | +- Install uv (package manager): |
| 9 | + ```bash |
| 10 | + curl -LsSf https://astral.sh/uv/install.sh | sh |
| 11 | + # Restart your shell so "uv" is on PATH, or follow the installer hint |
| 12 | + ``` |
40 | 13 |
|
| 14 | +### Run the CLI locally |
41 | 15 | ```bash |
42 | | -# Run on all files |
43 | | -uv run pre-commit run --all-files |
44 | | - |
45 | | -# Run on staged files only |
46 | | -uv run pre-commit run |
47 | | -``` |
48 | | - |
49 | | -### Available Commands |
50 | | - |
51 | | -Run `make help` to see all available commands: |
52 | | - |
53 | | -```bash |
54 | | -make help |
55 | | -``` |
56 | | - |
57 | | -## Binary Packaging |
58 | | - |
59 | | -The OpenHands CLI can be packaged into a standalone executable binary using PyInstaller. This allows distribution of the CLI without requiring users to install Python or dependencies. |
60 | | - |
61 | | -### Building the Executable |
62 | | - |
63 | | -#### Quick Build |
| 16 | +# Install dependencies (incl. dev tools) |
| 17 | +make install-dev |
64 | 18 |
|
65 | | -Use the provided build script to create a standalone executable: |
| 19 | +# Optional: install pre-commit hooks |
| 20 | +make install-pre-commit-hooks |
66 | 21 |
|
67 | | -```bash |
68 | | -# Using shell script (recommended - handles installation automatically) |
69 | | -./build.sh --install-pyinstaller |
70 | | - |
71 | | -# Using Python script directly (requires PyInstaller to be pre-installed) |
72 | | -uv run python build.py |
| 22 | +# Start the CLI |
| 23 | +make run |
| 24 | +# or |
| 25 | +uv run openhands-cli |
73 | 26 | ``` |
74 | 27 |
|
75 | | -#### Manual Build |
76 | | - |
77 | | -You can also build manually using PyInstaller with uv: |
78 | | - |
| 28 | +Tip: Set your model key (one of) so the agent can talk to an LLM: |
79 | 29 | ```bash |
80 | | -# Install PyInstaller as dev dependency |
81 | | -uv add --dev pyinstaller |
82 | | - |
83 | | -# Build using the spec file |
84 | | -uv run pyinstaller openhands-cli.spec --clean |
| 30 | +export OPENAI_API_KEY=... |
| 31 | +# or |
| 32 | +export LITELLM_API_KEY=... |
85 | 33 | ``` |
86 | 34 |
|
87 | | -### Build Options |
88 | | - |
89 | | -The build script supports several options: |
90 | | - |
| 35 | +### Build a standalone executable |
91 | 36 | ```bash |
92 | | -# Install PyInstaller and build (shell script handles installation) |
| 37 | +# Build (installs PyInstaller if needed) |
93 | 38 | ./build.sh --install-pyinstaller |
94 | 39 |
|
95 | | -# Build without testing the executable |
96 | | -./build.sh --install-pyinstaller --no-test |
97 | | - |
98 | | -# Build without cleaning previous artifacts |
99 | | -./build.sh --install-pyinstaller --no-clean |
100 | | - |
101 | | -# Use a custom spec file |
102 | | -./build.sh --install-pyinstaller --spec custom.spec |
103 | | - |
104 | | -# Show help |
105 | | -./build.sh --help |
| 40 | +# The binary will be in dist/ |
| 41 | +./dist/openhands-cli # macOS/Linux |
| 42 | +# dist/openhands-cli.exe # Windows |
106 | 43 | ``` |
107 | 44 |
|
108 | | -**Note:** The shell script (`build.sh`) automatically handles PyInstaller installation when using the `--install-pyinstaller` flag. The Python script (`build.py`) can be used directly but requires PyInstaller to be pre-installed. |
109 | | - |
110 | | -### Output |
111 | | - |
112 | | -The build process creates: |
113 | | -- `dist/openhands-cli` - The standalone executable |
114 | | -- `build/` - Temporary build files (automatically cleaned) |
115 | | - |
116 | | -The executable is typically 10-15 MB and includes all necessary dependencies. |
117 | | - |
118 | | -### Testing the Executable |
119 | | - |
120 | | -The build script automatically tests the executable, but you can also test manually: |
121 | | - |
122 | | -```bash |
123 | | -# Run the executable |
124 | | -./dist/openhands-cli |
125 | | - |
126 | | -# Check that it displays the CLI interface |
127 | | -``` |
128 | | - |
129 | | -### Packaging Configuration |
130 | | - |
131 | | -The packaging is configured through: |
132 | | -- `openhands-cli.spec` - PyInstaller specification file |
133 | | -- `build.py` - Build automation script |
134 | | -- `build.sh` - Shell wrapper script |
135 | | - |
136 | | -The spec file is optimized for: |
137 | | -- Single-file executable |
138 | | -- Minimal size through exclusions |
139 | | -- All required dependencies included |
140 | | -- Console application mode |
| 45 | +For advanced development (adding deps, updating the spec file, debugging builds), see Development.md. |
0 commit comments