jleechanorg-pr-automation 0.2.41__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. jleechanorg_pr_automation-0.2.41/PKG-INFO +864 -0
  2. jleechanorg_pr_automation-0.2.41/README.md +829 -0
  3. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/STORAGE_STATE_TESTING_PROTOCOL.md +326 -0
  4. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/__init__.py +87 -0
  5. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/automation_safety_manager.py +1041 -0
  6. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/automation_safety_wrapper.py +110 -0
  7. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/automation_utils.py +336 -0
  8. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/check_codex_comment.py +82 -0
  9. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/codex_branch_updater.py +284 -0
  10. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/codex_config.py +190 -0
  11. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/jleechanorg_pr_monitor.py +2933 -0
  12. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/logging_utils.py +86 -0
  13. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/openai_automation/__init__.py +3 -0
  14. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/openai_automation/codex_github_mentions.py +966 -0
  15. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/openai_automation/debug_page_content.py +88 -0
  16. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/openai_automation/oracle_cli.py +364 -0
  17. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/openai_automation/test_codex_comprehensive.py +355 -0
  18. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/openai_automation/test_codex_integration.py +254 -0
  19. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/orchestrated_pr_runner.py +497 -0
  20. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/__init__.py +0 -0
  21. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/conftest.py +12 -0
  22. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_actionable_counting_matrix.py +219 -0
  23. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_attempt_limit_logic.py +124 -0
  24. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_automation_marker_functions.py +175 -0
  25. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_automation_over_running_reproduction.py +155 -0
  26. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_automation_safety_limits.py +474 -0
  27. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_automation_safety_manager_comprehensive.py +659 -0
  28. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_codex_actor_matching.py +137 -0
  29. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_fixpr_prompt.py +54 -0
  30. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_fixpr_return_value.py +140 -0
  31. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_graphql_error_handling.py +155 -0
  32. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_model_parameter.py +324 -0
  33. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_orchestrated_pr_runner.py +697 -0
  34. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_packaging_integration.py +127 -0
  35. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_pr_filtering_matrix.py +526 -0
  36. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_pr_monitor_eligibility.py +354 -0
  37. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_pr_targeting.py +213 -0
  38. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_version_consistency.py +51 -0
  39. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_workflow_specific_limits.py +202 -0
  40. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/tests/test_workspace_dispatch_missing_dir.py +119 -0
  41. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation/utils.py +257 -0
  42. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation.egg-info/PKG-INFO +864 -0
  43. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation.egg-info/SOURCES.txt +47 -0
  44. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation.egg-info/dependency_links.txt +1 -0
  45. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation.egg-info/entry_points.txt +3 -0
  46. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation.egg-info/requires.txt +15 -0
  47. jleechanorg_pr_automation-0.2.41/jleechanorg_pr_automation.egg-info/top_level.txt +1 -0
  48. jleechanorg_pr_automation-0.2.41/pyproject.toml +174 -0
  49. jleechanorg_pr_automation-0.2.41/setup.cfg +4 -0
