Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8802101
feat(cron-agent): add weekly cron agents (architecture audit, openapi…
enyst Aug 30, 2025
9d41526
refactor(cloud_api): use persistent requests.Session and narrower JSO…
enyst Aug 30, 2025
a91efbf
security(ci): avoid passing API key via CLI; use env + working-direct…
enyst Aug 30, 2025
04a2706
style: apply ruff/format fixes from pre-commit hooks\n\nCo-authored-b…
enyst Aug 30, 2025
e0eb847
security: disallow CLI API key entirely; env-only OPENHANDS_API_KEY\n…
enyst Aug 30, 2025
3ef9b4c
refactor(cloud_api): preserve injected Session; robust JSON handling;…
enyst Aug 30, 2025
ed53d00
docs(cron-agents): document env-only auth for CLI usage (OPENHANDS_AP…
enyst Aug 30, 2025
2235aaf
refactor(cron-agents): revert shared helper for readability; expand e…
enyst Aug 30, 2025
cdf7c47
Rename Cloud API -> OpenHands API in scripts
enyst Aug 30, 2025
71dc5c5
Format fixes from ruff hooks
enyst Aug 30, 2025
cddb065
PR tone: remove 'comprehensive' wording in scripts subset
enyst Aug 30, 2025
8a59d93
PR tone: remove remaining 'Comprehensive' instance in scripts/README.md
enyst Aug 30, 2025
7155f71
Cron agents: post human-friendly comments to a dedicated issue; stop …
enyst Aug 30, 2025
1888391
Cron agents: remove artifact upload steps; rely on issue comments for…
enyst Aug 30, 2025
b6474c0
Cron agents: grant issues:write permission to allow commenting
enyst Aug 30, 2025
5200c1e
Run pre-commit auto-fixes for workflows and scripts
enyst Aug 30, 2025
39a7d39
Cron agents: adjust comment intro wording to 'I am OpenHands, an AI e…
enyst Aug 30, 2025
34fe138
Update scripts/cron_agents.py
enyst Aug 30, 2025
bb7e531
cron_agents: normalize event['source'] case when extracting report me…
enyst Aug 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/weekly-architecture-audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Weekly Architecture Audit

on:
schedule:
- cron: "0 6 * * 6" # Every Saturday at 06:00 UTC
workflow_dispatch:
inputs:
reason:
description: 'Reason for manual trigger'
required: false
default: ''

permissions:
contents: read
issues: write

jobs:
architecture-audit:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests jinja2

- name: Run architecture audit
env:
CRON_AGENTS_ISSUE_NUMBER: "97"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
OPENHANDS_API_KEY: ${{ secrets.OPENHANDS_API_KEY }}
working-directory: scripts
run: |
python cron_agents.py architecture-audit \
--repository "${{ github.repository }}" \
--branch "main"
45 changes: 45 additions & 0 deletions .github/workflows/weekly-openapi-drift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Weekly OpenAPI Drift Check

on:
schedule:
- cron: "0 6 * * 6" # Every Saturday at 06:00 UTC
workflow_dispatch:
inputs:
reason:
description: 'Reason for manual trigger'
required: false
default: ''

permissions:
contents: read
issues: write

jobs:
openapi-drift:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests jinja2

- name: Run OpenAPI drift check
env:
CRON_AGENTS_ISSUE_NUMBER: "97"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
OPENHANDS_API_KEY: ${{ secrets.OPENHANDS_API_KEY }}
working-directory: scripts
run: |
python cron_agents.py openapi-drift \
--repository "${{ github.repository }}" \
--branch "main"
103 changes: 103 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# OpenHands Cron Agents

This directory contains the implementation of automated weekly tasks using the OpenHands API.

## Structure

```
scripts/
├── openhands_api.py # Clean OpenHands API client
├── cron_agents.py # Main task functions with CLI
├── prompts/ # Jinja2 prompt templates
│ ├── architecture_audit.j2
│ └── openapi_drift.j2
└── README.md # This file
```

## Components

### `openhands_api.py`
Clean, reusable OpenHands API client with:
- Structured error handling with `OpenHandsAPIError`
- Authentication testing
- Conversation management
- Event polling with progress callbacks
- Timeout handling and error recovery

### `cron_agents.py`
Main module containing two weekly task functions:

1. **`run_architecture_audit()`** - Reviews architecture documentation
2. **`run_openapi_drift_check()`** - Detects OpenAPI schema drift

Both functions return structured results with success/error information.

### `prompts/`
Jinja2 templates for task prompts:
- `architecture_audit.j2` - Architecture documentation review prompt
- `openapi_drift.j2` - OpenAPI drift detection prompt with structured reporting

## Usage

### CLI Interface

```bash
# Architecture audit (reads OPENHANDS_API_KEY from environment)
python cron_agents.py architecture-audit \
--repository "owner/repo" \
--branch "main" \
--output results.json

# OpenAPI drift check (reads OPENHANDS_API_KEY from environment)
python cron_agents.py openapi-drift \
--repository "owner/repo" \
--branch "main" \
--output results.json
```

### Programmatic Usage

```python
from cron_agents import run_architecture_audit, run_openapi_drift_check

# Run architecture audit
result = run_architecture_audit(
api_key="your-api-key",
repository="owner/repo",
branch="main"
)

if result["success"]:
print(f"Audit completed: {result['conversation_url']}")
else:
print(f"Audit failed: {result['error']}")
```

## GitHub Workflows

Two minimal workflows are provided:
- `.github/workflows/weekly-architecture-audit.yml`
- `.github/workflows/weekly-openapi-drift.yml`

Both run weekly and only require the `OPENHANDS_API_KEY` secret.

## Error Handling

The implementation provides structured error reporting:
- HTTP status codes and response details for API errors
- Structured error messages with context
- Progress logging during polling
- Timeout handling with graceful degradation

## Security Model

- Only requires `OPENHANDS_API_KEY` in CI/workflows
- LLM provider settings managed in your OpenHands account
- No sensitive data logged or exposed
- Clean separation between authentication and task logic

## Dependencies

- `requests` - HTTP client for API calls
- `jinja2` - Template rendering for prompts
- Standard library modules: `json`, `logging`, `pathlib`, `re`, `time`
Loading
Loading