|
| 1 | +## Summary |
| 2 | + |
| 3 | +Adds support for `repository_dispatch` events, enabling backend services to programmatically trigger Claude to perform tasks and receive progress updates via API. |
| 4 | + |
| 5 | +## Architecture |
| 6 | + |
| 7 | +```mermaid |
| 8 | +sequenceDiagram |
| 9 | + participant Backend as Backend Service |
| 10 | + participant GH as GitHub |
| 11 | + participant Action as Claude Action |
| 12 | + participant Claude as Claude |
| 13 | + participant MCP as Progress MCP Server |
| 14 | + participant API as Progress API |
| 15 | +
|
| 16 | + Backend->>GH: POST /repos/{owner}/{repo}/dispatches |
| 17 | + Note over Backend,GH: Payload includes:<br/>- description (task)<br/>- progress_endpoint<br/>- correlation_id |
| 18 | +
|
| 19 | + GH->>Action: Trigger workflow<br/>(repository_dispatch) |
| 20 | +
|
| 21 | + Action->>Action: Parse dispatch payload |
| 22 | + Note over Action: Extract task description,<br/>endpoint, correlation_id |
| 23 | +
|
| 24 | + Action->>MCP: Install Progress Server |
| 25 | + Note over MCP: Configure with:<br/>- PROGRESS_ENDPOINT<br/>- CORRELATION_ID<br/>- GITHUB_RUN_ID |
| 26 | +
|
| 27 | + Action->>Claude: Execute task with<br/>MCP tools available |
| 28 | +
|
| 29 | + loop Task Execution |
| 30 | + Claude->>MCP: update_claude_progress() |
| 31 | + MCP->>MCP: Get OIDC token |
| 32 | + MCP->>API: POST progress update |
| 33 | + Note over API: Payload includes:<br/>- correlation_id<br/>- status<br/>- message<br/>- completed_tasks |
| 34 | + API->>Backend: Forward update |
| 35 | + end |
| 36 | +
|
| 37 | + Claude->>Action: Task complete |
| 38 | + Action->>GH: Commit changes |
| 39 | +``` |
| 40 | + |
| 41 | +## Key Features |
| 42 | + |
| 43 | +### 1. Repository Dispatch Support |
| 44 | + |
| 45 | +- New event handler for `repository_dispatch` events |
| 46 | +- Extracts task description, progress endpoint, and correlation ID from `client_payload` |
| 47 | +- Bypasses GitHub UI interaction for fully programmatic operation |
| 48 | + |
| 49 | +### 2. Progress Reporting MCP Server |
| 50 | + |
| 51 | +- New MCP server (`progress-server.ts`) for sending progress updates |
| 52 | +- OIDC authentication for secure API communication |
| 53 | +- Includes correlation ID in all updates for request tracking |
| 54 | + |
| 55 | +### 3. Simplified Dispatch Prompts |
| 56 | + |
| 57 | +- Focused instructions for dispatch events (no PR/issue context) |
| 58 | +- Clear directives: answer questions or implement changes |
| 59 | +- Automatic progress updates at start and completion |
| 60 | + |
| 61 | +## Implementation Details |
| 62 | + |
| 63 | +### Triggering a Dispatch |
| 64 | + |
| 65 | +```bash |
| 66 | +curl -X POST \ |
| 67 | + https://api.github.com/repos/{owner}/{repo}/dispatches \ |
| 68 | + -H "Authorization: token $GITHUB_TOKEN" \ |
| 69 | + -H "Accept: application/vnd.github.v3+json" \ |
| 70 | + -d '{ |
| 71 | + "event_type": "claude-task", |
| 72 | + "client_payload": { |
| 73 | + "description": "Implement a new feature that...", |
| 74 | + "progress_endpoint": "https://api.example.com/progress", |
| 75 | + "correlation_id": "req-123-abc" |
| 76 | + } |
| 77 | + }' |
| 78 | +``` |
| 79 | + |
| 80 | +### Progress Update Payload |
| 81 | + |
| 82 | +```json |
| 83 | +{ |
| 84 | + "repository": "owner/repo", |
| 85 | + "run_id": "123456789", |
| 86 | + "correlation_id": "req-123-abc", |
| 87 | + "status": "in_progress", |
| 88 | + "message": "Implementing feature...", |
| 89 | + "completed_tasks": ["Setup environment", "Created base structure"], |
| 90 | + "current_task": "Writing tests", |
| 91 | + "timestamp": "2024-01-17T12:00:00Z" |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +## Security |
| 96 | + |
| 97 | +- **OIDC Authentication**: All progress updates use GitHub OIDC tokens |
| 98 | +- **Correlation IDs**: Included in request body (not URL) for security |
| 99 | +- **Endpoint Validation**: Progress endpoint must be explicitly provided |
| 100 | +- **No Credential Storage**: Tokens are generated per-request |
| 101 | + |
| 102 | +## Testing |
| 103 | + |
| 104 | +To test the repository_dispatch flow: |
| 105 | + |
| 106 | +1. Configure workflow with `repository_dispatch` trigger |
| 107 | +2. Send dispatch event with required payload |
| 108 | +3. Monitor GitHub Actions logs for execution |
| 109 | +4. Verify progress updates at configured endpoint |
| 110 | + |
| 111 | +## Changes |
| 112 | + |
| 113 | +- Added `repository_dispatch` event handling in `context.ts` |
| 114 | +- Created new `progress-server.ts` MCP server |
| 115 | +- Updated `isDispatch` flag across all event types |
| 116 | +- Modified prompt generation for dispatch events |
| 117 | +- Made `githubData` optional for dispatch workflows |
| 118 | +- Added correlation ID support throughout the pipeline |
0 commit comments