Skip to content

Commit 1c82d0a

Browse files
rushilpatel0kopekC
andauthored
fix: add update command (#1257)
# Motivation <!-- Why is this change necessary? --> Make it easier for users to update their version of installed codegen # Content <!-- Please include a summary of the change --> - new command with args added to support updating the current codegen version - add a version check to the cli startup # Testing <!-- How was the change tested? --> # Please check the following before marking your PR as ready for review - [x] I have added tests for my changes - [x] I have updated the documentation or added new documentation as needed Co-authored-by: Edo Pujol <ed@codegen.com>
1 parent 8a77161 commit 1c82d0a

File tree

8 files changed

+815
-11
lines changed

8 files changed

+815
-11
lines changed

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,33 @@ if task.status == "completed":
5353

5454
## Installation and Usage
5555

56-
Install the SDK using pip or uv:
56+
Install the SDK using pip, pipx, or uv:
5757

5858
```bash
5959
pip install codegen
6060
# or
61-
uv pip install codegen
61+
pipx install codegen
62+
# or
63+
uv tool install codegen
6264
```
6365

66+
### Keeping Up to Date
67+
68+
The Codegen CLI includes a built-in self-update system:
69+
70+
```bash
71+
# Update to the latest version
72+
codegen update
73+
74+
# Check for available updates
75+
codegen update --check
76+
77+
# Update to a specific version
78+
codegen update --version 1.2.3
79+
```
80+
81+
The CLI automatically checks for updates daily and notifies you when a new version is available.
82+
6483
Get started at [codegen.com](https://codegen.com) and get your API token at [codegen.com/token](https://codegen.com/token).
6584

6685
You can interact with your AI engineer via API, or chat with it in Slack, Linear, Github, or on our website.

docs/introduction/cli.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,32 @@ codegen login
4848
codegen login --token YOUR_API_TOKEN
4949
```
5050

51+
### `codegen update`
52+
53+
Keep your CLI up to date with the latest features and improvements. The CLI automatically checks for updates daily and notifies you when new versions are available.
54+
55+
```bash
56+
# Update to latest version
57+
codegen update
58+
59+
# Check for updates without installing
60+
codegen update --check
61+
62+
# Update to a specific version
63+
codegen update --version 1.2.3
64+
65+
# Preview changes without updating
66+
codegen update --dry-run
67+
```
68+
5169
## What You Can Do
5270

5371
- **View and manage agents** - List agent runs, check status, and see detailed execution logs
5472
- **Pull agent work** - Download branches and code changes created by agents directly to your local environment
5573
- **Create new agents** - Trigger agent runs from the command line with custom prompts
5674
- **Run Claude Code** - Execute Claude Code with OpenTelemetry monitoring and comprehensive logging
5775
- **Manage organizations** - Switch between organizations and configure repositories
76+
- **Stay up to date** - Built-in self-update system with automatic update notifications
5877

5978
<Note>
6079
The CLI provides the same capabilities as the web UI and API, optimized for

docs/introduction/sdk.mdx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,31 @@ if task.status == "completed":
3131

3232
## Installation
3333

34-
Install the [codegen](https://pypi.org/project/codegen/) package from PyPI:
34+
Install the [codegen](https://pypi.org/project/codegen/) package from PyPI using your preferred package manager:
3535

3636
```bash
37+
# Using pip
38+
pip install codegen
39+
40+
# Using pipx (for CLI usage)
41+
pipx install codegen
42+
43+
# Using uv
3744
uv pip install codegen
45+
# or
46+
uv tool install codegen
47+
```
48+
49+
### Keeping Up to Date
50+
51+
The CLI includes a built-in self-update system that checks for updates daily:
52+
53+
```bash
54+
# Update to latest version
55+
codegen update
56+
57+
# Check for updates
58+
codegen update --check
3859
```
3960

4061
## Get Started

docs/self-update.md

Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
# Self-Update System for Codegen CLI
2+
3+
The Codegen CLI includes a simplified self-update system that allows users to easily update to the latest version.
4+
5+
## Features
6+
7+
### 🚀 Smart Update Detection
8+
- Automatically detects installation method (pip, pipx, uv tool, homebrew, development)
9+
- Checks for updates periodically (once per day by default)
10+
- Shows update notifications when new versions are available
11+
- Fetches stable releases from PyPI
12+
13+
### 🔄 Update Management
14+
- Update to latest stable version
15+
- Update to specific versions
16+
- Dry-run mode to preview changes
17+
- Legacy mode for simple pip upgrades
18+
19+
### 🛡️ Safety Features
20+
- Pre-update validation checks
21+
- Major version update warnings
22+
- Post-update tips and guidance
23+
24+
### 📊 Version Information
25+
- List available versions
26+
- Check for updates without installing
27+
- View current and latest versions
28+
29+
## Usage
30+
31+
### Basic Commands
32+
33+
```bash
34+
# Update to latest stable version
35+
codegen update
36+
37+
# Check for available updates without installing
38+
codegen update --check
39+
40+
# List available versions
41+
codegen update --list
42+
43+
# Show version history
44+
codegen update --history
45+
```
46+
47+
### Advanced Options
48+
49+
```bash
50+
# Update to specific version
51+
codegen update --version 1.2.3
52+
53+
# Preview update without making changes
54+
codegen update --dry-run
55+
56+
# Force update check (bypass cache)
57+
codegen update --force
58+
59+
# Use legacy pip upgrade method
60+
codegen update --legacy
61+
```
62+
63+
## Release Information
64+
65+
The update system fetches stable releases from PyPI. Pre-release versions are automatically filtered out to ensure stability. Only production-ready versions are shown and available for installation through the update command.
66+
67+
## Installation Methods
68+
69+
The update system automatically detects how Codegen was installed and uses the appropriate update method:
70+
71+
### pip Installation
72+
```bash
73+
pip install codegen
74+
# Updates via: pip install --upgrade codegen
75+
```
76+
77+
### pipx Installation
78+
```bash
79+
pipx install codegen
80+
# Updates via: pipx upgrade codegen
81+
```
82+
83+
### UV Tool Installation
84+
```bash
85+
uv tool install codegen
86+
# Updates via: uv tool install --upgrade codegen
87+
```
88+
89+
### Homebrew Installation (macOS)
90+
```bash
91+
brew install codegen
92+
# Updates via: brew upgrade codegen
93+
```
94+
95+
### Development Installation
96+
For development/editable installs, the update system will notify you to update via git:
97+
```bash
98+
git pull origin main
99+
pip install -e .
100+
```
101+
102+
## Update Process
103+
104+
The update system performs a streamlined update process:
105+
106+
### How Updates Work
107+
108+
1. **Version Check**: Fetches available versions from PyPI
109+
2. **Comparison**: Compares current version with available versions
110+
3. **Confirmation**: Asks for user confirmation before proceeding
111+
4. **Installation**: Uses the appropriate package manager to update
112+
5. **Verification**: Displays success message and restart instructions
113+
114+
### Major Version Updates
115+
116+
When updating to a new major version:
117+
- The system warns about potential breaking changes
118+
- Post-update tips are displayed
119+
- Users are encouraged to check the changelog
120+
121+
## Update Notifications
122+
123+
The CLI checks for updates periodically and shows notifications when new versions are available:
124+
125+
```
126+
ℹ️ A new version of Codegen CLI is available: 1.2.3
127+
Run 'codegen update' to upgrade
128+
```
129+
130+
### Disable Update Checks
131+
132+
To disable automatic update checks, set the environment variable:
133+
134+
```bash
135+
export CODEGEN_DISABLE_UPDATE_CHECK=1
136+
```
137+
138+
## Downgrading
139+
140+
If an update causes issues, you can downgrade to a previous version:
141+
142+
```bash
143+
# Downgrade to a specific version
144+
codegen update --version 1.2.2
145+
146+
# Or use your package manager directly
147+
pip install codegen==1.2.2
148+
pipx install codegen==1.2.2 --force
149+
uv tool install codegen==1.2.2 --upgrade
150+
```
151+
152+
## Configuration
153+
154+
Update settings are stored in `~/.codegen/`:
155+
156+
- `update_check.json` - Last update check timestamp and cache
157+
158+
## Troubleshooting
159+
160+
### Update Fails
161+
162+
1. Try using the legacy update method:
163+
```bash
164+
codegen update --legacy
165+
```
166+
167+
2. Manually update via pip:
168+
```bash
169+
pip install --upgrade codegen
170+
```
171+
172+
3. Check installation method:
173+
```bash
174+
which codegen
175+
pip show codegen
176+
```
177+
178+
### Permission Errors
179+
180+
If you get permission errors, you may need to use sudo (not recommended) or update your user installation:
181+
182+
```bash
183+
# For user installation
184+
pip install --user --upgrade codegen
185+
186+
# For pipx
187+
pipx upgrade codegen
188+
```
189+
190+
### Downgrade Issues
191+
192+
If you need to downgrade:
193+
194+
1. Use the update command with a specific version:
195+
```bash
196+
codegen update --version 1.2.2
197+
```
198+
199+
2. Or manually install the desired version:
200+
```bash
201+
pip install codegen==1.2.2
202+
pipx install codegen==1.2.2 --force
203+
uv tool install codegen==1.2.2 --upgrade
204+
```
205+
206+
## Development
207+
208+
### Testing Updates
209+
210+
Test the update system in development:
211+
212+
```bash
213+
# Check current version
214+
codegen --version
215+
216+
# Test update check
217+
codegen update --check --force
218+
219+
# Test dry-run update
220+
codegen update --dry-run
221+
222+
# Test specific version
223+
codegen update --version 1.2.3 --dry-run
224+
```
225+
226+
### Adding New Features
227+
228+
To add new update features:
229+
230+
1. Modify `updater.py` for core functionality
231+
2. Update command options in `main.py`
232+
3. Add tests for new functionality
233+
234+
## API Reference
235+
236+
### UpdateManager Class
237+
238+
```python
239+
from codegen.cli.commands.update import UpdateManager
240+
241+
manager = UpdateManager()
242+
243+
# Check for updates
244+
result = manager.check_for_updates(force=True)
245+
246+
# Perform update
247+
success = manager.perform_update(target_version="1.2.3", dry_run=False)
248+
249+
# Check installation method
250+
print(manager.install_method)
251+
```
252+
253+
### Installation Methods
254+
255+
```python
256+
from codegen.cli.commands.update.updater import InstallMethod
257+
258+
methods = [
259+
InstallMethod.PIP,
260+
InstallMethod.PIPX,
261+
InstallMethod.UV_TOOL,
262+
InstallMethod.HOMEBREW,
263+
InstallMethod.DEVELOPMENT,
264+
InstallMethod.UNKNOWN
265+
]
266+
```
267+
268+
## Best Practices
269+
270+
1. **Regular Updates**: Keep your CLI updated for latest features and security fixes
271+
2. **Check Changelog**: Review breaking changes before major version updates
272+
3. **Test in Dev**: Test updates in development environment first
273+
4. **Use Dry Run**: Preview updates with `--dry-run` before applying
274+
5. **Report Issues**: Report update issues to help improve the system
275+
276+
## Security
277+
278+
- Updates are fetched over HTTPS from PyPI
279+
- Package signatures are verified by pip/pipx/uv
280+
- Pre-release versions are filtered out automatically
281+
- Major version updates require confirmation
282+
283+
## Future Enhancements
284+
285+
- [ ] Automatic rollback on update failure
286+
- [ ] Configuration migration system
287+
- [ ] Release notes integration
288+
- [ ] Beta and nightly release channels
289+
- [ ] Binary distribution for faster updates
290+
- [ ] Automatic security update installation
291+
- [ ] Update progress with detailed logging
292+
- [ ] Network proxy support
293+
- [ ] Offline update packages

0 commit comments

Comments
 (0)