airbroke / lib
AGENTS.md221 starsChanged 6 months agoMITView on GitHub
lib/ is the application and server layer, not a generic utility bucket. It owns reads, mutations, auth policy, intake semantics, MCP behavior, and routing. - Import db from lib/db.ts; never construct an ad hoc Prisma client. - Server actions begin with "use server", authenticate before protected mutations, and pair writes with the paths or tags their consumers render. - Preserve Next control flow with unstable_rethrow or redirects outside broad catch blocks. - lib/queries/ is the default UI read layer. MCP…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,736 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository5 other files it gives its agents.
- AGENTS.mdAGENTS.md
- app/AGENTS.mdAGENTS.md
- components/AGENTS.mdAGENTS.md
- prisma/AGENTS.mdAGENTS.md
- __tests__/AGENTS.mdAGENTS.md
The file
We split this AGENTS.md into the rules it gives an agent
6 rules. About 1 is common, 3 are distinctive, and 2 are very specific to this project.
≈1
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 36
Import db from lib/db.ts; never construct an ad hoc Prisma client.
- Very specific: line 55
Do not turn utils.ts into a home for domain behavior.
- Distinctive: line 57
Do not duplicate grouping or persistence rules between Airbrake and Sentry.
- Distinctive: line 58
Do not weaken MCP timing-safe key comparison, origin checks, read-only hints, strict schemas, pagination limits, or structured ambiguity …
- Common: line 60
Do not expose additional project credentials through MCP setup-guide output without explicit security review and accepted/rejected tests.
- Distinctive: line 62
Do not change trigger-dependent resolution behavior without reviewing the corresponding Prisma migration SQL and action tests.
≈ “Common” is an estimate: at least 1 in 5 of the 16,597 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
APPLICATION LIBRARY GUIDE
OVERVIEW
lib/ is the application and server layer, not a generic utility bucket. It
owns reads, mutations, auth policy, intake semantics, MCP behavior, and routing.
STRUCTURE
actions/ # Authenticated server mutations and invalidation
auth/ # Better Auth providers, restrictions, and session helpers
intake/ # Airbrake/Sentry normalization and shared persistence
mcp/ # MCP transport, schemas, tools, and read models
queries/ # UI-facing Prisma read paths
integrations/ # SDK metadata and generated setup snippets
routing/ # Breadcrumb and search-parameter contracts
cache/ # Shared cache tags
db.ts # Lazy shared Prisma client boundaryWHERE TO LOOK
| Task | Location | Notes |
| Database client | db.ts | Callable lazy proxy; one shared entrypoint |
| Mutation guard | actions/requireAuth.ts | Run before protected writes |
| UI invalidation | actions/revalidateProjectShellPaths.ts | Project paths |
| Auth configuration | auth/index.ts | Lazy initialization is build-critical |
| Intake identity | intake/upsertNoticeOccurrence.ts | Grouping and retries |
| MCP registry | mcp/tools.ts | Public tool list and result contract |
| MCP security | mcp/server.ts | Key, origin, CORS, per-request handler |
CONVENTIONS
- Import
dbfromlib/db.ts; never construct an ad hoc Prisma client. - Server actions begin with
"use server", authenticate before protected mutations, and pair writes with the paths or tags their consumers render. - Preserve Next control flow with
unstable_rethrowor redirects outside broad catch blocks. lib/queries/is the default UI read layer. MCP keeps protocol-specific resolution and response shaping underlib/mcp/readModels/.- Intake groups notices by project, environment, and kind; occurrences by
notice and SHA-256 message hash. Existing occurrences are reinstated and
unique races receive bounded
P2002retries. - Better Auth is initialized lazily so imports and production builds do not require provider runtime configuration.
- MCP tools validate Zod inputs, stay read-only, normalize tool results, and make ambiguous project references explicit rather than guessing.
- Recreate the MCP transport handler per request; its collaborator retains request/session state internally.
ANTI-PATTERNS
- Do not turn
utils.tsinto a home for domain behavior; use the matching action, query, intake, auth, MCP, integration, or routing module. - Do not duplicate grouping or persistence rules between Airbrake and Sentry.
- Do not weaken MCP timing-safe key comparison, origin checks, read-only hints, strict schemas, pagination limits, or structured ambiguity errors.
- Do not expose additional project credentials through MCP setup-guide output without explicit security review and accepted/rejected tests.
- Do not change trigger-dependent resolution behavior without reviewing the corresponding Prisma migration SQL and action tests.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

