Files
mtusi2026lab3/.codex/rules/messenger.rules
T

148 lines
7.0 KiB
Plaintext

# Правила команд 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 .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-lab3*, 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",
"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-scaling SERIES=a", "make failover-each STOP_MODE=kill"],
not_match = ["make wipe"],
)
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/analysis.py --selftest"],
)
prefix_rule(
pattern = [["python3", "python"], ["scripts/lab3.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/lab3.py instances", "python3 student-tests/stand.py isolated"],
)