| 1 | --- |
| 2 | name: react-grab |
| 3 | description: >- |
| 4 | Use when the user wants a hands-free loop where grabbing UI elements in the |
| 5 | browser with React Grab feeds tasks to the agent automatically, with no |
| 6 | copy-paste or manual handoff. Triggers: "watch react grab", "monitor my |
| 7 | grabs", "auto-process react grab", "watch my clipboard for grabs". Not for a |
| 8 | one-off paste of a single grab; this is the continuous, always-on loop. |
| 9 | --- |
| 10 | |
| 11 | # React Grab |
| 12 | |
| 13 | The user selects UI elements in their browser and copies them with React Grab. |
| 14 | `npx react-grab@latest pull` waits for new grabs and prints each as one line of |
| 15 | JSON (usually one, sometimes a few if several were copied), starting the |
| 16 | background watcher automatically the first time. Run it in a loop. |
| 17 | |
| 18 | ## The loop |
| 19 | |
| 20 | Repeat until the user says stop: |
| 21 | |
| 22 | 1. Wait for the next grab: |
| 23 | |
| 24 | ```bash |
| 25 | npx react-grab@latest pull --max-age |
| 26 | ``` |
| 27 | |
| 28 | It blocks until the user grabs something, then prints the new grab(s) — one JSON |
| 29 | object per line. `--max-age 0` is important: it delivers every grab regardless of |
| 30 | age, so a comment the user added while you were busy on the previous task isn't |
| 31 | silently dropped (the default skips grabs older than ~5 min as stale). Act on |
| 32 | every line. If your shell cancels the command before a grab arrives, just run it |
| 33 | again — nothing is lost; the watcher keeps capturing in the background and `pull` |
| 34 | resumes where it left off. |
| 35 | |
| 36 | 2. Act on the grab (below). |
| 37 | 3. Go back to step 1. |
| 38 | |
| 39 | ## A new grab while you're working wins |
| 40 | |
| 41 | The watcher never stops capturing — including while you're mid-task. A grab the |
| 42 | user makes before you finish is them redirecting you, so it supersedes whatever |
| 43 | you're doing. Don't make them wait for the old task to finish. |
| 44 | |
| 45 | While acting on a grab: |
| 46 | |
| 47 | - Run anything slow (dev servers, builds, installs, test runs) as a background |
| 48 | process, never a blocking foreground call, so you stay free to notice new grabs. |
| 49 | - Between steps, peek without blocking: |
| 50 | |
| 51 | ```bash |
| 52 | npx react-grab@latest pull --max-age |
| 53 | ``` |
| 54 | |
| 55 | Empty output means nothing new — keep going. If it prints a grab, the user has |
| 56 | moved on: stop the current task, cancel any background processes you started for |
| 57 | it, and act on the newest grab instead. |
| 58 | |
| 59 | ## Acting on a grab |
| 60 | |
| 61 | Each grab JSON has `content` (the element's source references) and, in prompt |
| 62 | mode, `prompt` (the user's typed instruction): |
| 63 | |
| 64 | - **`prompt` |
| 65 | source; `content` holds the references (`// path:line`, ` |
| 66 | so jump straight to that file. |
| 67 | - **No `prompt |
| 68 | loop, or, if there is none, triage it (summarize component + `file:line`) and |
| 69 | wait for direction. |
| 70 | |
| 71 | ## Stopping |
| 72 | |
| 73 | When the user says stop, run this and don't pull again: |
| 74 | |
| 75 | ```bash |
| 76 | npx react-grab@latest stop |
| 77 | ``` |
| 78 | |
| 79 | ## Notes |
| 80 | |
| 81 | - The watcher reads the clipboard on the machine it runs on — run it on the same |
| 82 | machine as the browser, not over SSH or in a remote container. |