Skip to content

Add example for automated TODO management with GitHub Actions - #758

Merged
simonrosenberg merged 90 commits into
mainfrom
openhands/todo-management-example
Oct 17, 2025
Merged

simonrosenberg merged 90 commits into
mainfrom
openhands/todo-management-example

Conversation

@simonrosenberg

@simonrosenberg simonrosenberg commented Oct 16, 2025 •

Copy link
Copy Markdown
Member

Summary

This PR adds a comprehensive example in examples/github_workflows/03_todo_management that demonstrates how to use the OpenHands SDK to automatically scan a codebase for configurable TODO comments and create pull requests to implement them.

🚀 Latest Update: Configurable TODO Identifiers & Rust Support

The example now supports:

  • ✅ Configurable TODO Identifiers: Use custom identifiers like TODO(myteam), TODO[urgent], etc.
  • ✅ Rust Language Support: Added .rs file extension support
  • ✅ Enhanced CLI: Command-line interface with --identifier parameter
  • ✅ Workflow Integration: GitHub Actions workflow accepts todo_identifier input
  • ✅ Comprehensive Documentation: Updated README with new features and usage examples

Key Features

  • 🔍 Smart Scanning: Finds legitimate TODO comments with configurable identifiers while filtering out false positives
  • 🤖 AI Implementation: Uses OpenHands agent to automatically implement TODOs
  • 🔄 PR Management: Creates feature branches and pull requests automatically
  • 📝 Progress Tracking: Tracks TODO processing status and PR creation
  • 📊 Comprehensive Reporting: Detailed GitHub Actions summary with processing status
  • ⚙️ Configurable: Customizable TODO identifiers and processing limits
  • 🔒 Remote Execution: Uses secure remote runtime with proper GitHub permissions

Language Support

  • Python (.py)
  • TypeScript (.ts)
  • Java (.java)
  • Rust (.rs) - NEW

Configuration Examples

Default Usage

# TODO(openhands): Add input validation for user email
def process_user_email(email):
    return email.lower()

Custom Identifiers

# TODO(myteam): Implement caching mechanism
# TODO[urgent]: Fix security vulnerability
# TODO(backend): Add database indexing

Rust Support

// TODO(openhands): Add error handling
fn process_data(input: &str) -> String {
    input.to_uppercase()
}

Usage

GitHub Actions Workflow

  1. Go to Actions → "Automated TODO Management"
  2. Click "Run workflow"
  3. Configure parameters:
    • Max TODOs: Maximum number to process (default: 3)
    • TODO Identifier: Custom identifier (default: TODO(openhands))

CLI Usage

# Scan with default identifier
python scanner.py .

# Scan with custom identifier
python scanner.py . --identifier "TODO(myteam)"

# Scan specific directory and save to file
python scanner.py /path/to/code --output todos.json

# Get help
python scanner.py --help

Implementation Details

Remote Runtime Benefits

  • Solves Permission Issues: Remote runtime has access to GitHub tokens with proper permissions
  • Secure Execution: Sandboxed environment prevents local system interference
  • Consistent Results: Same execution environment regardless of GitHub Actions runner
  • Better Resource Management: Dedicated resources for agent execution

Components

  1. Scanner (scanner.py): Intelligent TODO detection with configurable identifiers
  2. Agent (agent.py): OpenHands agent integration with remote runtime
  3. Workflow (.github/workflows/todo-management.yml): GitHub Actions automation
  4. Documentation (README.md): Comprehensive setup and usage guide

Setup Requirements

Repository Secrets

  • LLM_API_KEY: API key for the LLM (required)
  • RUNTIME_API_KEY: API key for runtime API access (required)
  • GITHUB_TOKEN: GitHub token with repo permissions (automatically provided)

Permissions

permissions:
  contents: write
  pull-requests: write
  issues: write

Technical Implementation

Configurable Identifier Support

# Regex escaping for special characters
escaped_identifier = re.escape(todo_identifier)
todo_pattern = re.compile(rf"{escaped_identifier}(?::\s*(.*))?", re.IGNORECASE)

Multi-Language Support

# Supported file extensions
if file_path.suffix.lower() not in {".py", ".ts", ".java", ".rs"}:
    return []

Remote Runtime Configuration

with APIRemoteWorkspace(
    runtime_api_url="https://runtime.eval.all-hands.dev",
    runtime_api_key=runtime_api_key,
    server_image="ghcr.io/all-hands-ai/agent-server:latest-python",
) as workspace:
    conversation = Conversation(agent=agent, workspace=workspace)

Testing

Comprehensive test coverage including:

  • ✅ Rust file support
  • ✅ Custom identifier functionality
  • ✅ Edge cases and error handling
  • ✅ Multi-language comment detection
  • ✅ False positive filtering

