--- description: EventHub — команды только через WSL/bash; PowerShell для сложного запрещён alwaysApply: true --- # EventHub: как запускать команды (обязательно) ## Проблема PowerShell в Cursor **ломает** кавычки, `$`, JSON, heredoc и вложенный `bash -lc "..."`. Из‑за этого агенты снова и снова получают `unexpected EOF`, `Invalid JSON`, пустой curl. ## Правило 1. **Нельзя** гонять сложные one-liner’ы в PowerShell (npm, curl+JSON, python -c, git commit heredoc, вложенный bash с кавычками). 2. **Можно** в PowerShell только простые вещи: `cd`, `git status`, `ls`, одиночный `wsl …` без вложенных кавычек в аргументе. 3. Рабочий способ — **WSL bash** или **файл `.sh` + launcher** (см. ниже). ## CRLF / «No such file or directory» (обязательно) Cursor `Write` на Windows часто сохраняет `.sh` с **CRLF**. Тогда: ```text wsl -e bash /mnt/c/.../EventHubFront/.tmp-run.sh # bash: .../.tmp-run.sh: No such file or directory ``` Файл **есть** (`ls` его видит) — ломается shebang (`#!/usr/bin/env bash\r`). Это **не** «файл не записался». ### Канон запуска любого `.sh` с `/mnt/c/...` **Всегда** через хелпер (снимает `\r`, потом `bash`): ```text wsl -e bash /mnt/c/Users/alexc/.cursor/eventhub/run-wsl-sh.sh /mnt/c/Users/alexc/IdeaProjects/eventHub/EventHubFront/.tmp-run.sh ``` **Запрещено** после `Write` голый: ```text wsl -e bash /mnt/c/.../repo/.tmp-something.sh ``` Альтернатива без хелпера (тот же смысл): ```text wsl -e bash -lc 'sed -i "s/\r$//" /mnt/c/.../script.sh && bash /mnt/c/.../script.sh' ``` Предпочтительно класть долгоживущие скрипты в `/mnt/c/Users/alexc/.cursor/eventhub/` и тоже гонять через `run-wsl-sh.sh`. ## Канон (копируй) ### Вариант A — скрипт (предпочтительно) 1. Запиши команды в файл, например `EventHubBack/.tmp-run.sh` или `~/.cursor/eventhub/….sh` (`#!/usr/bin/env bash`). 2. Запусти **только** так (из PowerShell, без вложенных кавычек): ```text wsl -e bash /mnt/c/Users/alexc/.cursor/eventhub/run-wsl-sh.sh /mnt/c/Users/alexc/IdeaProjects/eventHub/EventHubBack/.tmp-run.sh ``` ### Вариант B — один простой WSL вызов Только если внутри **одинарные** кавычки bash и нет `"`/`$` конфликтов с PS (и **нет** нового `.sh` с диска C): ```text wsl -e bash -lc 'cd /mnt/c/Users/alexc/IdeaProjects/eventHub/EventHubFront && npm run lint' ``` В PowerShell для `-lc` используй **одинарные** кавычки снаружи (`'...'`), внутри — обычный bash. ### Запрещено ```text wsl -e bash /mnt/c/.../.tmp-run.sh # без run-wsl-sh / sed — CRLF → No such file wsl -e bash -lc ".... python -c \"import...\" ...." # ломается curl ... -d "{\"email\":\"$x\"}" # в PS ломается git commit -m "$(cat <<'EOF' ...)" # в PS не так wsl -e bash -lc 'git-commit.sh … fix(ci): subject' # ( ) ломают bash wsl -e bash -lc 'git commit -m "fix(ci): …"' # то же npm / npx / node из Windows # сломан ``` ### Git commit — канон (subject с `( )`, `#`, `$`) 1. Текст коммита — в файл репо, напр. `.tmp-commit-msg.txt` (без heredoc из PS). 2. Скрипт `.tmp-commit.sh`: ```bash #!/usr/bin/env bash set -euo pipefail cd /mnt/c/Users/alexc/IdeaProjects/eventHub/EventHubBack git add path1 path2 GIT_EDITOR=true git commit -F .tmp-commit-msg.txt ``` 3. Из PowerShell: ```text wsl -e bash /mnt/c/Users/alexc/.cursor/eventhub/run-wsl-sh.sh /mnt/c/Users/alexc/IdeaProjects/eventHub/EventHubBack/.tmp-commit.sh ``` **Не** передавать сообщение аргументом в `git-commit.sh` / `-m` через `wsl -lc` — скобки в `fix(ci):` парсятся как subshell. ## Стек → команда | Задача | Как | |-----|-----| | Front lint/build/e2e | `.sh` + `run-wsl-sh.sh` или `-lc` с PATH-fix + `npm …` | | Front перед push main | сначала `npm run test:e2e:ift` в WSL, потом `git-push-main.sh` | | Back rebar/eunit | `source scripts/wsl-dev-env.sh` в WSL | | Git commit/push | **commit:** `.tmp-commit-msg.txt` + `git commit -F` в `.sh` через `run-wsl-sh.sh`; **push:** `bash /mnt/c/Users/alexc/.cursor/eventhub/git-push.sh …` | | JSON/API/python | скрипт `.sh`/`.py` + `run-wsl-sh.sh` | ## Git push (обязательно) **Запрещено агентам:** `git push`, `git push origin`, `git push origin HEAD` / `master` напрямую — без токена зависают на HTTPS prompt. **Канон:** ```text bash /mnt/c/Users/alexc/.cursor/eventhub/git-push.sh /mnt/c/Users/alexc/IdeaProjects/eventHub/EventHubBack bash /mnt/c/Users/alexc/.cursor/eventhub/git-push-main.sh /mnt/c/Users/alexc/IdeaProjects/eventHub/EventHubFront ``` Путь WSL: `/mnt/c/Users/alexc/.cursor/eventhub/` (не `~/.cursor/…` — home в WSL может отличаться). Credential store в WSL уже настроен (`credential.helper=store` + `git.sabilin.com`); хелпер всё равно предпочтителен (явный URL с токеном из secrets). ## Перед push Front 1. WSL: `npm run lint && npm run build` (ловит синтаксис/TS) 2. WSL: `npm run test:e2e:ift` 3. Только потом push через `git-push-main.sh`. **Не пушить**, если lint/build/IFT красные. ## Частые сбои (подробнее) См. **`agent-pitfalls.mdc`**: CRLF/`run-wsl-sh.sh`, git `-F`, `&&` в PS, docker dev scale, `git clean` vs `.cursor/`.