# Правила команд Codex для проекта (execpolicy, Starlark). # # Действуют на команды, которые Codex запускает вне sandbox (docker, сеть): # allow — без вопроса; # prompt — спросить пользователя перед каждым запуском; # forbidden — не запускать никогда. # Несколько совпавших правил — побеждает самое строгое (forbidden → # prompt → allow). pattern — точный префикс аргументов команды; список в # позиции — варианты. match / not_match — примеры, которые Codex # проверяет при загрузке правил. # # Файл загружается, только если проект доверенный (слой .codex/ проекта # trusted). После правки — перезапустить Codex. Проверка правила (команда — # без «--» перед ней: с ним ничего не сопоставляется): # codex execpolicy check --pretty --rules "$PWD/.codex/rules/messenger.rules" git push # # Источник запретов — корневой AGENTS.md, раздел 2 «Нельзя»; правила их # дублируют на уровне команд, но не заменяют. # --- git: только смотреть; изменения — по просьбе пользователя ------------- prefix_rule( pattern = ["git", ["status", "diff", "log", "show", "rev-parse", "ls-files"]], decision = "allow", justification = "Read-only git commands are always fine.", match = ["git status", "git diff --stat", "git log --oneline -5"], not_match = ["git commit -m x"], ) prefix_rule( pattern = ["git", ["commit", "checkout", "switch", "reset", "stash", "rebase", "merge", "restore", "tag", "branch"]], decision = "prompt", justification = "AGENTS.md: git changes only when the user asked for them (commit message in English, conventional style).", match = ["git commit -m 'feat: x'", "git reset --hard", "git checkout main"], not_match = ["git status"], ) prefix_rule( pattern = ["git", ["push", "clean"]], decision = "forbidden", justification = "Never push or clean the working tree: the user does it; git clean would delete evidence and local files.", match = ["git push", "git push origin main", "git clean -fdx"], ) # --- данные стендов: удаление только с согласия ----------------------------- prefix_rule( pattern = ["make", "wipe"], decision = "prompt", justification = "make wipe deletes the working stand volume (all data). Ask the user first (AGENTS.md, section 2, item 8).", match = ["make wipe"], ) prefix_rule( pattern = ["docker", "compose", "down", "-v"], decision = "prompt", justification = "down -v deletes volumes. The bench and test stands remove their own projects themselves; for the working stand ask the user.", match = ["docker compose down -v", "docker compose down -v --remove-orphans"], not_match = ["docker compose down"], ) prefix_rule( pattern = ["docker", "volume", ["rm", "prune"]], decision = "prompt", justification = "Deleting volumes deletes data: only bench leftovers (vlad-bench*) and only with the user's consent.", match = ["docker volume rm vlad-bench_pgdata", "docker volume prune -f"], ) prefix_rule( pattern = ["docker", ["rm", "kill", "stop", "pause"]], decision = "prompt", justification = "Only own containers (vladimirceva-lab4*, vlad-bench*); never containers of other projects.", match = ["docker rm -f vlad-bench-gen", "docker stop some-container"], ) prefix_rule( pattern = ["docker", ["system", "builder", "image", "container", "network"], "prune"], decision = "forbidden", justification = "Prune touches every project on this machine. Remove own leftovers by name instead (bench/AGENTS.md).", match = ["docker system prune -af", "docker image prune -a"], ) # --- процессы: не убивать по порту вслепую ------------------------------------ prefix_rule( pattern = [["kill", "pkill", "killall"]], decision = "prompt", justification = "Kill only a PID whose command is `python -m src` (AGENTS.md, section 10). A published port on macOS belongs to com.docker.backend: killing it stops Docker Desktop.", match = ["kill 12345", "pkill -f uvicorn"], ) prefix_rule( pattern = ["rm", ["-rf", "-fr", "-r"]], decision = "prompt", justification = "Recursive delete: label folders in evidence/ are removed only with the user's consent (bench/AGENTS.md).", match = ["rm -rf evidence/scaling/quick-x"], ) # --- проект: проверки, стенд, замеры — без вопроса ---------------------------- prefix_rule( pattern = [ "make", [ "install", "lint", "fmt", "check", "validate", "test", "load", "test-persistence", "test-failover", "student-test", "test-isolated", "failure-checks", "requirements", "requirements-check", "env", "docker-build", "up", "stop", "down", "logs", "db-up", "run", "migrate-local", "replicas", "instances", "lb-stats", "failover-each", "rolling-update", "attachment-failover", "s3-check", "cleanup-once", "bench-uploads", "bench-uploads-quick", "bench-reconcile", "bench-reconcile-quick", "bench-failover", "bench-failover-quick", "bench-rollout", "bench-rollout-quick", "bench-scaling", "bench-scaling-quick", "bench-compare", "bench-plots", ], ], decision = "allow", justification = "Project targets: checks, the working stand without deleting data, bench profiles (bench/RUNBOOK.md).", match = ["make lint", "make test-isolated", "make bench-uploads", "make bench-reconcile-quick", "make failover-each STOP_MODE=kill"], not_match = ["make wipe", "make reconcile APPLY=1"], ) # make reconcile без APPLY — dry-run: ничего не меняет prefix_rule( pattern = ["make", "reconcile"], decision = "allow", justification = "Dry-run reconcile only reports discrepancies (exit 0 or 3).", match = ["make reconcile", "make reconcile STRATEGY=head DEEP=1"], ) # с APPLY=1 сверка удаляет объекты без строки и помечает потерянные # оригиналы в рабочей базе: спросить пользователя prefix_rule( pattern = ["make", "reconcile", "APPLY=1"], decision = "prompt", justification = "reconcile --apply deletes orphan objects and marks lost originals in the working stand: ask the user first.", match = ["make reconcile APPLY=1", "make reconcile APPLY=1 MAX_CHANGES=10"], ) prefix_rule( pattern = ["docker", ["ps", "info", "version", "inspect", "logs", "images", "events", "exec", "cp", "build", "tag", "run", "start", "unpause"]], decision = "allow", justification = "Inspecting and running own stand containers; deletion is covered by stricter rules above.", match = ["docker ps -a", "docker info", "docker logs -t vlad-bench-lb"], ) prefix_rule( pattern = ["docker", "compose"], decision = "allow", justification = "Compose of this project; down -v is prompted by the stricter rule above.", match = ["docker compose ps", "docker compose logs api"], ) prefix_rule( pattern = ["uv", ["run", "sync", "lock", "export"]], decision = "allow", justification = "Project environment from uv.lock; new dependencies still need the user's consent (AGENTS.md, section 2, item 11).", match = ["uv run pytest", "uv sync", "uv run python bench/reconcile.py --selftest"], ) prefix_rule( pattern = [["python3", "python"], ["scripts/lab4.py", "student-tests/stand.py", "tests/smoke.py", "tests/resilience.py", "scripts/check_contract.py"]], decision = "allow", justification = "Project scripts on the host Python (stdlib only).", match = ["python3 scripts/lab4.py s3-check", "python3 student-tests/stand.py isolated"], )