Files Structure

examples/github_workflows/03_todo_management/
├── README.md (130+ lines) - Comprehensive documentation
├── scanner.py (252 lines) - Smart TODO scanner with configurable identifiers
├── agent.py (318 lines) - Remote runtime agent
└── prompt.py (27 lines) - Agent prompt template

.github/workflows/
└── todo-management.yml (330+ lines) - GitHub Actions workflow

tests/github_workflows/
└── test_todo_scanner.py - Comprehensive test suite

Changelog

v3.0 - Configurable Identifiers & Rust Support

  • ✅ Added configurable TODO identifier support
  • ✅ Added Rust (.rs) file extension support
  • ✅ Enhanced CLI with --identifier parameter
  • ✅ Updated workflow to accept todo_identifier input
  • ✅ Comprehensive documentation updates
  • ✅ Added test coverage for new features
  • ✅ Fixed pre-commit compliance issues

v2.0 - Remote Runtime Integration

  • ✅ Implemented APIRemoteWorkspace for secure execution
  • ✅ Added RUNTIME_API_KEY environment variable
  • ✅ Updated LLM configuration for remote proxy
  • ✅ Enhanced error handling for remote operations

v1.0 - Initial Implementation

  • ✅ Smart TODO scanning with false positive filtering
  • ✅ OpenHands agent integration
  • ✅ GitHub Actions workflow automation
  • ✅ Comprehensive documentation and testing

Fixes #757

Benefits

  1. Flexible TODO Management: Support for team-specific or priority-based identifiers
  2. Multi-Language Support: Works across Python, TypeScript, Java, and Rust codebases
  3. Automated Code Improvement: Continuously implements pending TODOs
  4. Reduced Technical Debt: Prevents TODO accumulation
  5. Team Productivity: Frees developers from routine implementation tasks
  6. Code Quality: Ensures TODOs are addressed systematically
  7. Secure Execution: Remote runtime provides proper isolation and permissions

Co-authored-by: openhands openhands@all-hands.dev


Agent Server images for this PR

• GHCR package: https://github.com/All-Hands-AI/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Base Image Docs / Tags
golang golang:1.21-bookworm Link
java eclipse-temurin:17-jdk Link
python nikolaik/python-nodejs:python3.12-nodejs22 Link

Pull (multi-arch manifest)

docker pull ghcr.io/all-hands-ai/agent-server:c939ade-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-c939ade-python \
  ghcr.io/all-hands-ai/agent-server:c939ade-python

All tags pushed for this build

ghcr.io/all-hands-ai/agent-server:c939ade-golang
ghcr.io/all-hands-ai/agent-server:v1.0.0a2_golang_tag_1.21-bookworm_binary
ghcr.io/all-hands-ai/agent-server:c939ade-java
ghcr.io/all-hands-ai/agent-server:v1.0.0a2_eclipse-temurin_tag_17-jdk_binary
ghcr.io/all-hands-ai/agent-server:c939ade-python
ghcr.io/all-hands-ai/agent-server:v1.0.0a2_nikolaik_s_python-nodejs_tag_python3.12-nodejs22_binary

The c939ade tag is a multi-arch manifest (amd64/arm64); your client pulls the right arch automatically.

This PR implements issue #757 by creating a comprehensive example that demonstrates
how to use the OpenHands SDK to automatically scan a codebase for # TODO(openhands)
comments and create pull requests to implement them.

Features:
- todo_scanner.py: Scans codebase for TODO(openhands) comments with filtering
- todo_agent.py: Uses OpenHands to implement individual TODOs in feature branches
- workflow.yml: GitHub Actions workflow for automation
- Comprehensive README with setup and usage instructions
- Complete test suite with 10 test cases

The implementation follows the same patterns as examples/github_workflows/01_basic_action
and provides practical automation for self-improving codebase capabilities.

Co-authored-by: openhands <openhands@all-hands.dev>
Changes TODO(openhands: {pr_url}) to TODO(in progress: {pr_url}) for better clarity
that the TODO is being actively worked on.

Co-authored-by: openhands <openhands@all-hands.dev>
@simonrosenberg simonrosenberg self-assigned this Oct 16, 2025
openhands-agent and others added 14 commits October 16, 2025 08:45
- Add prompt.py file with single PROMPT constant
- Remove helper methods from todo_agent.py (create_feature_branch, generate_todo_prompt, create_pull_request)
- Simplify TODO scanner to only scan .py, .ts, and .java files
- Update update_todo_with_pr_url to verify agent created branch/PR and handle git history smartly
- Update tests to reflect simplified scanner behavior
- Update README to document new structure

