[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-80994":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":13,"openIssues":14,"contributorsCount":14,"subscribersCount":14,"size":14,"stars1d":14,"stars7d":14,"stars30d":14,"stars90d":14,"forks30d":14,"starsTrendScore":14,"compositeScore":15,"rankGlobal":10,"rankLanguage":10,"license":16,"archived":17,"fork":17,"defaultBranch":18,"hasWiki":17,"hasPages":17,"topics":19,"createdAt":10,"pushedAt":10,"updatedAt":31,"readmeContent":32,"aiSummary":33,"trendingCount":14,"starSnapshotCount":14,"syncStatus":34,"lastSyncTime":35,"discoverSource":36},80994,"pinrule","jhaizhou-ops\u002Fpinrule","jhaizhou-ops","Universal AI behavior rule framework — pin your 5-10 rules so AI doesn't drift in long tasks. Dev-scenario preset built in; switch to any scenario in one line. Claude \u002F Codex \u002F Cursor \u002F Hermes. Zero LLM, zero network, zero deps.","https:\u002F\u002Fpypi.org\u002Fproject\u002Fpinrule\u002F",null,"Python",30,1,0,0.9,"MIT License",false,"main",[20,21,22,23,24,25,26,27,28,29,5,30],"agent-rules","agent-tooling","ai-agent","claude-code","codex-cli","coding-assistant","cursor","developer-tools","hooks","llm","prompt-engineering","2026-06-12 02:04:09","# pinrule\n\n**[🇬🇧 English (current)](.\u002FREADME.md) · [🇨🇳 中文](.\u002FREADME.zh.md)**\n\n[![CI](https:\u002F\u002Fgithub.com\u002Fjhaizhou-ops\u002Fpinrule\u002Factions\u002Fworkflows\u002Fci.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fjhaizhou-ops\u002Fpinrule\u002Factions\u002Fworkflows\u002Fci.yml)\n[![Python](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpython-3.11%2B-blue)](https:\u002F\u002Fwww.python.org\u002F)\n[![License: MIT](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-MIT-green)](LICENSE)\n[![Tests](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Ftests-passing-brightgreen)](https:\u002F\u002Fgithub.com\u002Fjhaizhou-ops\u002Fpinrule\u002Factions)\n[![Latest Release](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fv\u002Frelease\u002Fjhaizhou-ops\u002Fpinrule?label=release)](https:\u002F\u002Fgithub.com\u002Fjhaizhou-ops\u002Fpinrule\u002Freleases)\n[![Last Commit](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Flast-commit\u002Fjhaizhou-ops\u002Fpinrule)](https:\u002F\u002Fgithub.com\u002Fjhaizhou-ops\u002Fpinrule\u002Fcommits\u002Fmain)\n\n**Pin the 5-10 rules your AI must not drift from during long tasks.** Ships with a 7-rule dev preset; switch to any other scenario with one sentence: `\u002Fpinrule I mainly do X, switch to this scenario`.\n\n> **Runtime**: pure engineering · zero LLM · zero network · zero runtime deps · ~50-70ms hook · ~2% token overhead. (Scenario rule pack generation runs in your Agent — see Path B below.)\n\n![pinrule demo — 5 scenes, animated SVG](.\u002Fassets\u002Fdemo-en.svg)\n\nAndrej Karpathy's [CLAUDE.md](https:\u002F\u002Fgithub.com\u002Fforrestchang\u002Fandrej-karpathy-skills) teaches your AI *how* to write good code. pinrule keeps your AI *aligned with your personal preferences* in long tasks — what to never do, what to always do, what to push back on — so you don't have to repeat yourself every 30 turns.\n\n---\n\n## Quick start\n\n### Let your Agent install it (recommended — least friction)\n\nSince you're already using Claude Code \u002F Codex \u002F Cursor (otherwise you wouldn't need pinrule), paste this prompt to your Agent:\n\n```\nInstall pinrule (github.com\u002Fjhaizhou-ops\u002Fpinrule) — a universal AI behavior rule\nframework that keeps my long-task rules from being lost. Steps:\n\n1. Verify Python is actually installed (Windows: run `python --version` — if it\n   silently exits to Microsoft Store, first `winget install Python.Python.3.12`\n   and reopen PowerShell). Use `python -m pinrule` form on Windows to avoid PATH issues.\n2. pip install pinrule\n3. pinrule init      # auto-installs default rules + hooks for every detected client\n4. pinrule doctor    # verify install\n5. Show me the 7 default rules + how to add my own via \u002Fpinrule\n```\n\nThe Agent figures out your OS, Python state, and which clients you have. After install, restart your client and rules take effect.\n\n### Manual install\n\n```bash\npip install pinrule && pinrule init\n```\n\n`pinrule init` auto-installs hooks for any detected client (Claude \u002F Codex \u002F Cursor \u002F Hermes) + writes default rules to `~\u002F.pinrule\u002F`. If you install a new client later, run `pinrule install-hooks` to wire it up.\n\nRestart Claude \u002F Codex \u002F Cursor \u002F Hermes — default rules become active once hooks load.\n\n**Uninstall** — `pinrule uninstall-hooks` (auto-removes pinrule entries from every detected client surgically; doesn't touch hooks installed by other tools).\n\n> **Windows without Python**: `python --version` silently jumping to Microsoft Store means no real Python — install via `winget install Python.Python.3.12`, reopen PowerShell, then use `python -m pip install pinrule && python -m pinrule init` (the `python -m` form avoids needing `Scripts\\` on PATH).\n\n---\n\n## What pinrule does\n\n- **Injects** your 5-10 directions at session start, compact anchor each turn, full reinject on long-context decay.\n- **Blocks drift in real time** — Bash `sleep`, Edit-before-Read, \"let me hardcode this\" intent declarations all caught before they ship.\n- **Survives compact** — dumps full rule state pre-compact; reloads + re-injects post-restart.\n\nPer-hook lifecycle: see [ARCHITECTURE.md](.\u002Fdocs\u002FARCHITECTURE.md#backend-capability-matrix).\n\n---\n\n## How it fits together\n\n```mermaid\nflowchart LR\n    R[(rules.json\u003Cbr\u002F>5-10 core directions)]\n    K[pinrule engine\u003Cbr\u002F>regex + counting]\n    A[🤖 Agent\u003Cbr\u002F>Claude \u002F Codex \u002F Cursor \u002F Hermes]\n    V[(violations.jsonl\u003Cbr\u002F>audit history)]\n\n    R ==> K\n    K ==>|prompt header| A\n    A ==>|tool call \u002F response| K\n    K -.->|hit → deny + log| V\n    V -.->|next-turn drift marker| K\n```\n\n`rules.json` is the only thing you maintain. The engine reads it, injects at the right hook points, watches Agent traffic for drift — no retrieval, no scoring, no LLM in the loop.\n\n---\n\n## Not just another AI memory tool\n\n| Tool category | What it stores | When it fires |\n|---|---|---|\n| **Memory** (mem0, Claude memory) | Facts about you (preferences, history, profile) | Agent chooses to query |\n| **pinrule** | Behaviors you've articulated as long-term directions | Hooks fire automatically every prompt + every tool call |\n\nUse both. Memory holds \"I prefer TypeScript\"; pinrule enforces \"non-negotiable directions, hook-enforced.\"\n\n---\n\n## Performance\n\n| | |\n|---|---|\n| **Runtime deps** | 0 (Python stdlib only — JSON, no third-party packages) |\n| **Rule count** | 7 default (dev-scenario preset) · soft cap 10 · hard cap 12 (load refused beyond) |\n| **Hook latency** | ~50-70ms typical (machine-bound; reproduce via `scripts\u002Fmeasure_perf.py`) |\n| **Token overhead** | ~2% of conversation context in real dogfood (methodology: [docs\u002FEVALUATION.md](.\u002Fdocs\u002FEVALUATION.md)) |\n| **Tests** | 800+ unit tests, [green on 6-matrix CI](https:\u002F\u002Fgithub.com\u002Fjhaizhou-ops\u002Fpinrule\u002Factions\u002Fworkflows\u002Fci.yml) (ubuntu + macOS + Windows × Python 3.11 \u002F 3.12) |\n| **Supported clients** | Claude \u002F Codex \u002F Cursor \u002F Hermes — [add a backend](.\u002Fpinrule\u002Fbackends\u002FHOWTO.md) |\n\n---\n\n## `\u002Fpinrule` — one command, three jobs\n\nYou only need to remember one command — `\u002Fpinrule`. Based on the natural-language content you type, the pinrule skill auto-dispatches to one of three paths, guides your Agent through tone refinement, schema validation, and monitoring wiring, then writes to your rule library after your confirmation.\n\n| You type | Routes to | Wall time |\n|---|---|---|\n| **`\u002Fpinrule`** (no args) | **Data dashboard** — which engine checks fire most, real-vs-false-positive split | \u003C1s (pure CLI, no LLM synthesis) |\n| **`\u002Fpinrule \u003Csingle rule>`** | **Path A: add \u002F modify \u002F remove one rule** — 7-step skill flow | ~30s |\n| **`\u002Fpinrule \u003Cscenario, switch to this>`** | **Path B: scenario rule pack** — synthesize 5-7 rules from 4 signals, two-phase confirm, atomic batch write | 3-5 min |\n\nPath A: `\u002Fpinrule When I say \"done\" I want test pass evidence attached` → 30s end-to-end.\n\nPath B: see next section.\n\n---\n\n## Switch any work scenario in one line\n\nWhatever your work is, your Agent researches the matching rule pack:\n\n```\n\u002Fpinrule I mainly do UX user research + interviews, switch to this scenario\n```\n\nThe Agent synthesizes 4 signals into a 5-7 rule pack:\n\n| Signal | Content |\n|---|---|\n| **A. Your local rule files** | `~\u002F.claude\u002FCLAUDE.md` \u002F `~\u002F.codex\u002FAGENTS.md` \u002F project `CLAUDE.md` \u002F `.cursor\u002Frules\u002F*.mdc` |\n| **B. Online best practices** | `WebSearch` finds high-star GitHub repos \u002F industry blogs \u002F papers |\n| **H. Karpathy CLAUDE.md baseline** | Cross-scenario engineering principles |\n| **S. Session context** | What you're working on right now |\n\nTwo-phase approval (content → mechanism), then atomic batch write with backup. Full walkthrough: [SKILL.md Path B](.\u002Fskills\u002Fpinrule\u002FSKILL.md).\n\n> **Boundary**: pinrule runtime does not call LLMs or the network. Your Agent does the scenario research; pinrule validates and runs the resulting rules locally.\n\n---\n\n## Tried and rejected\n\nSeveral ideas looked attractive but failed in practice. Recorded so the same paths don't get re-walked:\n\n| Tried | Why rejected |\n|---|---|\n| **LLM auto-distilling new rules** | Latency + noise. Hearing something once doesn't make it a long-term direction. |\n| **Retrieval \u002F cosine recall** | The pain is \"persistence,\" not \"recall\" — 5-10 rules can be always-on. |\n| **More than 12 rules** | LLMs pattern-match \"a rule list exists\" instead of reading it ([Mnilax's 30-codebase study](https:\u002F\u002Fx.com\u002FMnilax\u002Fstatus\u002F2053116311132155938)). |\n| **Reshipping as MCP server** | Hooks are *enforced*; MCP tools are *chosen*. In long-session decay, the Agent drifts before it asks \"what rules apply.\" |\n\n---\n\n## Honest tool boundaries\n\npinrule is **regex + counting**, not LLM semantic understanding. Each known failure mode has a regression test you can run yourself:\n\n| Failure mode | Evidence you can reproduce |\n|---|---|\n| **False positives** (table cells quoting a term, `python -c` literals, commit messages) | `pytest tests\u002Ftest_check_fp_fixes_v0_16_13.py` — locks down 4 historical FP fixes (negation prefix, fenced code blocks, inline backticks, full-width punctuation). `pinrule audit` flags suspected FPs at runtime. |\n| **False negatives** (Agent disguising a violation) | `pytest tests\u002Ftest_false_negative_regression.py` — 30+ FN cases pinned. Regex can't read intent — pinrule assumes you're not cheating yourself. |\n| **Zero hits ≠ fix correct** | Pattern may just be too wide. Cross-check with `pinrule audit` on real session data, not synthetic prompts. |\n\nSits between `git` and a linter — signals, not verdicts.\n\n---\n\n## FAQ\n\n\u003Cdetails>\n\u003Csummary>\u003Cb>Nothing happens after install?\u003C\u002Fb>\u003C\u002Fsummary>\nRun \u003Ccode>pinrule doctor\u003C\u002Fcode> — checks hook events, rule loading, session state.\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Cb>Too many false positives?\u003C\u002Fb>\u003C\u002Fsummary>\n\u003Ccode>pinrule audit\u003C\u002Fcode> shows triggers tagged \"⚠️ possible false positive\" — report via Issue. Disable a single rule: \u003Ccode>pinrule rule remove &lt;id&gt;\u003C\u002Fcode>, or edit \u003Ccode>~\u002F.pinrule\u002Frules.json\u003C\u002Fcode> and remove its \u003Ccode>violation_keywords\u003C\u002Fcode> \u002F \u003Ccode>violation_checks\u003C\u002Fcode> fields.\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Cb>Custom rule sets for non-dev scenarios (writing \u002F research \u002F legal \u002F UX)?\u003C\u002Fb>\u003C\u002Fsummary>\nSay \u003Ccode>\u002Fpinrule I mainly do X scenario, switch to this\u003C\u002Fcode>. Agent synthesizes 5-7 rules from 4 signals (your local \u003Ccode>CLAUDE.md\u003C\u002Fcode> \u002F \u003Ccode>AGENTS.md\u003C\u002Fcode> \u002F \u003Ccode>.cursor\u002Frules\u003C\u002Fcode>, online best practices via WebSearch, Karpathy baseline, session context), previews with source attribution, two-phase confirms, atomic batch write — 3-5 min end-to-end. See \u003Ca href=\"#switch-any-work-scenario-in-one-line\">\"Switch any work scenario\"\u003C\u002Fa> above.\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Cb>How do I sync rules across devices?\u003C\u002Fb>\u003C\u002Fsummary>\nAsk the Agent to copy \u003Ccode>~\u002F.pinrule\u002Frules.json\u003C\u002Fcode>. \u003Cb>Safe to sync\u003C\u002Fb>: \u003Ccode>rules.json\u003C\u002Fcode> + \u003Ccode>config.json\u003C\u002Fcode>. \u003Cb>Never sync\u003C\u002Fb>: \u003Ccode>violations.jsonl\u003C\u002Fcode>, \u003Ccode>session-state\u002F\u003C\u002Fcode> (runtime data, per-device — cloud-synced folders can corrupt cross-device state).\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Cb>Does this overlap with Karpathy's CLAUDE.md?\u003C\u002Fb>\u003C\u002Fsummary>\nComplementary. Karpathy's 12 rules are \u003Cb>universal coding principles\u003C\u002Fb> (cross-user). pinrule's are \u003Cb>personal preferences\u003C\u002Fb> (per-user). Use both.\n\u003C\u002Fdetails>\n\n---\n\n## What Agents say after running pinrule\n\n> **Claude (Opus 4.7)**: Like having a senior tech director reviewing every action in real time — tiring, but it delivers. Without pinrule, a lot more behavior-the-user-didn't-want would have shipped.\n>\n> **Codex (GPT 5.5)**: I noticed myself being \"behaviorally nudged,\" but didn't strongly feel \"blocked or interrupted.\"\n>\n> *— Matches pinrule's positioning: guardrails + background noise, speaking up only when you hit a rule.*\n\n---\n\n## Mental model\n\n> A rules file isn't a wishlist. It's a behavioral contract closing out failure modes you've actually observed. Each rule should answer: **what error is this rule preventing?**\n\nThe 7 default rules in `data\u002Frules.dev.example.json` are pain points from self-use, not a template to copy verbatim. Keep what matches your own failure scenes, replace the rest via `\u002Fpinrule \u003Cnatural language>`.\n\n---\n\n## Documentation\n\n- [PRD.md](.\u002Fdocs\u002FPRD.md) — product requirements + scenario positioning\n- [ARCHITECTURE.md](.\u002Fdocs\u002FARCHITECTURE.md) — hook protocol, 8 check implementations, sandbox model\n- [HOOK_CONFIGURATION_GUIDE.md](.\u002Fdocs\u002FHOOK_CONFIGURATION_GUIDE.md) — per-hook lifecycle + tunable thresholds\n- [EVALUATION.md](.\u002Fdocs\u002FEVALUATION.md) — methodology behind performance numbers (hook latency, token overhead)\n- [CHANGELOG.md](.\u002FCHANGELOG.md) — release notes (grouped by minor version)\n- [CODEX_BACKEND.md](.\u002Fdocs\u002FCODEX_BACKEND.md) — Codex backend ownership boundary\n- [CLAUDE.md](.\u002FCLAUDE.md) — project charter for Claude collaboration\n\nAll bilingual (`.md` English + `.zh.md` Chinese).\n\n## Acknowledgments\n\n- [Andrej Karpathy's CLAUDE.md template](https:\u002F\u002Fgithub.com\u002Fforrestchang\u002Fandrej-karpathy-skills) — universal coding-principles companion to pinrule's personal preferences.\n- [Mnilax's 30-codebase 6-week CLAUDE.md study](https:\u002F\u002Fx.com\u002FMnilax\u002Fstatus\u002F2053116311132155938) — pinrule's soft cap 10 \u002F hard cap 12 comes from this.\n\n## Contributing\n\n- Bugs \u002F ideas: [GitHub Issues](https:\u002F\u002Fgithub.com\u002Fjhaizhou-ops\u002Fpinrule\u002Fissues)\n- Add a new AI client backend: [HOWTO](.\u002Fpinrule\u002Fbackends\u002FHOWTO.md)\n- Scenario rule templates: PR to `data\u002F`\n\n## License\n\nMIT\n","pinrule 是一个通用的AI行为规则框架，旨在确保AI在执行长时间任务时遵循用户设定的5-10条核心规则。其主要功能包括预设开发场景、一键切换不同场景以及对Claude、Codex、Cursor和Hermes等主流AI助手的支持。技术上，pinrule采用纯Python编写，无需依赖任何大型语言模型、网络连接或额外库，运行时开销极低（约50-70毫秒）。该工具非常适合需要定制化AI行为以适应特定工作流程的开发者或团队使用，例如代码编写辅助、文档生成等场景。通过简单的命令行操作即可完成安装与配置，易于集成到现有开发环境中。",2,"2026-06-11 04:03:06","CREATED_QUERY"]