From 7e14dbcf8be0aca9d9d5f3c0217d4274ac0bc73f Mon Sep 17 00:00:00 2001 From: Aleksey Sabilin Date: Wed, 29 Jul 2026 12:55:01 +0300 Subject: [PATCH] docs(rules): require run-wsl-sh for CRLF .sh scripts Cursor Write on Windows often saves CRLF; bare wsl -e bash script.sh then fails with No such file. Canon is run-wsl-sh.sh (strip CR). --- .cursor/rules/agent-pitfalls.mdc | 9 ++-- .cursor/rules/shell-wsl-not-powershell.mdc | 62 +++++++++++++++++----- 2 files changed, 56 insertions(+), 15 deletions(-) diff --git a/.cursor/rules/agent-pitfalls.mdc b/.cursor/rules/agent-pitfalls.mdc index a5417f6..90dbbe2 100644 --- a/.cursor/rules/agent-pitfalls.mdc +++ b/.cursor/rules/agent-pitfalls.mdc @@ -11,12 +11,15 @@ alwaysApply: true | Симптом | Причина | Как правильно | |---------|---------|---------------| -| `unexpected EOF`, `ParserError`, пустой curl | PS ломает `"`, `$`, heredoc, `&&` | Файл `.sh` → `wsl -e bash /mnt/c/.../script.sh` | +| `bash: /mnt/c/.../.tmp-*.sh: No such file or directory` при том что `ls` файл видит | **CRLF** от Cursor Write: shebang = `bash\r` | **Всегда** `wsl -e bash /mnt/c/Users/alexc/.cursor/eventhub/run-wsl-sh.sh /mnt/c/.../script.sh` (или `sed -i 's/\r$//' && bash`). **Не** голый `wsl -e bash /mnt/c/.../script.sh` | +| `unexpected EOF`, `ParserError`, пустой curl | PS ломает `"`, `$`, heredoc, `&&` | Файл `.sh` → `run-wsl-sh.sh` | | `bash: syntax error near '('` | `grep -E ^(...)` в PS; **`fix(ci):` / `(…)` в `wsl -lc` one-liner** | Только внутри `.sh`; commit → `-F` файл (см. ниже) | | `{{.Names}}: command not found` | `docker --format "{{…}}"` в PS | Формат в `.sh` или простой `docker ps` | | `&&` is not valid | PowerShell не bash | Отдельные команды или `.sh` | -**Запрещено в PS:** `wsl -e bash -lc "…\"…"`, `curl -d "{\"x\":…}"`, heredoc commit, `npm`/`rebar3`. +**Запрещено в PS:** голый `wsl -e bash /mnt/c/.../.tmp-*.sh` (без `run-wsl-sh.sh`), `wsl -e bash -lc "…\"…"`, `curl -d "{\"x\":…}"`, heredoc commit, `npm`/`rebar3`. + +Канон запуска скриптов: см. `shell-wsl-not-powershell.mdc` § CRLF. ## 2. Git @@ -43,7 +46,7 @@ git add path/to/file GIT_EDITOR=true git commit -F .tmp-commit-msg.txt ``` -Запуск из PS: `wsl -e bash /mnt/c/.../EventHubBack/.tmp-commit.sh` — **без** `-lc` и **без** `-m "fix(ci): …"`. +Запуск из PS: `wsl -e bash /mnt/c/Users/alexc/.cursor/eventhub/run-wsl-sh.sh /mnt/c/.../EventHubBack/.tmp-commit.sh` — **без** голого `wsl -e bash …/.tmp-commit.sh`, **без** `-lc` и **без** `-m "fix(ci): …"`. ## 3. Docker dev (Swarm локально) diff --git a/.cursor/rules/shell-wsl-not-powershell.mdc b/.cursor/rules/shell-wsl-not-powershell.mdc index 34b922c..8b54896 100644 --- a/.cursor/rules/shell-wsl-not-powershell.mdc +++ b/.cursor/rules/shell-wsl-not-powershell.mdc @@ -11,20 +11,53 @@ PowerShell в Cursor **ломает** кавычки, `$`, JSON, heredoc и вл ## Правило 1. **Нельзя** гонять сложные one-liner’ы в PowerShell (npm, curl+JSON, python -c, git commit heredoc, вложенный bash с кавычками). 2. **Можно** в PowerShell только простые вещи: `cd`, `git status`, `ls`, одиночный `wsl …` без вложенных кавычек в аргументе. -3. Рабочий способ — **WSL bash** или **файл `.sh` + `wsl -e bash /path/to/script.sh`**. +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` (LF, `#!/usr/bin/env bash`). -2. Запусти **без** вложенных кавычек в PowerShell: +1. Запиши команды в файл, например `EventHubBack/.tmp-run.sh` или `~/.cursor/eventhub/….sh` (`#!/usr/bin/env bash`). +2. Запусти **только** так (из PowerShell, без вложенных кавычек): ```text -wsl -e bash /mnt/c/Users/alexc/IdeaProjects/eventHub/EventHubBack/.tmp-run.sh +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: +Только если внутри **одинарные** кавычки bash и нет `"`/`$` конфликтов с PS (и **нет** нового `.sh` с диска C): ```text wsl -e bash -lc 'cd /mnt/c/Users/alexc/IdeaProjects/eventHub/EventHubFront && npm run lint' @@ -34,6 +67,7 @@ wsl -e bash -lc 'cd /mnt/c/Users/alexc/IdeaProjects/eventHub/EventHubFront && np ### Запрещено ```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 не так @@ -44,7 +78,7 @@ npm / npx / node из Windows # сломан ### Git commit — канон (subject с `( )`, `#`, `$`) -1. Текст коммита — в файл репо, напр. `.tmp-commit-msg.txt` (LF, без heredoc из PS). +1. Текст коммита — в файл репо, напр. `.tmp-commit-msg.txt` (без heredoc из PS). 2. Скрипт `.tmp-commit.sh`: ```bash @@ -55,7 +89,11 @@ git add path1 path2 GIT_EDITOR=true git commit -F .tmp-commit-msg.txt ``` -3. Из PowerShell только: `wsl -e bash /mnt/c/.../EventHubBack/.tmp-commit.sh` +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. @@ -63,11 +101,11 @@ GIT_EDITOR=true git commit -F .tmp-commit-msg.txt | Задача | Как | |-----|-----| -| Front lint/build/e2e | `wsl -e bash` + `cd …/EventHubFront && npm …` | -| Front перед push main | сначала `npm run test:e2e:ift` в WSL, потом `~/.cursor/eventhub/git-push-main.sh` | +| 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`; **push:** `bash /mnt/c/Users/alexc/.cursor/eventhub/git-push.sh …` | -| JSON/API/python | скрипт `.sh` или `.py` на диске, запуск из 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 (обязательно) @@ -89,4 +127,4 @@ Credential store в WSL уже настроен (`credential.helper=store` + `gi 3. Только потом push через `git-push-main.sh`. **Не пушить**, если lint/build/IFT красные. ## Частые сбои (подробнее) -См. **`agent-pitfalls.mdc`**: git `-F` вместо heredoc, `&&` в PS, docker dev scale, `git clean` vs `.cursor/`. +См. **`agent-pitfalls.mdc`**: CRLF/`run-wsl-sh.sh`, git `-F`, `&&` в PS, docker dev scale, `git clean` vs `.cursor/`.