Co-authored-by: openhands <openhands@all-hands.dev>
- Reduce todo_scanner.py from ~280 lines to ~80 lines
- Remove unnecessary complexity: binary file detection, markdown filtering, context extraction
- Keep only essential functionality: scan .py/.ts/.java files for TODO(openhands) comments
- Simplify tests to match streamlined implementation
- Update README to reflect simplified structure

Co-authored-by: openhands <openhands@all-hands.dev>
- Replace get_recent_branches() heuristic with get_pr_info() using GitHub API
- Automatically extract head and base branch names from PR URL
- Remove guesswork about which branch the agent created
- Simplify update_todo_with_pr_url() function signature
- Use GITHUB_TOKEN environment variable for API authentication
- More reliable branch detection and TODO comment updates

Co-authored-by: openhands <openhands@all-hands.dev>
- After agent.run(), detect feature branch by checking current branch
- Use find_pr_for_branch() to find PR for the detected branch via GitHub API
- Remove complex PR URL parsing from agent responses
- Cleaner logic: initial_branch -> agent.run() -> current_branch -> find PR
- More reliable than parsing agent text responses for PR URLs
- Reduced from 304 to 297 lines with cleaner flow

Co-authored-by: openhands <openhands@all-hands.dev>
- Created debug_workflow.py to trigger and monitor the workflow
- Provides blocking execution with detailed logs and error reporting
- Shows URLs of created PRs or error details
- Updated README with debug script documentation

Co-authored-by: openhands <openhands@all-hands.dev>
- Enhanced scanner.py with detailed logging and false positive filtering
- Added logging to agent.py for better debugging
- Updated debug_workflow.py with more verbose output
- Added GitHub Actions workflow file to .github/workflows/
- Fixed scanner to exclude test files and documentation references
- Scanner now correctly identifies only legitimate TODOs

Co-authored-by: openhands <openhands@all-hands.dev>
- Added comprehensive README with setup, usage, and troubleshooting guides
- Created test_local.py for local component testing
- Documented smart filtering capabilities and debug tools
- Added troubleshooting section with common issues and solutions
- Included development workflow and contribution guidelines
- Documented all features: smart scanning, AI implementation, PR management
- Added examples of workflow execution and TODO format requirements

The example is now complete and ready for production use.

Co-authored-by: openhands <openhands@all-hands.dev>
- Fix line length violations by breaking long lines
- Fix import sorting issues
- Remove unnecessary f-string prefixes
- Fix type annotation issue in test_local.py
- All linting and type checking now passes

Co-authored-by: openhands <openhands@all-hands.dev>
- Add comprehensive workflow simulation and testing
- Create implementation summary documenting all features
- Add test files for validation and debugging
- All components tested and validated
- Ready for production deployment

Key features:
- Smart TODO scanning with false positive filtering
- OpenHands agent integration for TODO implementation
- Automatic PR creation and TODO progress tracking
- Comprehensive testing and debugging tools
- Complete documentation and setup guides

Fixes #757

Co-authored-by: openhands <openhands@all-hands.dev>
- Add comprehensive filtering for processed TODOs with PR URLs, progress markers, and GitHub URLs
- Improve false positive detection for print statements, docstrings, and quoted strings
- Implement robust docstring state tracking to filter TODOs inside multi-line docstrings
- Add comprehensive test suite (test_scanner_filtering.py) to validate filtering capabilities
- Update README with detailed filtering documentation
- Ensure scanner only processes unhandled TODOs to avoid duplicate PRs

Co-authored-by: openhands <openhands@all-hands.dev>
- Add pull_request trigger with 'labeled' type
- Only run when 'automatic-todo' label is added to PR
- Maintains existing workflow_dispatch functionality

Co-authored-by: openhands <openhands@all-hands.dev>
- Use litellm_proxy/claude-sonnet-4-5-20250929 model
- Use https://llm-proxy.eval.all-hands.dev as base URL
- Pass LLM configuration to agent execution environment

Co-authored-by: openhands <openhands@all-hands.dev>
- Add rich>=13.0.0 to SDK dependencies (used extensively in codebase)
- Add pydantic and rich to tools build requirements
- Resolves ModuleNotFoundError during package builds

Co-authored-by: openhands <openhands@all-hands.dev>
- Include all SDK dependencies in tools build requirements
- Addresses import issues during package build process
- Note: Circular import issue with glob module still exists

Co-authored-by: openhands <openhands@all-hands.dev>
- Add logic to capture continuation comment lines after TODO(openhands)
- Combine multi-line TODO descriptions into single coherent text
- Stop at comments that appear to be separate (capital letter heuristic)
- Handle empty comment lines gracefully
- Preserve full context for better agent understanding

