feat: custom violation types + AGENTS.md developer guide #45

Merged
jason merged 1 commits from claude/musing-bell into master 2026-03-18 16:15:55 -05:00
Owner

Summary

  • Custom Violation Types — full CRUD system for user-defined violation types persisted in the database, appearing in the violation form dropdown alongside hardcoded types
  • AGENTS.md — authoritative developer/AI agent reference covering data integrity rules, coding standards, schema change checklist, and forward-thinking guidelines

Custom Violation Types (feat)

Database

  • New violation_types table auto-migrated on startup (db/database.js)
  • type_key auto-generated as custom_<slug> to prevent collisions with hardcoded violation keys
  • All write actions audited via existing audit() helper

API — server.js

  • GET /api/violation-types — all custom types
  • POST /api/violation-types — create; auto-generates unique type_key
  • PUT /api/violation-types/:id — edit name, category, chapter, description, points, fields
  • DELETE /api/violation-types/:id — blocked with 409 if any violations reference the type

ViolationTypeModal.jsx (new component)

  • Name, category (datalist autocomplete from existing categories + free-type for new groups), handbook chapter reference, description/reference text
  • Fixed vs. sliding point toggle (fixed = exact value, sliding = min/max range with supervisor discretion)
  • Context field checkboxes: Incident Time, Minutes Late, Amount, Location, Additional Details
  • Edit mode pre-populates all fields; delete button with usage guard

ViolationForm.jsx

  • Fetches custom types on mount; merged into dropdown via mergedGroups memo (custom types appear in their category group alongside hardcoded types)
  • resolveViolation() checks hardcoded registry first, then custom type map — recidivist escalation, repeat badge, tier warning, and point slider all work identically for custom types
  • + Add Type button above dropdown opens create modal
  • Edit Type button appears inline when a custom type is selected
  • Newly created type auto-selects after save; deleted type clears selection if active
  • Custom types marked with in dropdown and green Custom badge in context box

AGENTS.md (docs)

Covers: immutable scoring fields, soft-delete contract, audit log rules, tier system canonical source, migration pattern, schema change checklist, coding standards (backend + frontend), PDF generation, deployment notes, and explicit anti-patterns.

Test plan

  • Add a new fixed-point custom violation type; confirm it appears in dropdown under correct category
  • Add a sliding-point type; confirm point slider respects min/max
  • Submit a violation using a custom type; confirm it records correctly and PDF generates
  • Edit a custom type; confirm changes reflect immediately in dropdown
  • Attempt to delete a custom type that has violations; confirm 409 error message
  • Delete a custom type with no violations; confirm it disappears from dropdown
  • Add a custom type with a new category name; confirm new <optgroup> appears in dropdown

🤖 Generated with Claude Code

## Summary - **Custom Violation Types** — full CRUD system for user-defined violation types persisted in the database, appearing in the violation form dropdown alongside hardcoded types - **AGENTS.md** — authoritative developer/AI agent reference covering data integrity rules, coding standards, schema change checklist, and forward-thinking guidelines ## Custom Violation Types (feat) ### Database - New `violation_types` table auto-migrated on startup (`db/database.js`) - `type_key` auto-generated as `custom_<slug>` to prevent collisions with hardcoded violation keys - All write actions audited via existing `audit()` helper ### API — `server.js` - `GET /api/violation-types` — all custom types - `POST /api/violation-types` — create; auto-generates unique `type_key` - `PUT /api/violation-types/:id` — edit name, category, chapter, description, points, fields - `DELETE /api/violation-types/:id` — blocked with `409` if any violations reference the type ### `ViolationTypeModal.jsx` (new component) - Name, category (datalist autocomplete from existing categories + free-type for new groups), handbook chapter reference, description/reference text - Fixed vs. sliding point toggle (fixed = exact value, sliding = min/max range with supervisor discretion) - Context field checkboxes: Incident Time, Minutes Late, Amount, Location, Additional Details - Edit mode pre-populates all fields; delete button with usage guard ### `ViolationForm.jsx` - Fetches custom types on mount; merged into dropdown via `mergedGroups` memo (custom types appear in their category group alongside hardcoded types) - `resolveViolation()` checks hardcoded registry first, then custom type map — recidivist escalation, repeat badge, tier warning, and point slider all work identically for custom types - `+ Add Type` button above dropdown opens create modal - `Edit Type` button appears inline when a custom type is selected - Newly created type auto-selects after save; deleted type clears selection if active - Custom types marked with `✦` in dropdown and green **Custom** badge in context box ## AGENTS.md (docs) Covers: immutable scoring fields, soft-delete contract, audit log rules, tier system canonical source, migration pattern, schema change checklist, coding standards (backend + frontend), PDF generation, deployment notes, and explicit anti-patterns. ## Test plan - [ ] Add a new fixed-point custom violation type; confirm it appears in dropdown under correct category - [ ] Add a sliding-point type; confirm point slider respects min/max - [ ] Submit a violation using a custom type; confirm it records correctly and PDF generates - [ ] Edit a custom type; confirm changes reflect immediately in dropdown - [ ] Attempt to delete a custom type that has violations; confirm `409` error message - [ ] Delete a custom type with no violations; confirm it disappears from dropdown - [ ] Add a custom type with a new category name; confirm new `<optgroup>` appears in dropdown 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jason added 1 commit 2026-03-18 16:15:40 -05:00
Establishes AI agent and developer guidelines covering data integrity rules
(immutable scoring fields, soft-delete contract, audit log append-only),
tier system canonical source, migration patterns, coding standards for both
backend and frontend, schema change checklist, PDF generation notes, and
forward-thinking development constraints.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
jason merged commit 1c4494dd28 into master 2026-03-18 16:15:55 -05:00
jason changed title from docs: add AGENTS.md with coding, compliance, and architecture guidance to feat: custom violation types + AGENTS.md developer guide 2026-03-18 16:24:37 -05:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jason/cpas#45