Backend Atomic Commit Skill
When to Use This Skill
Use this Skill in backend/Django repos (especially the Diversio monolith
backend) when you want:
/backend-atomic-commit:pre-commit – to actively fix the current code
(formatting, imports, type hints, logging, etc.) so that it matches:
- Local
AGENTS.md / CLAUDE.md rules.
.pre-commit-config.yaml expectations.
.security/ diff helpers (ruff and local imports).
- Monty’s backend taste.
/backend-atomic-commit:atomic-commit – to run the same checks plus:
- Enforce that the staged changes are atomic (one coherent change).
- Ensure all quality gates are green (no shortcuts).
- Propose a strict, ticket-prefixed commit message without any Claude or
AI signatures.
Example Prompts
- “Run
/backend-atomic-commit:pre-commit on this repo and actively fix all
files in git status so they obey backend AGENTS.md, .pre-commit-config.yaml,
.security/* helpers, and Monty’s taste (no local imports, strong typing,
structured logging). Then summarize what you changed and what’s still
[BLOCKING].”
- “Use
/backend-atomic-commit:atomic-commit to prepare an atomic commit for
the staged changes in backend/. Enforce all pre-commit hooks and
.security scripts, run Ruff, ty, Django checks, and relevant pytest
subsets, then propose a ticket-prefixed commit message with no AI
signature and clearly mark any [BLOCKING] issues.”
- “Treat my current backend changes as one logical bugfix and run
/backend-atomic-commit:pre-commit in a strict mode: eliminate local
imports, fix type hints (no Any, no string-based annotations), clean up
debug statements, and ensure Ruff, .security/local_imports_pr_diff.sh,
ty, and Django checks are happy."
- “Before I commit these
optimo_* changes, run
/backend-atomic-commit:atomic-commit --auto to:
- enforce structured logging with
TypedDict payloads,
- ensure no PII in logs,
- verify tests and
.security/* scripts,
and then tell me whether the commit is ready and what the commit message
should be.”
If you’re not in a backend repo (no manage.py, no backend-style AGENTS.md,
no .pre-commit-config.yaml), this Skill should say so explicitly and fall
back to a lighter “generic Python pre-commit” behavior.
Modes
This Skill behaves differently based on how it is invoked:
pre-commit mode – invoked via /backend-atomic-commit:pre-commit:
- Actively applies changes to make the working tree and staged files conform
to repo standards and pre-commit requirements.
- Runs all relevant static checks and auto-fixers.
- Does not propose or drive a commit.
atomic-commit mode – invoked via /backend-atomic-commit:atomic-commit:
- Runs everything from
pre-commit mode.
- Enforces atomicity of staged changes.
- Requires all gates to be green.
- Proposes a commit message, but must never add AI signatures or plugin
branding to the message.
The command markdown sets the mode. You should detect the mode from the command
description/context and adjust behavior accordingly.
Core Priorities
Emulate Monty’s backend engineering and review taste, tuned for pre-commit:
- Correctness & invariants – multi-tenancy, time dimensions, and security
constraints come first.
- Safety & reviewability – avoid dangerous schema changes, large risky
try/except blocks, hidden PII, or untyped payloads.
- Atomic commits – one commit should represent one coherent change; split
unrelated work.
- Local repo rules first – treat
AGENTS.md and CLAUDE.md as the source
of truth when present; this Skill is a default baseline.
- Tooling alignment – use uv wrappers,
.security/* helpers, and
.pre-commit-config.yaml hooks as documented, not ad-hoc commands.
- Type and structure – prefer precise type hints,
TypedDict/dataclasses,
and structured logging over untyped dicts and log soup.
- No AI signatures in commits – commit messages must look like a human
wrote them; this Skill should be invisible from
git log.
Always prioritize [BLOCKING] issues over style and nits.
Environment & Context Gathering
When this Skill runs, you should first gather context using Bash, Read,
Glob, and Grep:
- Git context:
git status --porcelain
git branch --show-current
git diff --cached --stat
git diff --cached --name-only
git log --oneline -10
- Repo configuration:
- Read
AGENTS.md and CLAUDE.md (if present) for repo-specific rules.
- Detect
.pre-commit-config.yaml.
- Detect
.security/ scripts, especially:
./.security/ruff_pr_diff.sh
./.security/local_imports_pr_diff.sh
- Detect
manage.py / Django project layout.
- Tool availability:
uv and .bin/ wrappers:
.bin/ruff, .bin/ty, .bin/django, .bin/pytest.
- Fallback to
uv run or plain python / pytest / ruff where necessary.
If the repo clearly isn’t the Diversio backend / Django4Lyfe style, say so and
adjust expectations (but you can still run generic Python pre-commit checks).
Checks in Both Modes
In both pre-commit and atomic-commit modes, follow this pipeline:
Scope changed files
- Start from files reported by
git status and git diff --cached:
- Distinguish staged vs unstaged vs untracked.
- Categorize by type:
- Python (src vs tests;
optimo_*, dashboardapp, survey, etc.).
- Templates (Django HTML).
- Config (YAML, JSON,
.pre-commit-config.yaml, pyproject.toml,
requirements*.txt).
- Docs/markdown.
Static formatting/linting
- Ruff:
- Run
./.security/ruff_pr_diff.sh if present.
- Run
.bin/ruff check --fix on changed Python files.
- Run
.bin/ruff format on those files.
- IMPORTANT: For any file you touch, you must resolve ALL ruff
errors in that file—not just the ones you introduced. CI runs ruff on
modified files, so pre-existing errors in touched files will cause CI
failures. Do not dismiss errors as "pre-existing" if the file is in
your diff.
- Templates:
- Run
djlint-reformat-django and djlint-django on changed templates
when configured in .pre-commit-config.yaml.
- Generic pre-commit hooks:
- Respect hook definitions in
.pre-commit-config.yaml; run
pre-commit run on relevant files when possible.
Backend-specific .security gates
- Run
.security scripts where present:
./.security/ruff_pr_diff.sh – Ruff on changed files vs base branch.
./.security/local_imports_pr_diff.sh – check for local imports.
- Treat failures as at least
[SHOULD_FIX] and usually [BLOCKING] for
atomic-commit.
Type checking with ty
Django system checks
- Run
.bin/django check or equivalent:
uv run python manage.py check --fail-level WARNING.
- For risky changes (models, migrations, core logic), run targeted
pytest subsets based on changed apps:
- Example:
dashboardapp/ changes → pytest dashboardapp/tests/.
- If tests cannot be run (e.g. env not set up), say so explicitly and treat
“tests not run” as at least
[SHOULD_FIX] and often [BLOCKING] for
atomic-commit.
Interaction with pre-commit hooks
- If
.pre-commit-config.yaml exists:
- Expect hooks to run and modify files (ruff, djlint, interrogate,
custom scripts).
- After hooks run, re-check
git status and restage modified files as
appropriate.
- If a hook executable is missing (e.g.
check_prepare_commit_msg_hook.py
referenced but not present), do not crash:
- Record a
[SHOULD_FIX] issue stating which hook is missing and why it
matters.
Monty Backend Taste – Auto-Fix Rules
When running in pre-commit mode, you are allowed and expected to actively
edit code to align with Monty’s backend taste where it is clearly safe. In
atomic-commit mode, you may still fix things, but be more conservative and
always summarize edits.
Imports & local imports
- Enforce no local imports at any cost:
- Avoid
from myapp.models import MyModel inside functions or methods just
to dodge cyclic imports.
- Use
.security/local_imports_pr_diff.sh as the first line of defense.
- Prefer:
- Module-level imports.
- Refactoring helpers to avoid cycles.
- Type-only imports (e.g.
from __future__ import annotations) when needed.
- If moving imports risks true cyclic import problems:
- Suggest structural changes (splitting modules, relocating helpers).
- Never silently reintroduce local imports; call out unresolved cycles as
[SHOULD_FIX].
Logging (especially in optimo_* apps)
- Enforce structured logging:
- Prefer structured payloads over single log strings:
- Good:
logger.info("optimo_event", extra={"company_uuid": str(company.uuid)}).
- Avoid:
logger.info("Company %s did %s", company.name, something).
- In
optimo_* apps, treat unstructured logging as at least [SHOULD_FIX].
- PII in logs:
- Never log PII such as
assignment.employee.email; this is enforced by
pre-commit hooks already, but you should also conceptually check.
- Prefer logging UUIDs/IDs instead of emails or names.
- Log levels:
- Avoid
logger.exception for expected error paths; use error or warning
with explicit messages.
Try/except and error handling
- Avoid large, catch-all
try/except blocks:
- Shrink the
try body to only the lines that can raise.
- Replace bare
except: or except Exception: with specific exceptions
whenever possible.
- Never swallow exceptions silently:
- Always log or re-raise; returning silently on failure is
[BLOCKING] for
behaviorally important code.
- Avoid overusing
getattr/hasattr as a crutch:
- Only use
hasattr() when truly needed (e.g. cross-version adapters) and
document why.
Types, hints, and data structures
- Be pedantic about type hints:
- Avoid
Any as much as possible; prefer precise types and generics.
- No string-based type hints like
"OptimoRiskQuestionBank"; use real types
and proper imports.
- Add missing annotations on new/changed functions, especially in
optimo_*, dashboardapp, and other core apps.
- Prefer structured data:
- Replace
Dict[str, Any] or ad-hoc dict payloads with TypedDict or
dataclasses when the shape is stable and local.
- Avoid shape-changing dicts where keys appear/disappear across branches;
suggest a typed structure instead.
Tests and fixtures
- Avoid repeating fixtures or introducing fixture collisions:
- Prefer existing rich fixtures described in
AGENTS.md (e.g. responses
in survey tests, company/survey fixtures that respect multi-tenant
relationships).
- Do not introduce new Django
TestCase classes in optimo_* apps; use
pytest + fixtures.
- Watch for multi-tenant fixture mismatches (e.g. survey from one company,
user from another); highlight these as
[BLOCKING] when they affect
correctness.
- When touching tests:
- Prefer pytest fixtures and helper factories.
- Avoid local imports inside tests; use module-level imports.
ORM and query patterns
- Use reverse relations where it reduces imports and improves clarity:
- Prefer
company.surveys.all() to Survey.objects.filter(company=company)
when it avoids extra imports and is idiomatic.
- Watch for N+1 queries in obvious loops:
- Flag them as
[SHOULD_FIX] for hot paths or performance-sensitive code.
Commented / dead code and debug artifacts
- Remove obvious debug leftovers:
print(...), pdb.set_trace(), ipdb.set_trace(), breakpoint() in
non-test code.
- Remove clearly obsolete commented-out blocks:
- Old versions of code commented around a new implementation.
- For ambiguous commented sections:
- Flag them as
[SHOULD_FIX] and suggest either deleting them or moving
rationale into docs.
TODO / FIXME without ticket IDs:
- Suggest converting to ticket-tagged comments (e.g.
TODO(GH-123): ... or
TODO(27pfu0): ...) or moving the note into ClickUp.
String / formatting style
- Migrate to f-strings where it improves clarity:
- Replace old
% formatting or .format() with f-strings when not blocked
by translation/i18n constraints.
- Avoid giant f-strings with logic:
- Suggest splitting into intermediate variables when readability suffers.
Security & secrets
- Detect obvious secrets checked into code or fixtures:
- Hardcoded tokens, passwords, API keys.
- Flag as
[BLOCKING] and suggest using environment variables and 1Password.
- Avoid staging obvious secret-heavy files:
.env, google_creds.json, google_drive_creds.json, etc.
- Recommend un-staging and
.gitignore updates where appropriate.
Migrations and schema changes
- Do not change migration behavior automatically; instead:
- Detect destructive schema changes (dropping fields/tables) combined with
code changes that still expect those fields:
- Mark as
[BLOCKING] and recommend a two-step rollout:
- PR 1: remove usage in code, keep schema.
- PR 2: drop the field/table once code is clean.
- Detect new non-nullable fields with defaults on large/hot tables:
- Mark as
[SHOULD_FIX] or [BLOCKING] depending on risk.
- Suggest the safer pattern:
- Add nullable field with no default.
- Backfill in batches.
- Then add default for new rows only.
- Detect volatile defaults (UUIDs, timestamps) used in migrations:
- Warn against backfilling large tables inside a single atomic migration;
recommend batched or non-atomic backfills.
Critical backend patterns from AGENTS.md
- Watch for new instances of patterns explicitly banned in backend
AGENTS.md:
- Django Ninja
Query() module-level constants that break parameter
resolution (e.g. Q_INCLUDE_INACTIVE = Query(False, ...)).
- Legacy survey models like
OptimoEmployeeSurvey or employee_survey.
- Any other CRITICAL warnings spelled out in that file.
- Treat any new usage of these patterns as
[BLOCKING].
Atomic-Commit Mode – Extra Strictness
In atomic-commit mode (invoked via /backend-atomic-commit:atomic-commit),
you must be very strict:
Atomicity of staged changes
- From
git diff --cached --name-only, determine if staged changes belong
to one coherent change:
- Example of non-atomic:
- Refactor in
survey/ plus an unrelated optimo bugfix and docs tweak.
- Emit:
[BLOCKING] if the staged set is clearly multiple logical changes.
[SHOULD_FIX] for minor opportunistic cleanups that could be split.
- You may suggest a split (e.g. “extract the optimo fix into a separate
commit”) but must not label a non-atomic set as “ready”.
All gates must be green
- The commit is not ready if any of these fail:
./.security/ruff_pr_diff.sh
./.security/local_imports_pr_diff.sh
.bin/ruff check / ruff format
.bin/ty check <staged_python_files> (scoped to modified files only)
.bin/django check / manage.py check
- Relevant
pytest subsets for risky changes
- Pre-commit hooks defined in
.pre-commit-config.yaml
- In
--auto style usage, you may skip conversational confirmation, but
you must not relax these gates.
- If tests or checks are skipped for any reason, clearly state that and
treat it as at least
[SHOULD_FIX] and usually [BLOCKING].
Commit message generation (no AI signature)
- Extract ticket ID from branch name using repo conventions:
- For the Diversio backend:
- Branch name:
clickup_<ticket_id>_...
- Commit format per
AGENTS.md: <ticket_id>: Description.
- If commit message hooks like
commit_msg_hook.py exist:
- Avoid double-prefixing ticket IDs.
- If hooks and docs disagree, call that out as
[SHOULD_FIX] and follow
the documented AGENTS.md convention for suggestions.
- Generate a concise, human-looking subject line:
- Summarize what changed and why in one line.
- Do not mention Claude, AI, this Skill, or plugin names.
- Do not add any footer or signature:
- No “via Claude Code”.
- No “Generated by backend-atomic-commit”.
- Commit messages must look like a human wrote them.
- Final preview and verdict
Your atomic-commit output should include:
- A short summary of what was checked.
Checks run – listing each gate and its status.
What’s aligned – strengths and good patterns in the staged changes.
Needs changes – bullets with [BLOCKING], [SHOULD_FIX], [NIT].
Proposed commit – suggested commit message and list of files.
- An explicit verdict:
- “✅ Commit ready” only if there are no
[BLOCKING] items.
- Otherwise:
- “❌ Not ready to commit” with concrete next steps.
You should never encourage the user to run git commit as-is if any
[BLOCKING] issues remain.
Pre-Commit Mode – Fixing Without Committing
In pre-commit mode (invoked via /backend-atomic-commit:pre-commit):
- You may aggressively auto-fix:
- Formatting, linting, local imports, obvious type hints, logging patterns,
removal of debug code, and consistent fixtures.
- You must:
- Run the same gates described above (Ruff,
.security/*, ty, Django
checks, tests as appropriate).
- Re-run or re-stage files modified by tools or hooks.
- You do not propose a commit or check atomicity.
- Your output should focus on:
Fixes applied – concrete edits you made.
Remaining issues – with severity tags.
Checks run – which gates passed/failed.
This mode is the “make my working tree clean and standards-compliant” helper
before running an atomic commit.
Severity Tags & Output Shape
Always structure findings using severity tags and sections:
[BLOCKING] – must be fixed before a commit is considered ready:
- Failing
.security scripts or pre-commit hooks.
- New banned patterns from
AGENTS.md (e.g., Ninja Query constants, legacy
survey models).
- Obvious multi-tenant or security regressions.
- Non-atomic staged changes in
atomic-commit mode.
[SHOULD_FIX] – important, strongly recommended changes:
- Style/structure that harms readability or maintainability.
- Missing type hints where types are clear.
- Ambiguous commented code or TODOs without tickets.
- Missing tests for non-trivial new behavior.
[NIT] – minor cleanups:
- Docstring tone/punctuation.
- Minor naming and formatting nits not covered by Ruff.
Output shape for both modes:
- 1–3 sentence summary of what was checked.
- Sections (when appropriate):
What’s aligned
Needs changes
Checks run
Proposed commit (only in atomic-commit mode)
Be direct, specific, and actionable in each bullet, pointing to file/area and
suggesting concrete corrections. Never hide behind vague "consider improving"
phrases when you can be precise.
Compatibility Notes
This skill is designed to work with both Claude Code and OpenAI Codex.
For Codex users:
- Install via skill-installer with
--repo DiversioTeam/agent-skills-marketplace --path plugins/backend-atomic-commit/skills/backend-atomic-commit.
- Use
$skill backend-atomic-commit to invoke.
For Claude Code users:
- Install via
/plugin install backend-atomic-commit@diversiotech.
- Use
/backend-atomic-commit:atomic-commit or /backend-atomic-commit:pre-commit to invoke.
1---
2name: backend-atomic-commit
3description: >
4 Pedantic backend pre-commit and atomic commit Skill for Django/Optimo-style
5 repos. Enforces local AGENTS.md / CLAUDE.md, pre-commit hooks, .security/*
6 helpers, and Monty’s backend engineering taste – with no AI signatures in
7 commit messages.
8allowed-tools:
9 - Bash
10 - Read
11 - Edit
12 - Glob
13 - Grep
14metadata:
15 source: https://skillmd.com/skills/aibot88/backend-atomic-commit
16---
17
18# Backend Atomic Commit Skill
19
20## When to Use This Skill
21
22Use this Skill in backend/Django repos (especially the Diversio monolith
23backend) when you want:
24
25- `/backend-atomic-commit:pre-commit` – to **actively fix** the current code
26 (formatting, imports, type hints, logging, etc.) so that it matches:
27 - Local `AGENTS.md` / `CLAUDE.md` rules.
28 - `.pre-commit-config.yaml` expectations.
29 - `.security/` diff helpers (ruff and local imports).
30 - Monty’s backend taste.
31- `/backend-atomic-commit:atomic-commit` – to run the same checks plus:
32 - Enforce that the **staged changes are atomic** (one coherent change).
33 - Ensure all quality gates are green (no shortcuts).
34 - Propose a strict, ticket-prefixed commit message **without** any Claude or
35 AI signatures.
36
37## Example Prompts
38
39- “Run `/backend-atomic-commit:pre-commit` on this repo and actively fix all
40 files in `git status` so they obey backend `AGENTS.md`, `.pre-commit-config.yaml`,
41 `.security/*` helpers, and Monty’s taste (no local imports, strong typing,
42 structured logging). Then summarize what you changed and what’s still
43 `[BLOCKING]`.”
44- “Use `/backend-atomic-commit:atomic-commit` to prepare an atomic commit for
45 the staged changes in `backend/`. Enforce all pre-commit hooks and
46 `.security` scripts, run Ruff, ty, Django checks, and relevant pytest
47 subsets, then propose a ticket-prefixed commit message with **no AI
48 signature** and clearly mark any `[BLOCKING]` issues.”
49- “Treat my current backend changes as one logical bugfix and run
50 `/backend-atomic-commit:pre-commit` in a strict mode: eliminate local
51 imports, fix type hints (no `Any`, no string-based annotations), clean up
52 debug statements, and ensure Ruff, `.security/local_imports_pr_diff.sh`,
53 ty, and Django checks are happy."
54- “Before I commit these `optimo_*` changes, run
55 `/backend-atomic-commit:atomic-commit --auto` to:
56 - enforce structured logging with `TypedDict` payloads,
57 - ensure no PII in logs,
58 - verify tests and `.security/*` scripts,
59 and then tell me whether the commit is ready and what the commit message
60 should be.”
61
62If you’re not in a backend repo (no `manage.py`, no backend-style `AGENTS.md`,
63no `.pre-commit-config.yaml`), this Skill should say so explicitly and fall
64back to a lighter “generic Python pre-commit” behavior.
65
66## Modes
67
68This Skill behaves differently based on how it is invoked:
69
70- `pre-commit` mode – invoked via `/backend-atomic-commit:pre-commit`:
71 - Actively applies changes to make the working tree and staged files conform
72 to repo standards and pre-commit requirements.
73 - Runs all relevant static checks and auto-fixers.
74 - Does **not** propose or drive a commit.
75- `atomic-commit` mode – invoked via `/backend-atomic-commit:atomic-commit`:
76 - Runs everything from `pre-commit` mode.
77 - Enforces atomicity of staged changes.
78 - Requires all gates to be green.
79 - Proposes a commit message, but **must never** add AI signatures or plugin
80 branding to the message.
81
82The command markdown sets the mode. You should detect the mode from the command
83description/context and adjust behavior accordingly.
84
85## Core Priorities
86
87Emulate Monty’s backend engineering and review taste, tuned for pre-commit:
88
891. **Correctness & invariants** – multi-tenancy, time dimensions, and security
90 constraints come first.
912. **Safety & reviewability** – avoid dangerous schema changes, large risky
92 try/except blocks, hidden PII, or untyped payloads.
933. **Atomic commits** – one commit should represent one coherent change; split
94 unrelated work.
954. **Local repo rules first** – treat `AGENTS.md` and `CLAUDE.md` as the source
96 of truth when present; this Skill is a default baseline.
975. **Tooling alignment** – use uv wrappers, `.security/*` helpers, and
98 `.pre-commit-config.yaml` hooks as documented, not ad-hoc commands.
996. **Type and structure** – prefer precise type hints, `TypedDict`/dataclasses,
100 and structured logging over untyped dicts and log soup.
1017. **No AI signatures in commits** – commit messages must look like a human
102 wrote them; this Skill should be invisible from `git log`.
103
104Always prioritize `[BLOCKING]` issues over style and nits.
105
106## Environment & Context Gathering
107
108When this Skill runs, you should first gather context using `Bash`, `Read`,
109`Glob`, and `Grep`:
110
111- Git context:
112 - `git status --porcelain`
113 - `git branch --show-current`
114 - `git diff --cached --stat`
115 - `git diff --cached --name-only`
116 - `git log --oneline -10`
117- Repo configuration:
118 - Read `AGENTS.md` and `CLAUDE.md` (if present) for repo-specific rules.
119 - Detect `.pre-commit-config.yaml`.
120 - Detect `.security/` scripts, especially:
121 - `./.security/ruff_pr_diff.sh`
122 - `./.security/local_imports_pr_diff.sh`
123 - Detect `manage.py` / Django project layout.
124- Tool availability:
125 - `uv` and `.bin/` wrappers:
126 - `.bin/ruff`, `.bin/ty`, `.bin/django`, `.bin/pytest`.
127 - Fallback to `uv run` or plain `python` / `pytest` / `ruff` where necessary.
128
129If the repo clearly isn’t the Diversio backend / Django4Lyfe style, say so and
130adjust expectations (but you can still run generic Python pre-commit checks).
131
132## Checks in Both Modes
133
134In **both** `pre-commit` and `atomic-commit` modes, follow this pipeline:
135
1361. **Scope changed files**
137 - Start from files reported by `git status` and `git diff --cached`:
138 - Distinguish staged vs unstaged vs untracked.
139 - Categorize by type:
140 - Python (src vs tests; `optimo_*`, `dashboardapp`, `survey`, etc.).
141 - Templates (Django HTML).
142 - Config (YAML, JSON, `.pre-commit-config.yaml`, `pyproject.toml`,
143 `requirements*.txt`).
144 - Docs/markdown.
145
1462. **Static formatting/linting**
147 - Ruff:
148 - Run `./.security/ruff_pr_diff.sh` if present.
149 - Run `.bin/ruff check --fix` on changed Python files.
150 - Run `.bin/ruff format` on those files.
151 - **IMPORTANT**: For any file you touch, you must resolve **ALL** ruff
152 errors in that file—not just the ones you introduced. CI runs ruff on
153 modified files, so pre-existing errors in touched files will cause CI
154 failures. Do **not** dismiss errors as "pre-existing" if the file is in
155 your diff.
156 - Templates:
157 - Run `djlint-reformat-django` and `djlint-django` on changed templates
158 when configured in `.pre-commit-config.yaml`.
159 - Generic pre-commit hooks:
160 - Respect hook definitions in `.pre-commit-config.yaml`; run
161 `pre-commit run` on relevant files when possible.
162
1633. **Backend-specific .security gates**
164 - Run `.security` scripts where present:
165 - `./.security/ruff_pr_diff.sh` – Ruff on changed files vs base branch.
166 - `./.security/local_imports_pr_diff.sh` – check for local imports.
167 - Treat failures as at least `[SHOULD_FIX]` and usually `[BLOCKING]` for
168 `atomic-commit`.
169
1704. **Type checking with ty**
171 - Run `ty` on **modified Python files only** to catch type errors before CI:
172 ```bash
173 # For staged files (atomic-commit mode):
174 .bin/ty check $(git diff --cached --name-only --diff-filter=ACMR | grep '\.py$')
175
176 # For all modified files (pre-commit mode):
177 .bin/ty check $(git diff --name-only --diff-filter=ACMR | grep '\.py$')
178 ```
179 - This scoped approach avoids triggering baseline errors in **unmodified**
180 files while matching CircleCI's `ty` check behavior.
181 - **IMPORTANT**: For any file you touch, you must resolve **ALL** `ty` errors
182 in that file—not just the ones you introduced. CI runs `ty` on modified
183 files, so pre-existing errors in touched files will cause CI failures.
184 Do **not** dismiss errors as "pre-existing" if the file is in your diff.
185 - Common pitfall: Fixing ruff ARG002 (unused argument) by prefixing with `_`
186 may satisfy ruff but break `ty` if the method signature must match a parent
187 class (e.g., Django admin methods). Always run both checks together.
188 - Treat **any** `ty` errors in modified files as `[BLOCKING]` for
189 `atomic-commit` mode or `[SHOULD_FIX]` for `pre-commit` mode.
190
1915. **Django system checks**
192 - Run `.bin/django check` or equivalent:
193 - `uv run python manage.py check --fail-level WARNING`.
194 - For risky changes (models, migrations, core logic), run **targeted**
195 `pytest` subsets based on changed apps:
196 - Example: `dashboardapp/` changes → `pytest dashboardapp/tests/`.
197 - If tests cannot be run (e.g. env not set up), say so explicitly and treat
198 “tests not run” as at least `[SHOULD_FIX]` and often `[BLOCKING]` for
199 `atomic-commit`.
200
2016. **Interaction with pre-commit hooks**
202 - If `.pre-commit-config.yaml` exists:
203 - Expect hooks to run and modify files (ruff, djlint, interrogate,
204 custom scripts).
205 - After hooks run, re-check `git status` and restage modified files as
206 appropriate.
207 - If a hook executable is missing (e.g. `check_prepare_commit_msg_hook.py`
208 referenced but not present), do **not** crash:
209 - Record a `[SHOULD_FIX]` issue stating which hook is missing and why it
210 matters.
211
212## Monty Backend Taste – Auto-Fix Rules
213
214When running in `pre-commit` mode, you are allowed and expected to **actively
215edit code** to align with Monty’s backend taste where it is clearly safe. In
216`atomic-commit` mode, you may still fix things, but be more conservative and
217always summarize edits.
218
219### Imports & local imports
220
221- Enforce **no local imports at any cost**:
222 - Avoid `from myapp.models import MyModel` inside functions or methods just
223 to dodge cyclic imports.
224 - Use `.security/local_imports_pr_diff.sh` as the first line of defense.
225 - Prefer:
226 - Module-level imports.
227 - Refactoring helpers to avoid cycles.
228 - Type-only imports (e.g. `from __future__ import annotations`) when needed.
229 - If moving imports risks true cyclic import problems:
230 - Suggest structural changes (splitting modules, relocating helpers).
231 - Never silently reintroduce local imports; call out unresolved cycles as
232 `[SHOULD_FIX]`.
233
234### Logging (especially in optimo_* apps)
235
236- Enforce structured logging:
237 - Prefer structured payloads over single log strings:
238 - Good: `logger.info("optimo_event", extra={"company_uuid": str(company.uuid)})`.
239 - Avoid: `logger.info("Company %s did %s", company.name, something)`.
240 - In `optimo_*` apps, treat unstructured logging as at least `[SHOULD_FIX]`.
241- PII in logs:
242 - Never log PII such as `assignment.employee.email`; this is enforced by
243 pre-commit hooks already, but you should also conceptually check.
244 - Prefer logging UUIDs/IDs instead of emails or names.
245- Log levels:
246 - Avoid `logger.exception` for expected error paths; use `error` or `warning`
247 with explicit messages.
248
249### Try/except and error handling
250
251- Avoid large, catch-all `try/except` blocks:
252 - Shrink the `try` body to only the lines that can raise.
253 - Replace bare `except:` or `except Exception:` with specific exceptions
254 whenever possible.
255- Never swallow exceptions silently:
256 - Always log or re-raise; returning silently on failure is `[BLOCKING]` for
257 behaviorally important code.
258- Avoid overusing `getattr`/`hasattr` as a crutch:
259 - Only use `hasattr()` when truly needed (e.g. cross-version adapters) and
260 document why.
261
262### Types, hints, and data structures
263
264- Be pedantic about type hints:
265 - Avoid `Any` as much as possible; prefer precise types and generics.
266 - No string-based type hints like `"OptimoRiskQuestionBank"`; use real types
267 and proper imports.
268 - Add missing annotations on new/changed functions, especially in
269 `optimo_*`, `dashboardapp`, and other core apps.
270- Prefer structured data:
271 - Replace `Dict[str, Any]` or ad-hoc dict payloads with `TypedDict` or
272 dataclasses when the shape is stable and local.
273 - Avoid shape-changing dicts where keys appear/disappear across branches;
274 suggest a typed structure instead.
275
276### Tests and fixtures
277
278- Avoid repeating fixtures or introducing fixture collisions:
279 - Prefer existing rich fixtures described in `AGENTS.md` (e.g. `responses`
280 in survey tests, company/survey fixtures that respect multi-tenant
281 relationships).
282 - Do not introduce new Django `TestCase` classes in `optimo_*` apps; use
283 pytest + fixtures.
284 - Watch for multi-tenant fixture mismatches (e.g. survey from one company,
285 user from another); highlight these as `[BLOCKING]` when they affect
286 correctness.
287- When touching tests:
288 - Prefer pytest fixtures and helper factories.
289 - Avoid local imports inside tests; use module-level imports.
290
291### ORM and query patterns
292
293- Use reverse relations where it reduces imports and improves clarity:
294 - Prefer `company.surveys.all()` to `Survey.objects.filter(company=company)`
295 when it avoids extra imports and is idiomatic.
296- Watch for N+1 queries in obvious loops:
297 - Flag them as `[SHOULD_FIX]` for hot paths or performance-sensitive code.
298
299### Commented / dead code and debug artifacts
300
301- Remove obvious debug leftovers:
302 - `print(...)`, `pdb.set_trace()`, `ipdb.set_trace()`, `breakpoint()` in
303 non-test code.
304- Remove clearly obsolete commented-out blocks:
305 - Old versions of code commented around a new implementation.
306- For ambiguous commented sections:
307 - Flag them as `[SHOULD_FIX]` and suggest either deleting them or moving
308 rationale into docs.
309- `TODO` / `FIXME` without ticket IDs:
310 - Suggest converting to ticket-tagged comments (e.g. `TODO(GH-123): ...` or
311 `TODO(27pfu0): ...`) or moving the note into ClickUp.
312
313### String / formatting style
314
315- Migrate to f-strings where it improves clarity:
316 - Replace old `%` formatting or `.format()` with f-strings when not blocked
317 by translation/i18n constraints.
318- Avoid giant f-strings with logic:
319 - Suggest splitting into intermediate variables when readability suffers.
320
321### Security & secrets
322
323- Detect obvious secrets checked into code or fixtures:
324 - Hardcoded tokens, passwords, API keys.
325 - Flag as `[BLOCKING]` and suggest using environment variables and 1Password.
326- Avoid staging obvious secret-heavy files:
327 - `.env`, `google_creds.json`, `google_drive_creds.json`, etc.
328 - Recommend un-staging and `.gitignore` updates where appropriate.
329
330### Migrations and schema changes
331
332- Do **not** change migration behavior automatically; instead:
333 - Detect destructive schema changes (dropping fields/tables) combined with
334 code changes that still expect those fields:
335 - Mark as `[BLOCKING]` and recommend a two-step rollout:
336 - PR 1: remove usage in code, keep schema.
337 - PR 2: drop the field/table once code is clean.
338 - Detect new non-nullable fields with defaults on large/hot tables:
339 - Mark as `[SHOULD_FIX]` or `[BLOCKING]` depending on risk.
340 - Suggest the safer pattern:
341 - Add nullable field with no default.
342 - Backfill in batches.
343 - Then add default for new rows only.
344 - Detect volatile defaults (UUIDs, timestamps) used in migrations:
345 - Warn against backfilling large tables inside a single atomic migration;
346 recommend batched or non-atomic backfills.
347
348### Critical backend patterns from AGENTS.md
349
350- Watch for new instances of patterns explicitly banned in backend `AGENTS.md`:
351 - Django Ninja `Query()` module-level constants that break parameter
352 resolution (e.g. `Q_INCLUDE_INACTIVE = Query(False, ...)`).
353 - Legacy survey models like `OptimoEmployeeSurvey` or `employee_survey`.
354 - Any other CRITICAL warnings spelled out in that file.
355- Treat any new usage of these patterns as `[BLOCKING]`.
356
357## Atomic-Commit Mode – Extra Strictness
358
359In `atomic-commit` mode (invoked via `/backend-atomic-commit:atomic-commit`),
360you must be **very strict**:
361
3621. **Atomicity of staged changes**
363 - From `git diff --cached --name-only`, determine if staged changes belong
364 to one coherent change:
365 - Example of non-atomic:
366 - Refactor in `survey/` plus an unrelated optimo bugfix and docs tweak.
367 - Emit:
368 - `[BLOCKING]` if the staged set is clearly multiple logical changes.
369 - `[SHOULD_FIX]` for minor opportunistic cleanups that could be split.
370 - You may suggest a split (e.g. “extract the optimo fix into a separate
371 commit”) but must not label a non-atomic set as “ready”.
372
3732. **All gates must be green**
374 - The commit is **not** ready if any of these fail:
375 - `./.security/ruff_pr_diff.sh`
376 - `./.security/local_imports_pr_diff.sh`
377 - `.bin/ruff check` / `ruff format`
378 - `.bin/ty check <staged_python_files>` (scoped to modified files only)
379 - `.bin/django check` / `manage.py check`
380 - Relevant `pytest` subsets for risky changes
381 - Pre-commit hooks defined in `.pre-commit-config.yaml`
382 - In `--auto` style usage, you may skip conversational confirmation, but
383 you **must not** relax these gates.
384 - If tests or checks are skipped for any reason, clearly state that and
385 treat it as at least `[SHOULD_FIX]` and usually `[BLOCKING]`.
386
3873. **Commit message generation (no AI signature)**
388
389- Extract ticket ID from branch name using repo conventions:
390 - For the Diversio backend:
391 - Branch name: `clickup_<ticket_id>_...`
392 - Commit format per `AGENTS.md`: `<ticket_id>: Description`.
393 - If commit message hooks like `commit_msg_hook.py` exist:
394 - Avoid double-prefixing ticket IDs.
395 - If hooks and docs disagree, call that out as `[SHOULD_FIX]` and follow
396 the documented `AGENTS.md` convention for suggestions.
397- Generate a concise, human-looking subject line:
398 - Summarize what changed and why in one line.
399 - Do **not** mention Claude, AI, this Skill, or plugin names.
400- Do **not** add any footer or signature:
401 - No “via Claude Code”.
402 - No “Generated by backend-atomic-commit”.
403 - Commit messages must look like a human wrote them.
404
4054. **Final preview and verdict**
406
407Your `atomic-commit` output should include:
408
409- A short summary of what was checked.
410- `Checks run` – listing each gate and its status.
411- `What’s aligned` – strengths and good patterns in the staged changes.
412- `Needs changes` – bullets with `[BLOCKING]`, `[SHOULD_FIX]`, `[NIT]`.
413- `Proposed commit` – suggested commit message and list of files.
414- An explicit verdict:
415 - “✅ Commit ready” only if there are **no `[BLOCKING]` items**.
416 - Otherwise:
417 - “❌ Not ready to commit” with concrete next steps.
418
419You should **never** encourage the user to run `git commit` as-is if any
420`[BLOCKING]` issues remain.
421
422## Pre-Commit Mode – Fixing Without Committing
423
424In `pre-commit` mode (invoked via `/backend-atomic-commit:pre-commit`):
425
426- You may aggressively auto-fix:
427 - Formatting, linting, local imports, obvious type hints, logging patterns,
428 removal of debug code, and consistent fixtures.
429- You must:
430 - Run the same gates described above (Ruff, `.security/*`, ty, Django
431 checks, tests as appropriate).
432 - Re-run or re-stage files modified by tools or hooks.
433- You do **not** propose a commit or check atomicity.
434- Your output should focus on:
435 - `Fixes applied` – concrete edits you made.
436 - `Remaining issues` – with severity tags.
437 - `Checks run` – which gates passed/failed.
438
439This mode is the “make my working tree clean and standards-compliant” helper
440before running an atomic commit.
441
442## Severity Tags & Output Shape
443
444Always structure findings using severity tags and sections:
445
446- `[BLOCKING]` – must be fixed before a commit is considered ready:
447 - Failing `.security` scripts or pre-commit hooks.
448 - New banned patterns from `AGENTS.md` (e.g., Ninja Query constants, legacy
449 survey models).
450 - Obvious multi-tenant or security regressions.
451 - Non-atomic staged changes in `atomic-commit` mode.
452- `[SHOULD_FIX]` – important, strongly recommended changes:
453 - Style/structure that harms readability or maintainability.
454 - Missing type hints where types are clear.
455 - Ambiguous commented code or TODOs without tickets.
456 - Missing tests for non-trivial new behavior.
457- `[NIT]` – minor cleanups:
458 - Docstring tone/punctuation.
459 - Minor naming and formatting nits not covered by Ruff.
460
461Output shape for both modes:
462
463- 1–3 sentence summary of what was checked.
464- Sections (when appropriate):
465 - `What’s aligned`
466 - `Needs changes`
467 - `Checks run`
468 - `Proposed commit` (only in atomic-commit mode)
469
470Be direct, specific, and actionable in each bullet, pointing to file/area and
471suggesting concrete corrections. Never hide behind vague "consider improving"
472phrases when you can be precise.
473
474## Compatibility Notes
475
476This skill is designed to work with both **Claude Code** and **OpenAI Codex**.
477
478For Codex users:
479- Install via skill-installer with `--repo DiversioTeam/agent-skills-marketplace
480 --path plugins/backend-atomic-commit/skills/backend-atomic-commit`.
481- Use `$skill backend-atomic-commit` to invoke.
482
483For Claude Code users:
484- Install via `/plugin install backend-atomic-commit@diversiotech`.
485- Use `/backend-atomic-commit:atomic-commit` or `/backend-atomic-commit:pre-commit` to invoke.