Example:
# TODO(openhands): we should add test to test this init_state will actually
# modify state in-place

Now captures: 'we should add test to test this init_state will actually modify state in-place'

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions

github-actions Bot commented Oct 16, 2025 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
TOTAL10191572143% 
report-only-changed-files is enabled. No files were changed during this commit :)

Enhanced Features:
- Agent now outputs structured result files with TODO processing status
- Workflow collects all result artifacts and creates detailed summary
- Summary includes list of TODOs with their associated PR URLs
- Shows processing status (success/failed/partial) for each TODO
- Provides clickable PR links in GitHub Actions summary
- Handles error cases and partial completions gracefully

Summary Format:
## TODOs and Pull Requests
1. **file.py** line 123: Description of TODO...
   - 🔗 PR: [https://github.com/repo/pull/456](https://github.com/repo/pull/456)
   - ✅ Status: success

This provides clear visibility into which TODOs were processed and their outcomes.

Co-authored-by: openhands <openhands@all-hands.dev>
- Remove document separators (---) from workflow files
- Fix indentation to use consistent 2-space formatting
- Align YAML structure properly for better readability

Co-authored-by: openhands <openhands@all-hands.dev>
- Remove leading slash from example path filter to match actual paths
- Prevents scanner from processing mock TODOs in example files
- Fixes workflow failures caused by empty TODO descriptions

Co-authored-by: openhands <openhands@all-hands.dev>
simonrosenberg and others added 6 commits October 17, 2025 18:56
- Remove unnecessary git command functions (run_git_command, get_current_branch, find_pr_for_branch)
- Remove post-analysis logic after conversation run
- Trust the agent to create feature branch and pull request automatically
- Simplify result structure by removing pr_url and branch fields
- Reduce code complexity and improve maintainability

Co-authored-by: openhands <openhands@all-hands.dev>
- Update openhands-sdk subdirectory path from openhands/sdk to openhands-sdk
- Update openhands-tools subdirectory path from openhands/tools to openhands-tools
- Move TODO management files from examples/github_workflows to examples/03_github_workflows
- Update all URLs to reference correct directory structure
- Update agent script filename from agent.py to agent_script.py
- Add type ignore comments for imports that will be available in workflow environment

The agent script is already simplified as requested:
- Trusts the agent to handle branch creation and PR management
- Removed post-analysis after conversation run
- No need for find_pr_for_branch, get_current_branch, or run_git_command functions

Co-authored-by: openhands <openhands@all-hands.dev>
- Update exclusion pattern from 'examples/github_workflows/03_todo_management/'
  to 'examples/03_github_workflows/03_todo_management/' to match new directory structure
- Scanner now correctly finds TODO comments in the reorganized codebase

Co-authored-by: openhands <openhands@all-hands.dev>
@openhands-ai

openhands-ai Bot commented Oct 17, 2025

Copy link
Copy Markdown

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • Automated TODO Management

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #758 at branch `openhands/todo-management-example`

Feel free to include any additional details that might help me get this PR into a better state.

You can manage your notification settings

@neubig neubig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good! We can always polish it later.

simonrosenberg and others added 14 commits October 17, 2025 23:41
…nds-AI/agent-sdk into openhands/todo-management-example
…path

- Update scanner.py path from examples/github_workflows/ to examples/03_github_workflows/
- Update agent_script.py and prompt.py paths to match correct directory structure
- Fixes 'No such file or directory' errors in GitHub Actions workflow

Co-authored-by: openhands <openhands@all-hands.dev>
- Change openhands/sdk to openhands-sdk (hyphenated)
- Change openhands/tools to openhands-tools (hyphenated)
- Fixes 'has no subdirectory' error in GitHub Actions workflow
- Matches actual directory structure in main branch

Co-authored-by: openhands <openhands@all-hands.dev>
- Change from main branch to openhands/todo-management-example branch
- Fixes 'No such file or directory' error when copying agent files
- TODO management example files only exist on the feature branch
- Ensures workflow can access all required files (scanner.py, agent_script.py, prompt.py)

Co-authored-by: openhands <openhands@all-hands.dev>
…nds-AI/agent-sdk into openhands/todo-management-example
- Remove complex result structure and JSON file output
- Align with basic action script pattern for consistency
- Simplify error handling with direct sys.exit()
- Update workflow to remove result file checking
- Maintain all core functionality without breaking changes

Co-authored-by: openhands <openhands@all-hands.dev>
…nds-AI/agent-sdk into openhands/todo-management-example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add example for automated TODO management with GitHub Actions

3 participants