Project rules from the brain's lessons — enforced before CI, with no AI at check time
brain_rulesConverts recorded lessons into deterministic, versioned diff rules that check edits and commits before code reaches CI, warning by default and blocking only after human approval.
Instructions
Turns lessons this brain recorded ("every new route must also be in PRIVATE_ROUTES", "a new *.test.ts must be listed in package.json", "this file is mixed CRLF/LF") into DETERMINISTIC diff checks, versioned in the repo as .klypix/rules.json, each citing the card it came from. Checked before the code reaches CI: brain_sync shows the rules for the files you declare; the edit hook (Claude Code; Codex gets the same) and an opt-in git pre-commit/pre-push hook report findings. Rules WARN by default; only a rule the human approved with --block stops an edit (Claude Code) or a commit, and a commit that skips a blocking rule (--no-verify) is recorded. Actions: "propose" routes each lesson to rule / instruction / note and drafts the checkable ones; "add" writes completed drafts as CANDIDATES (inert); "promote" and "retire" without approve open a human review prompt (MCP form or Windows dialog); never answer it for the human or repeat after decline unless asked. Other hosts can use the human's 8-character approval code (npx klypix-mcp rules code promote|retire <ids> — never shown to you, never guess it; a rule that blocks you is lifted only by the human); "check" runs the rules on the working tree, the staged change, or a range (include_candidates:true tests candidates before approval); "status" lists rules with fires / blocks / overrides / false alarms and retirement suggestions; "false_alarm" records that a finding was wrong (it does not lift the rule). Kinds: listed-in, forbid-pattern, preserve-eol, cloud-required. Checks are string/glob/regex work over the diff — milliseconds, offline; the project's own tests stay with its CI.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ids | No | promote / retire / false_alarm: rule ids. | |
| base | No | check: base ref for a range (merge-base with head is used). | |
| head | No | check: head ref for a range (default HEAD). | |
| mode | No | check: the working tree vs HEAD (default), the staged change, or a commit range (with base). | |
| block | No | promote: request blocking checks instead of warnings; the human reviews this severity in the approval prompt. With a terminal code, must match --block. | |
| files | No | check: just list the rules these files fall under (no diff). | |
| limit | No | propose: at most this many lessons (default 30). | |
| query | No | propose: only lessons containing this text. | |
| rules | No | add: complete rules — {id, kind, severity, why, fix, source:{card}, files:[globs], …kind fields}. listed-in: when "added-files"|"added-lines", registry:[files], needle (template: {file} {basename} {name} {relpath} {1}), pattern for added-lines (capture group 1 = the value to find). forbid-pattern: pattern. preserve-eol: files only. cloud-required: files, severity "advise". | |
| action | Yes | What to do. Default flow: propose → add → (human) promote; check any time; status for counts and suggestions. | |
| reason | No | retire / false_alarm: why, in one line. | |
| approve | No | promote / retire: omit to request human approval in a form or Windows dialog. Optional terminal fallback: the human's 8-character code. Never guess it. | |
| project | No | Absolute project root (the folder holding brain.klypix and .klypix/). Defaults to this session's project brain. | |
| include_candidates | No | check: also run candidate rules — to see what a rule would catch before the human approves it. |