diff --git a/DISCOVERY.md b/DISCOVERY.md new file mode 100644 index 0000000..5ed4ca4 --- /dev/null +++ b/DISCOVERY.md @@ -0,0 +1,375 @@ +# GrokAuto Discovery Notes + +**Host:** `dsd.890.be` +**User:** `grok` +**Project path:** `/home/grok/grokauto` +**Local mirror:** `/Users/martin/dsd_890_be/grokauto` + +GrokAuto is a headless-browser automation tool that drives `grok.com` through the Chrome DevTools Protocol (CDP). It reads tasks from a JSON config, sends each prompt to Grok, waits for the streaming response to finish, and writes the results to timestamped Markdown files. + +--- + +## 1. Architecture + +``` +main.py +├── modules/deps_checker.py System dependency checks (Chrome, Python, pip, Xvfb, cron) +├── modules/config_validator.py JSON config parsing and validation +├── modules/browser_ctl.py Launch Chromium and talk CDP over WebSocket +├── modules/login_validator.py Heuristic grok.com login detection +├── modules/task_executor.py Send prompts, wait for streaming, capture response text +└── modules/response_writer.py Format and persist Markdown output files +``` + +### 1.1 `main.py` + +CLI orchestrator. Sub-commands: + +| Flag | Purpose | +|------|---------| +| `--diagnose` | Full dependency + configuration diagnostic | +| `--check-deps` | Dependency report only | +| `--validate-config` | Config report only | +| `--run` | Execute tasks from config (default action) | +| `--prompt "..."` | Run a single inline prompt | +| `--task-id ID` | Run only one task from config | +| `--setup-cron "SCHEDULE"` | Install a crontab entry | +| `--remove-cron` | Remove the crontab entry | +| `--list-outputs` | List saved `.md` outputs | + +The default action is `--run`. Execution flow: + +1. Validate dependencies. +2. Validate and load config. +3. Launch Chrome with `--remote-debugging-port=9222`. +4. Check grok.com login state; abort if not authenticated. +5. Run selected tasks. +6. Save responses to `output_dir` with mode `0o600`. +7. Print summary and close browser. + +### 1.2 `modules/browser_ctl.py` + +- Launches Chromium with `--remote-debugging-port`, `--user-data-dir`, `--headless=new`, and anti-automation flags. +- Connects to CDP via `websocket-client`. +- Exposes `navigate_to`, `execute_js`, `wait_for_element`, `get_page_source`, `close_browser`. +- Pre-flight port check: refuses to launch if `127.0.0.1:debug_port` is already open. +- Registers an `atexit` cleanup handler. + +### 1.3 `modules/task_executor.py` + +- Navigates to `https://grok.com`, waits 4s for React hydration. +- Finds the chat input using a fallback selector chain (`contenteditable`, `textarea`, etc.). +- Handles both ProseMirror/tiptap `contenteditable` inputs and plain `