@@ -0,0 +1,864 @@
1
+ Metadata-Version: 2.4
2
+ Name: jleechanorg-pr-automation
3
+ Version: 0.2.41
4
+ Summary: GitHub PR automation system with safety limits and actionable counting
5
+ Author-email: jleechan <jlee@jleechan.org>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/jleechanorg/worldarchitect.ai
8
+ Project-URL: Repository, https://github.com/jleechanorg/worldarchitect.ai
9
+ Project-URL: Issues, https://github.com/jleechanorg/worldarchitect.ai/issues
10
+ Keywords: github,automation,pr,pull-request,monitoring
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Classifier: Topic :: Software Development :: Version Control :: Git
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ Requires-Dist: requests>=2.25.0
23
+ Requires-Dist: jleechanorg-orchestration>=0.1.18
24
+ Requires-Dist: playwright>=1.40.0
25
+ Requires-Dist: playwright-stealth>=1.0.0
26
+ Requires-Dist: aiohttp>=3.8.0
27
+ Provides-Extra: email
28
+ Requires-Dist: keyring>=23.0.0; extra == "email"
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
31
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
32
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
33
+ Requires-Dist: black>=22.0.0; extra == "dev"
34
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
35
+
36
+ # GitHub PR Automation System
37
+
38
+ **Autonomous PR fixing and code review automation for the jleechanorg organization**
39
+
40
+ ## Overview
41
+
42
+ This automation system provides three core workflows:
43
+
44
+ 1. **@codex Comment Agent** - Monitors PRs and posts intelligent automation comments
45
+ 2. **FixPR Workflow** - Autonomously fixes merge conflicts and failing CI checks
46
+ 3. **Codex GitHub Mentions** - Processes OpenAI Codex tasks via browser automation
47
+
48
+ All workflows use safety limits, commit tracking, and orchestrated AI agents to process PRs reliably.
49
+
50
+ ---
51
+
52
+ ## 🤖 Workflow 1: @codex Comment Agent
53
+
54
+ ### What It Does
55
+
56
+ The @codex comment agent continuously monitors all open PRs across the jleechanorg organization and posts standardized Codex instruction comments when new commits are pushed. This enables AI assistants (@codex, @coderabbitai, @copilot, @cursor) to review and improve PRs automatically.
57
+
58
+ ### How It Works
59
+
60
+ ```
61
+ ┌─────────────────────────────────────────────────────────────┐
62
+ │ 1. DISCOVERY PHASE │
63
+ │ ───────────────────────────────────────────────────────────│
64
+ │ • Scan all repositories in jleechanorg organization │
65
+ │ • Find open PRs updated in last 24 hours │
66
+ │ • Filter to actionable PRs (new commits, not drafts) │
67
+ └─────────────────────────────────────────────────────────────┘
68
+
69
+ ┌─────────────────────────────────────────────────────────────┐
70
+ │ 2. COMMIT TRACKING │
71
+ │ ───────────────────────────────────────────────────────────│
72
+ │ • Check if PR has new commits since last processed │
73
+ │ • Skip if already commented on this commit SHA │
74
+ │ • Prevent duplicate comments on same commit │
75
+ └─────────────────────────────────────────────────────────────┘
76
+
77
+ ┌─────────────────────────────────────────────────────────────┐
78
+ │ 3. SAFETY CHECKS │
79
+ │ ───────────────────────────────────────────────────────────│
80
+ │ • Verify PR hasn't exceeded attempt limits (max 10) │
81
+ │ • Check global automation limit (max 50 runs) │
82
+ │ • Skip if safety limits reached │
83
+ └─────────────────────────────────────────────────────────────┘
84
+
85
+ ┌─────────────────────────────────────────────────────────────┐
86
+ │ 4. POST COMMENT │
87
+ │ ───────────────────────────────────────────────────────────│
88
+ │ • Post standardized @codex instruction comment │
89
+ │ • Include hidden commit marker: <!-- codex-automation- │
90
+ │ commit:abc123def --> │
91
+ │ • Record processing in commit history │
92
+ └─────────────────────────────────────────────────────────────┘
93
+ ```
94
+
95
+ ### Comment Template
96
+
97
+ The agent posts this standardized instruction:
98
+
99
+ ```markdown
100
+ @codex @coderabbitai @copilot @cursor [AI automation] Codex will implement
101
+ the code updates while coderabbitai, copilot, and cursor focus on review
102
+ support. Please make the following changes to this PR.
103
+
104
+ Use your judgment to fix comments from everyone or explain why it should
105
+ not be fixed. Follow binary response protocol - every comment needs "DONE"
106
+ or "NOT DONE" classification explicitly with an explanation. Address all
107
+ comments on this PR. Fix any failing tests and resolve merge conflicts.
108
+ Push any commits needed to remote so the PR is updated.
109
+
110
+ <!-- codex-automation-commit:abc123def456 -->
111
+ ```
112
+
113
+ ### Tech Stack
114
+
115
+ | Component | Technology | Purpose |
116
+ |-----------|-----------|---------|
117
+ | **PR Discovery** | GitHub GraphQL API | Organization-wide PR search |
118
+ | **Commit Detection** | `check_codex_comment.py` | Prevents duplicate comments |
119
+ | **Comment Posting** | GitHub REST API (`gh pr comment`) | Posts automation instructions |
120
+ | **Safety Manager** | `AutomationSafetyManager` | File-based rate limiting |
121
+ | **Scheduling** | launchd/cron | Runs every 10 minutes |
122
+
123
+ ### Usage
124
+
125
+ #### CLI Commands
126
+
127
+ ```bash
128
+ # Monitor all repositories (posts comments to actionable PRs)
129
+ jleechanorg-pr-monitor
130
+
131
+ # Monitor specific repository
132
+ jleechanorg-pr-monitor --single-repo worldarchitect.ai
133
+
134
+ # Process specific PR
135
+ jleechanorg-pr-monitor --target-pr 123 --target-repo jleechanorg/worldarchitect.ai
136
+
137
+ # Dry run (discovery only, no comments)
138
+ jleechanorg-pr-monitor --dry-run
139
+
140
+ # Check safety status
141
+ automation-safety-cli status
142
+
143
+ # Clear safety data (resets limits)
144
+ automation-safety-cli clear
145
+ ```
146
+
147
+ #### Slash Command Integration
148
+
149
+ ```bash
150
+ # From Claude Code
151
+ /automation status # View automation state
152
+ /automation monitor # Process actionable PRs
153
+ /automation safety check # View safety limits
154
+ ```
155
+
156
+ ### Configuration
157
+
158
+ ```bash
159
+ # Required
160
+ export GITHUB_TOKEN="your_github_token_here"
161
+
162
+ # Safety limits (defaults shown). Override via CLI flags (not environment variables):
163
+ # - jleechanorg-pr-monitor --pr-limit 10 --global-limit 50 --approval-hours 24
164
+ # - jleechanorg-pr-monitor --pr-automation-limit 10 --fix-comment-limit 10 --fixpr-limit 10
165
+ # Or persist via `automation-safety-cli` which writes `automation_safety_config.json` in the safety data dir.
166
+
167
+ # Optional - Email Notifications
168
+ export SMTP_SERVER="smtp.gmail.com"
169
+ export SMTP_PORT=587
170
+ export EMAIL_USER="your-email@gmail.com"
171
+ export EMAIL_PASS="your-app-password"
172
+ export EMAIL_TO="recipient@example.com"
173
+ ```
174
+
175
+ ### Key Features
176
+
177
+ - ✅ **Commit-based tracking** - Only comments when new commits appear
178
+ - ✅ **Hidden markers** - Uses HTML comments to track processed commits
179
+ - ✅ **Safety limits** - Prevents automation abuse with dual limits
180
+ - ✅ **Cross-repo support** - Monitors entire organization
181
+ - ✅ **Draft PR filtering** - Skips draft PRs automatically
182
+
183
+ ---
184
+
185
+ ## 🔧 Workflow 2: FixPR (Autonomous PR Fixing)
186
+
187
+ ### What It Does
188
+
189
+ The FixPR workflow autonomously fixes PRs that have merge conflicts or failing CI checks by spawning AI agents in isolated workspaces. Each agent analyzes the PR, reproduces failures locally, applies fixes, and pushes updates.
190
+
191
+ ### How It Works
192
+
193
+ ```
194
+ ┌─────────────────────────────────────────────────────────────┐
195
+ │ 1. PR DISCOVERY & FILTERING │
196
+ │ ───────────────────────────────────────────────────────────│
197
+ │ • Query PRs updated in last 24 hours │
198
+ │ • Filter to PRs with: │
199
+ │ - mergeable: CONFLICTING │
200
+ │ - failing CI checks (FAILURE, ERROR, TIMED_OUT) │
201
+ │ • Skip PRs without blockers │
202
+ └─────────────────────────────────────────────────────────────┘
203
+
204
+ ┌─────────────────────────────────────────────────────────────┐
205
+ │ 2. WORKSPACE ISOLATION │
206
+ │ ───────────────────────────────────────────────────────────│
207
+ │ • Clone base repository to /tmp/pr-orch-bases/ │
208
+ │ • Create worktree at /tmp/{repo}/pr-{number}-{branch} │
209
+ │ • Checkout PR branch in isolated workspace │
210
+ │ • Clean previous tmux sessions with matching names │
211
+ └─────────────────────────────────────────────────────────────┘
212
+
213
+ ┌─────────────────────────────────────────────────────────────┐
214
+ │ 3. AI AGENT DISPATCH │
215
+ │ ───────────────────────────────────────────────────────────│
216
+ │ • Create TaskDispatcher with workspace config │
217
+ │ • Spawn agent with: │
218
+ │ - CLI: claude/codex/gemini (configurable) │
219
+ │ - Task: Fix PR #{number} - resolve conflicts & tests │
220
+ │ - Workspace: Isolated worktree path │
221
+ │ • Agent runs autonomously in tmux session │
222
+ └─────────────────────────────────────────────────────────────┘
223
+
224
+ ┌─────────────────────────────────────────────────────────────┐
225
+ │ 4. AGENT WORKFLOW (Autonomous) │
226
+ │ ───────────────────────────────────────────────────────────│
227
+ │ • Checkout PR: gh pr checkout {pr_number} │
228
+ │ • Analyze failures: gh pr view --json statusCheckRollup │
229
+ │ • Reproduce locally: Run failing tests │
230
+ │ • Apply fixes: Code changes to resolve issues │
231
+ │ • Verify: Run full test suite │
232
+ │ • Commit & Push: git push origin {branch} │
233
+ │ • Write report: /tmp/orchestration_results/pr-{num}.json │
234
+ └─────────────────────────────────────────────────────────────┘
235
+
236
+ ┌─────────────────────────────────────────────────────────────┐
237
+ │ 5. VERIFICATION │
238
+ │ ───────────────────────────────────────────────────────────│
239
+ │ • Agent monitors GitHub CI for updated status │
240
+ │ • Verifies mergeable: MERGEABLE │
241
+ │ • Confirms all checks passing │
242
+ │ • Logs success/failure to results file │
243
+ └─────────────────────────────────────────────────────────────┘
244
+ ```
245
+
246
+ ### Tech Stack
247
+
248
+ | Component | Technology | Purpose |
249
+ |-----------|-----------|---------|
250
+ | **PR Query** | GitHub GraphQL API | Find PRs with conflicts/failures |
251
+ | **CI Checks** | `gh pr checks` JSON output | Detect failing tests |
252
+ | **Worktree Isolation** | `git worktree add` | Isolated PR workspaces |
253
+ | **Agent Orchestration** | `TaskDispatcher` | Spawn AI agents in tmux |
254
+ | **AI CLI** | Claude/Codex/Gemini | Execute fixes autonomously |
255
+ | **Workspace Management** | `/tmp/{repo}/{pr-branch}/` | Clean isolated environments |
256
+
257
+ ### Usage
258
+
259
+ #### CLI Commands
260
+
261
+ ```bash
262
+ # Fix PRs with default settings (last 24h, max 5 PRs, Claude CLI)
263
+ python3 -m orchestrated_pr_runner
264
+
265
+ # Custom time window and PR limit
266
+ python3 -m orchestrated_pr_runner --cutoff-hours 48 --max-prs 10
267
+
268
+ # Use different AI CLI
269
+ python3 -m jleechanorg_pr_automation.orchestrated_pr_runner --agent-cli codex
270
+ python3 -m jleechanorg_pr_automation.orchestrated_pr_runner --agent-cli gemini
271
+
272
+ # List actionable PRs without fixing
273
+ jleechanorg-pr-monitor --fixpr --dry-run
274
+ ```
275
+
276
+ #### Slash Command Integration
277
+
278
+ ```bash
279
+ # Fix specific PR (from Claude Code)
280
+ /fixpr 123
281
+
282
+ # With auto-apply for safe fixes
283
+ /fixpr 123 --auto-apply
284
+
285
+ # Pattern detection mode (fixes similar issues)
286
+ /fixpr 123 --scope=pattern
287
+ ```
288
+
289
+ #### Integration with PR Monitor
290
+
291
+ ```bash
292
+ # Monitor and fix in one command
293
+ jleechanorg-pr-monitor --fixpr --max-prs 5 --fixpr-agent claude
294
+ ```
295
+
296
+ ### Agent CLI Options
297
+
298
+ The FixPR workflow supports multiple AI CLIs for autonomous fixing:
299
+
300
+ | CLI | Model | Best For | Configuration |
301
+ |-----|-------|----------|---------------|
302
+ | **claude** | Claude Sonnet 4.5 | Complex refactors, multi-file changes | Default |
303
+ | **codex** | OpenAI Codex | Code generation, boilerplate fixes | Requires `codex` binary in PATH |
304
+ | **gemini** | Gemini 3 Pro | Large codebases, pattern detection | `pip install google-gemini-cli` + `GOOGLE_API_KEY` |
305
+
306
+ **Usage:**
307
+ ```bash
308
+ # Explicit CLI selection
309
+ python3 -m orchestrated_pr_runner --agent-cli gemini
310
+
311
+ # Via environment variable
312
+ export AGENT_CLI=codex
313
+ python3 -m orchestrated_pr_runner
314
+ ```
315
+
316
+ ### Workspace Structure
317
+
318
+ ```
319
+ /tmp/
320
+ ├── pr-orch-bases/ # Base clones (shared)
321
+ │ ├── worldarchitect.ai/
322
+ │ └── ai_universe/
323
+ └── {repo}/ # PR workspaces (isolated)
324
+ ├── pr-123-fix-auth/
325
+ ├── pr-456-merge-conflict/
326
+ └── pr-789-test-failures/
327
+ ```
328
+
329
+ ### Key Features
330
+
331
+ - ✅ **Autonomous fixing** - AI agents work independently
332
+ - ✅ **Worktree isolation** - Each PR gets clean workspace
333
+ - ✅ **Multi-CLI support** - Claude, Codex, or Gemini
334
+ - ✅ **Tmux sessions** - Long-running agents in background
335
+ - ✅ **Result tracking** - JSON reports in `/tmp/orchestration_results/`
336
+ - ✅ **Safety limits** - Respects global and per-PR limits
337
+
338
+ ---
339
+
340
+ ## 🤝 Workflow 3: Codex GitHub Mentions Automation
341
+
342
+ ### What It Does
343
+
344
+ The Codex GitHub Mentions automation processes "GitHub Mention:" tasks from OpenAI's Codex interface via browser automation. When GitHub issues or PRs are mentioned in Codex conversations, they appear as actionable tasks that require manual approval to update the branch. This workflow automates clicking the "Update branch" button for each task.
345
+
346
+ ### How It Works
347
+
348
+ ```
349
+ ┌─────────────────────────────────────────────────────────────┐
350
+ │ 1. AUTHENTICATION │
351
+ │ ───────────────────────────────────────────────────────────│
352
+ │ • Connect to existing Chrome via CDP (port 9222) │
353
+ │ • Load saved auth state from Storage State API │
354
+ │ • Skip login if cookies/localStorage already exist │
355
+ │ • Auth persisted to ~/.chatgpt_codex_auth_state.json │
356
+ └─────────────────────────────────────────────────────────────┘
357
+
358
+ ┌─────────────────────────────────────────────────────────────┐
359
+ │ 2. TASK DISCOVERY │
360
+ │ ───────────────────────────────────────────────────────────│
361
+ │ • Navigate to https://chatgpt.com/codex/tasks │
362
+ │ • Find all task links matching "GitHub Mention:" │
363
+ │ • Collect task URLs and metadata │
364
+ │ • Filter to first N tasks (default: 50) │
365
+ └─────────────────────────────────────────────────────────────┘
366
+
367
+ ┌─────────────────────────────────────────────────────────────┐
368
+ │ 3. TASK PROCESSING │
369
+ │ ───────────────────────────────────────────────────────────│
370
+ │ • Navigate to each task page │
371
+ │ • Wait for page to fully load │
372
+ │ • Search for "Update branch" button │
373
+ │ • Click button if present │
374
+ │ • Log success/failure for each task │
375
+ └─────────────────────────────────────────────────────────────┘
376
+
377
+ ┌─────────────────────────────────────────────────────────────┐
378
+ │ 4. STATE PERSISTENCE │
379
+ │ ───────────────────────────────────────────────────────────│
380
+ │ • Save cookies and localStorage to auth state file │
381
+ │ • Auth persists across runs (no manual login required) │
382
+ │ • Browser context reusable for future runs │
383
+ └─────────────────────────────────────────────────────────────┘
384
+ ```
385
+
386
+ ### Tech Stack
387
+
388
+ | Component | Technology | Purpose |
389
+ |-----------|-----------|---------|
390
+ | **Browser Automation** | Playwright (Python) | Controls Chrome via CDP |
391
+ | **CDP Connection** | Chrome DevTools Protocol | Connects to existing browser on port 9222 |
392
+ | **Auth Persistence** | Storage State API | Saves/restores cookies and localStorage |
393
+ | **Cloudflare Bypass** | Existing browser session | Avoids rate limiting by appearing as normal user |
394
+ | **Task Selection** | CSS selector `a:has-text("GitHub Mention:")` | Finds GitHub PR tasks |
395
+ | **Scheduling** | cron | Runs every hour at :15 past the hour |
396
+
397
+ ### Usage
398
+
399
+ #### Prerequisites
400
+
401
+ **Start Chrome with remote debugging:**
402
+ ```bash
403
+ # Kill existing Chrome instances
404
+ killall "Google Chrome" 2>/dev/null
405
+
406
+ # Start Chrome with CDP enabled (custom profile to avoid conflicts)
407
+ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
408
+ --remote-debugging-port=9222 \
409
+ --user-data-dir="$HOME/.chrome-cdp-debug" \
410
+ > /dev/null 2>&1 &
411
+
412
+ # Verify CDP is accessible
413
+ curl -s http://localhost:9222/json/version | python3 -m json.tool
414
+
415
+ # IMPORTANT: Log in to chatgpt.com manually in the Chrome window
416
+ # The automation will save your auth state for future runs
417
+ ```
418
+
419
+ #### CLI Commands
420
+
421
+ ```bash
422
+ # Run automation (connects to existing Chrome on port 9222)
423
+ python3 -m jleechanorg_pr_automation.openai_automation.codex_github_mentions \
424
+ --use-existing-browser \
425
+ --cdp-port 9222 \
426
+ --limit 50
427
+
428
+ # Debug mode with verbose logging
429
+ python3 -m jleechanorg_pr_automation.openai_automation.codex_github_mentions \
430
+ --use-existing-browser \
431
+ --cdp-port 9222 \
432
+ --limit 50 \
433
+ --debug
434
+
435
+ # Process only first 10 tasks
436
+ python3 -m jleechanorg_pr_automation.openai_automation.codex_github_mentions \
437
+ --use-existing-browser \
438
+ --cdp-port 9222 \
439
+ --limit 10
440
+ ```
441
+
442
+ #### Cron Job Integration
443
+
444
+ The automation runs automatically via cron every hour at :15 past the hour (offset from PR monitor):
445
+
446
+ ```bash
447
+ # Cron entry (installed via install_jleechanorg_automation.sh)
448
+ 15 * * * * jleechanorg-pr-monitor --codex-update >> \
449
+ $HOME/Library/Logs/worldarchitect-automation/codex_automation.log 2>&1
450
+ ```
451
+
452
+ **Note:** The `--codex-update` flag internally calls:
453
+ ```bash
454
+ python3 -m jleechanorg_pr_automation.openai_automation.codex_github_mentions \
455
+ --use-existing-browser --cdp-host 127.0.0.1 --cdp-port 9222 --limit 50
456
+ ```
457
+
458
+ **Self-healing:** If Chrome CDP is not reachable, `--codex-update` will auto-start Chrome
459
+ using the settings below before retrying.
460
+
461
+ #### Slash Command Integration
462
+
463
+ ```bash
464
+ # From Claude Code (manual run)
465
+ python3 -m jleechanorg_pr_automation.openai_automation.codex_github_mentions \
466
+ --use-existing-browser --cdp-port 9222 --limit 50
467
+ ```
468
+
469
+ ### Configuration
470
+
471
+ ```bash
472
+ # Required: Chrome with remote debugging on port 9222
473
+ # (See "Prerequisites" section above)
474
+
475
+ # Optional: Customize task limit (used by `jleechanorg-pr-monitor --codex-update`)
476
+ # Default: 200 (matches the standard cron entry). Override to keep evidence/test runs fast.
477
+ # Use: `jleechanorg-pr-monitor --codex-update --codex-task-limit 200`
478
+
479
+ # Optional: Auth state file location
480
+ # Default: ~/.chatgpt_codex_auth_state.json
481
+
482
+ # Optional: CDP self-heal controls (used by jleechanorg-pr-monitor --codex-update)
483
+ export CODEX_CDP_AUTO_START=1 # default: 1 (auto-start Chrome if needed)
484
+ export CODEX_CDP_HOST=127.0.0.1 # default: 127.0.0.1
485
+ export CODEX_CDP_PORT=9222 # default: 9222
486
+ export CODEX_CDP_USER_DATA_DIR="$HOME/.chrome-automation-profile"
487
+ export CODEX_CDP_START_TIMEOUT=20 # seconds to wait for CDP after start
488
+ # Optional: custom launcher (script path). Port is appended as final arg.
489
+ export CODEX_CDP_START_SCRIPT="/path/to/start_chrome_debug.sh"
490
+ ```
491
+
492
+ ### Key Features
493
+
494
+ - ✅ **CDP-based automation** - Connects to existing Chrome to bypass Cloudflare
495
+ - ✅ **Persistent authentication** - Storage State API saves cookies/localStorage
496
+ - ✅ **No manual login** - Auth state persists across runs
497
+ - ✅ **Cloudflare bypass** - Appears as normal user browsing, not a bot
498
+ - ✅ **Configurable limits** - Process 1-N tasks per run
499
+ - ✅ **Robust task detection** - Handles dynamic page loading
500
+
501
+ ### Troubleshooting
502
+
503
+ **Issue**: Cloudflare rate limiting (0 tasks found)
504
+ ```bash
505
+ # Solution: Use existing browser via CDP instead of launching new instances
506
+ # The CDP approach connects to your logged-in Chrome session, avoiding detection
507
+
508
+ # Verify Chrome is running with CDP enabled
509
+ curl -s http://localhost:9222/json/version
510
+
511
+ # Expected output:
512
+ # {
513
+ # "Browser": "Chrome/131.0.6778.265",
514
+ # "Protocol-Version": "1.3",
515
+ # "webSocketDebuggerUrl": "ws://localhost:9222/..."
516
+ # }
517
+ ```
518
+
519
+ **Issue**: Auth state not persisting
520
+ ```bash
521
+ # Check auth state file exists
522
+ ls -lh ~/.chatgpt_codex_auth_state.json
523
+
524
+ # Expected: ~5-6KB JSON file
525
+ # If missing: Log in manually to chatgpt.com in the CDP Chrome window
526
+ # The script will save auth state on first successful run
527
+ ```
528
+
529
+ **Issue**: "Update branch" button not found
530
+ ```bash
531
+ # Run with debug logging
532
+ python3 -m jleechanorg_pr_automation.openai_automation.codex_github_mentions \
533
+ --use-existing-browser \
534
+ --cdp-port 9222 \
535
+ --debug
536
+
537
+ # Check if tasks are actually "GitHub Mention:" type
538
+ # Only GitHub PR tasks have "Update branch" buttons
539
+ ```
540
+
541
+ **Issue**: Chrome CDP connection fails
542
+ ```bash
543
+ # Verify Chrome is running with correct flags
544
+ ps aux | grep "remote-debugging-port=9222"
545
+
546
+ # If not running, start Chrome with CDP:
547
+ killall "Google Chrome" 2>/dev/null
548
+ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
549
+ --remote-debugging-port=9222 \
550
+ --user-data-dir="$HOME/.chrome-cdp-debug" &
551
+ ```
552
+
553
+ **Issue**: Cron job failing with "unrecognized arguments: --codex-update"
554
+ ```bash
555
+ # This happens when installed PyPI package is older than source code
556
+ # Temporary solution: Run manually from source until PR merges and package updates
557
+
558
+ # Reinstall from source
559
+ cd automation
560
+ pip install -e .
561
+
562
+ # Verify flag exists
563
+ jleechanorg-pr-monitor --help | grep codex-update
564
+ ```
565
+
566
+ ---
567
+
568
+ ## Installation
569
+
570
+ ### From PyPI
571
+
572
+ ```bash
573
+ # Basic installation
574
+ pip install jleechanorg-pr-automation
575
+
576
+ # With email notifications
577
+ pip install jleechanorg-pr-automation[email]
578
+
579
+ # For development
580
+ pip install jleechanorg-pr-automation[dev]
581
+ ```
582
+
583
+ ### From Source (Development)
584
+
585
+ ```bash
586
+ # Clone and install from repository
587
+ cd ~/worldarchitect.ai/automation
588
+ pip install -e .
589
+
590
+ # With optional dependencies
591
+ pip install -e .[email,dev]
592
+ ```
593
+
594
+ ### macOS Automation (Scheduled Monitoring)
595
+
596
+ ```bash
597
+ # Install launchd service
598
+ ./automation/install_jleechanorg_automation.sh
599
+
600
+ # Verify service
601
+ launchctl list | grep jleechanorg
602
+
603
+ # View logs
604
+ tail -f ~/Library/Logs/worldarchitect-automation/jleechanorg_pr_monitor.log
605
+ ```
606
+
607
+ ### Crontab Management
608
+
609
+ Use the `restore_crontab.sh` script to manage cron jobs for all three automation workflows:
610
+
611
+ ```bash
612
+ # Dry run (preview what will be restored)
613
+ cd automation
614
+ ./restore_crontab.sh --dry-run
615
+
616
+ # Interactive restore (prompts for confirmation)
617
+ ./restore_crontab.sh
618
+
619
+ # Force restore (no prompts)
620
+ ./restore_crontab.sh --force
621
+
622
+ # View current crontab
623
+ crontab -l
624
+
625
+ # Restore from backup (if needed)
626
+ crontab ~/.crontab_backup_YYYYMMDD_HHMMSS
627
+ ```
628
+
629
+ **Standard Cron Jobs:**
630
+
631
+ | Schedule | Command | Purpose |
632
+ |----------|---------|---------|
633
+ | Every hour (`:00`) | `jleechanorg-pr-monitor` | Workflow 1: Post @codex comments |
634
+ | Every hour (`:15`) | `jleechanorg-pr-monitor --codex-update` | Workflow 3: Process Codex tasks |
635
+ | Every 30 minutes | `jleechanorg-pr-monitor --fixpr` | Workflow 2: Fix PRs autonomously |
636
+ | Every 4 hours | `claude_backup_cron.sh` | Backup Claude conversations |
637
+
638
+ ---
639
+
640
+ ## Safety System
641
+
642
+ Both workflows use `AutomationSafetyManager` for rate limiting:
643
+
644
+ ### Dual Limits
645
+
646
+ 1. **Per-PR Limit**: Max 10 consecutive attempts per PR (internal safety)
647
+ 2. **Global Limit**: Max 50 total automation runs per day
648
+ 3. **Workflow-Specific Comment Limits**: Each workflow has its own limit for automation comments per PR (some workflows may not currently post comments, but have limits reserved for future compatibility):
649
+ - **PR Automation**: 10 comments (default)
650
+ - **Fix-Comment**: 10 comments (default)
651
+ - **Codex Update**: 10 comments (default; does not currently post PR comments—limit reserved for future compatibility)
652
+ - **FixPR**: 10 comments (default)
653
+
654
+ These limits prevent one workflow from blocking others. Configure via CLI flags:
655
+ - `--pr-automation-limit`
656
+ - `--fix-comment-limit`
657
+ - `--fixpr-limit`
658
+
659
+ **Note**: Workflow comment counting is marker-based:
660
+ - PR automation comments: `codex-automation-commit`
661
+ - Fix-comment queued runs: `fix-comment-automation-run` (separate from completion marker)
662
+ - Fix-comment completion/review requests: `fix-comment-automation-commit`
663
+ - FixPR queued runs: `fixpr-automation-run`
664
+
665
+ ### Safety Data Storage
666
+
667
+ ```
668
+ ~/Library/Application Support/worldarchitect-automation/
669
+ ├── automation_safety_data.json # Attempt tracking
670
+ └── pr_history/ # Commit tracking per repo
671
+ ├── worldarchitect.ai/
672
+ │ ├── main.json
673
+ │ └── feature-branch.json
674
+ └── ai_universe/
675
+ └── develop.json
676
+ ```
677
+
678
+ ### Safety Commands
679
+
680
+ ```bash
681
+ # Check current status
682
+ automation-safety-cli status
683
+
684
+ # Example output:
685
+ # Global runs: 23/50
686
+ # Requires approval: False
687
+ # PR attempts:
688
+ # worldarchitect.ai-1634: 2/10 (OK)
689
+ # ai_universe-42: 10/10 (BLOCKED)
690
+
691
+ # Clear all data (reset limits)
692
+ automation-safety-cli clear
693
+
694
+ # Check specific PR
695
+ automation-safety-cli check-pr 123 --repo worldarchitect.ai
696
+ ```
697
+
698
+ ---
699
+
700
+ ## Architecture Comparison
701
+
702
+ | Feature | @codex Comment Agent | FixPR Workflow | Codex GitHub Mentions |
703
+ |---------|---------------------|----------------|----------------------|
704
+ | **Trigger** | New commits on open PRs | Merge conflicts or failing checks | Codex tasks queue |
705
+ | **Action** | Posts instruction comment | Autonomously fixes code | Clicks "Update branch" buttons |
706
+ | **Execution** | Quick (API calls only) | Long-running (agent in tmux) | Medium (browser automation) |
707
+ | **Workspace** | None (comment-only) | Isolated git worktree | Chrome CDP session |
708
+ | **AI CLI** | N/A (GitHub API) | Claude/Codex/Gemini | N/A (Playwright) |
709
+ | **Output** | GitHub PR comment | Code commits + JSON report | Browser button clicks |
710
+ | **Schedule** | Every hour | Every 30 minutes | Every hour at :15 |
711
+
712
+ ---
713
+
714
+ ## Environment Variables
715
+
716
+ ### Required
717
+
718
+ ```bash
719
+ export GITHUB_TOKEN="ghp_xxxxxxxxxxxx"
720
+ ```
721
+
722
+ ### Optional
723
+
724
+ ```bash
725
+ # Workspace configuration
726
+ export PR_AUTOMATION_WORKSPACE="/custom/path"
727
+
728
+ # Email notifications
729
+ export SMTP_SERVER="smtp.gmail.com"
730
+ export SMTP_PORT=587
731
+ export EMAIL_USER="your@email.com"
732
+ export EMAIL_PASS="app-password"
733
+ export EMAIL_TO="recipient@email.com"
734
+
735
+ # Agent CLI selection (for FixPR)
736
+ export AGENT_CLI="claude" # or "codex" or "gemini"
737
+ export GEMINI_MODEL="gemini-3-pro-preview"
738
+ ```
739
+
740
+ ---
741
+
742
+ ## Development
743
+
744
+ ### Running Tests
745
+
746
+ ```bash
747
+ # Run all tests
748
+ pytest
749
+
750
+ # With coverage
751
+ pytest --cov=jleechanorg_pr_automation
752
+
753
+ # Specific test suite
754
+ pytest automation/jleechanorg_pr_automation/tests/test_pr_filtering_matrix.py
755
+ ```
756
+
757
+ ### Code Quality
758
+
759
+ ```bash
760
+ # Format code
761
+ black .
762
+ ruff check .
763
+
764
+ # Type checking
765
+ mypy jleechanorg_pr_automation
766
+ ```
767
+
768
+ ---
769
+
770
+ ## Troubleshooting
771
+
772
+ ### @codex Comment Agent
773
+
774
+ **Issue**: No PRs discovered
775
+ ```bash
776
+ # Check GitHub authentication
777
+ gh auth status
778
+
779
+ # Verify organization access
780
+ gh repo list jleechanorg --limit 5
781
+ ```
782
+
783
+ **Issue**: Duplicate comments on same commit
784
+ ```bash
785
+ # Check commit marker detection
786
+ python3 -c "from jleechanorg_pr_automation.check_codex_comment import decide; print(decide('<!-- codex-automation-commit:', '-->'))"
787
+ ```
788
+
789
+ ### FixPR Workflow
790
+
791
+ **Issue**: Worktree creation fails
792
+ ```bash
793
+ # Clean stale worktrees
794
+ cd ~/worldarchitect.ai
795
+ git worktree prune
796
+
797
+ # Remove old workspace
798
+ rm -rf /tmp/worldarchitect.ai/pr-*
799
+ ```
800
+
801
+ **Issue**: Agent not spawning
802
+ ```bash
803
+ # Check tmux sessions
804
+ tmux ls
805
+
806
+ # View agent logs
807
+ ls -la /tmp/orchestration_results/
808
+ ```
809
+
810
+ **Issue**: Wrong AI CLI used
811
+ ```bash
812
+ # Verify CLI availability
813
+ which claude codex gemini
814
+
815
+ # Set explicit CLI
816
+ export AGENT_CLI=claude
817
+ python3 -m orchestrated_pr_runner
818
+ ```
819
+
820
+ ---
821
+
822
+ ## Contributing
823
+
824
+ 1. Fork the repository
825
+ 2. Create a feature branch
826
+ 3. Add tests for new functionality
827
+ 4. Ensure all tests pass (`pytest`)
828
+ 5. Format code (`black . && ruff check .`)
829
+ 6. Submit a pull request
830
+
831
+ ---
832
+
833
+ ## License
834
+
835
+ MIT License - see LICENSE file for details.
836
+
837
+ ---
838
+
839
+ ## Changelog
840
+
841
+ ### 0.2.21 (Latest)
842
+ - Refined Codex updater logging and update-branch click handling.
843
+
844
+ ### 0.2.20
845
+ - Stabilized Codex updater tab reuse and recovery when pages close mid-run.
846
+ - Added login verification guard and extra diagnostics for tab switching.
847
+
848
+ ### 0.2.19
849
+ - Fixed `cleanup()` indentation so `CodexGitHubMentionsAutomation` can release resources.
850
+ - Note: version 0.2.18 was intentionally skipped (no public release).
851
+
852
+ ### 0.2.5
853
+ - Enhanced @codex comment detection with actor pattern matching
854
+ - Improved commit marker parsing for multiple AI assistants
855
+ - Added Gemini CLI support for FixPR workflow
856
+
857
+ ### 0.1.1
858
+ - Fixed daily reset of global automation limit
859
+ - Added last reset timestamp tracking
860
+
861
+ ### 0.1.0
862
+ - Initial release with @codex comment agent and FixPR workflow
863
+ - Comprehensive safety system with dual limits
864
+ - Cross-organization PR monitoring