diff --git a/.cursor/rules/00-always-read-rules.mdc b/.cursor/rules/00-always-read-rules.mdc index 35460ae..2243da5 100644 --- a/.cursor/rules/00-always-read-rules.mdc +++ b/.cursor/rules/00-always-read-rules.mdc @@ -17,6 +17,7 @@ alwaysApply: true |--------|-------------------------------------| | `git commit` / `push` | `no-cursor-in-repositories` — нет `.cursor/` в staged; `.gitignore` содержит `.cursor/` | | Push в `home` | `gitea-home-api` — сначала API, потом SSH push | +| Создание/правка .ps1, .sh, runtime JSON | ile-encoding — UTF-8 BOM+CRLF (PS), UTF-8+LF (sh), spool без BOM | | Bump версии | `version-bump` (+ `version-bump-rdp` / `version-bump-ssh` для агентских мониторов) | | Коммит | `git log -1 --format=fuller` — нет `cursoragent`, `Co-authored-by: Cursor` | diff --git a/.cursor/rules/file-encoding.mdc b/.cursor/rules/file-encoding.mdc new file mode 100644 index 0000000..f509049 --- /dev/null +++ b/.cursor/rules/file-encoding.mdc @@ -0,0 +1,51 @@ +--- +description: Кодировка и переносы строк для Windows (PowerShell) и Linux (shell) +alwaysApply: true +--- + +# Кодировка файлов (Windows / Linux) + +Исходники и runtime-текст должны сохраняться в кодировке, которую ожидает среда выполнения. Неверная кодировка ломает парсинг PowerShell/bash, regex по JSON и spool-файлы на диске. + +## Windows — PowerShell (`.ps1`, `.psm1`, `.psd1`) + +| Параметр | Значение | +|----------|----------| +| Кодировка исходников | **UTF-8 with BOM** (PS 5.1, кириллица в комментариях и строках) | +| Переносы | **CRLF** | +| EditorConfig | `charset = utf-8-bom`, `end_of_line = crlf` для `[*.ps1]` | + +- Не сохранять `.ps1` как UTF-16 LE/BE, CP1251 или «Unicode» без явной необходимости. +- JSON и текст на диск для API/SAC/spool: **UTF-8 без BOM** — `[System.IO.File]::WriteAllText($path, $text, (New-Object System.Text.UTF8Encoding $false))`. +- Чтение legacy/spool: UTF-8 → UTF-16 LE (BOM `FF FE` или `{` + `0x00` в начале файла). + +## Linux — shell (`.sh`, исполняемые скрипты) + +| Параметр | Значение | +|----------|----------| +| Кодировка | **UTF-8 без BOM** | +| Переносы | **LF** | +| Shebang | `#!/usr/bin/env bash` или `#!/bin/sh` | + +- Не коммитить `.sh` с **CRLF** и **BOM** — на Linux: `$'\r': command not found`, сбой shebang. +- После правки на Windows: `dos2unix path/to/script.sh` или в `.gitattributes`: `*.sh text eol=lf`. + +## Python, JSON, конфиги в git + +| Тип | Кодировка | EOL | +|-----|-----------|-----| +| `*.py` | UTF-8 без BOM | LF (или по `.editorconfig` проекта) | +| `*.json`, `*.yaml`, `*.md` | UTF-8 без BOM | LF или CRLF по проекту | +| `*.vue`, `*.ts`, `*.js` | UTF-8 без BOM | LF | + +## Обязательно в репозитории + +- **`.editorconfig`** — явные правила для `*.ps1`, `*.sh`, `*.py`. +- **`.gitattributes`** — минимум: `*.ps1 text eol=crlf`, `*.sh text eol=lf`. + +## Агент + +1. Перед записью файла — проверить `.editorconfig` / `.gitattributes` **текущего проекта**. +2. Если их нет — следовать таблицам выше. +3. Не перекодировать бинарники и файлы, которые уже корректны. +4. При правке PowerShell, который пишет файлы на диск (`spool`, логи, экспорт) — явно задавать UTF-8 без BOM, если файл читает другой процесс или Linux. diff --git a/.cursor/rules/powershell-spec.mdc b/.cursor/rules/powershell-spec.mdc index 588777f..2fa292b 100644 --- a/.cursor/rules/powershell-spec.mdc +++ b/.cursor/rules/powershell-spec.mdc @@ -10,3 +10,7 @@ alwaysApply: false - Без comment-based help и лишних `Write-Host`, если не просили UI/логи. - Не дублируй длинные CLI-аргументы целиком — placeholder или переменная. - Сохраняй стиль и алиасы **существующего файла**; не навязывай `gc`/`gci` если в проекте полные имена. + +## Кодировка и EOL + +См. **`file-encoding.mdc`**: `.ps1` — **UTF-8 with BOM**, **CRLF**; runtime JSON/spool на диск — **UTF-8 без BOM**. diff --git a/.cursor/rules/shell-spec.mdc b/.cursor/rules/shell-spec.mdc new file mode 100644 index 0000000..8353cb3 --- /dev/null +++ b/.cursor/rules/shell-spec.mdc @@ -0,0 +1,15 @@ +--- +description: Компактный shell/bash в выводе агента +globs: **/*.{sh,bash} +alwaysApply: false +--- + +# Shell (Linux) — компактный вывод + +- `set -euo pipefail` в bootstrap/install-скриптах, где уместно; не ломать интерактивные сценарии. +- Кавычки вокруг переменных; `"$var"` вместо `$var`. +- Без лишнего `echo` в библиотечных функциях — только UI/логи по делу. + +## Кодировка и EOL + +См. **`file-encoding.mdc`**: `.sh` — **UTF-8 без BOM**, **LF**. После правки на Windows — проверить отсутствие `\r`. diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..55e9303 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true + +[*.ps1] +charset = utf-8-bom +end_of_line = crlf + +[*.psm1] +charset = utf-8-bom +end_of_line = crlf + +[*.sh] +charset = utf-8 +end_of_line = lf + +[*.md] +end_of_line = lf diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..609182e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,13 @@ +* text=auto + +*.ps1 text eol=crlf +*.psm1 text eol=crlf +*.psd1 text eol=crlf + +*.sh text eol=lf +*.bash text eol=lf + +*.md text eol=lf +*.json text eol=lf +*.yml text eol=lf +*.yaml text eol=lf diff --git a/README.md b/README.md index 355da70..33e9957 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,22 @@ Push: `git push kalinamall` --- +## Кодировка файлов (Windows / Linux) + +Правило **`file-encoding`** (`.cursor/rules/file-encoding.mdc`, `alwaysApply: true`): + +| Среда | Расширения | Кодировка | Переносы | +|-------|------------|-----------|----------| +| Windows / PowerShell | `.ps1`, `.psm1` | UTF-8 **with BOM** | CRLF | +| Linux / shell | `.sh` | UTF-8 **без BOM** | LF | +| Runtime JSON/spool (PS → SAC/API) | на диске | UTF-8 **без BOM** | — | + +В репозиториях проектов — `.editorconfig` и `.gitattributes` (шаблоны есть в этом repo). + +После `init-cursor --update` правило попадает во все проекты. + +--- + ## Конфиги (`local/`) | Файл | Назначение |