# AGENTS.md — core-shared Generic, reusable primitives with **zero business knowledge**. This package is the foundation for all other packages and exports utilities, Payload field/hook definitions, and tRPC initialization. ## Responsibilities - **Generic primitives** — environment helpers, date utilities, type guards - **Payload utilities** — field definitions (slug, SEO), blocks (CTA), access controls (is-admin), hooks (slugify, publish timestamp) - **tRPC platform** — `initTRPC.create()`, shared context factory, procedure builders - **No business domain knowledge** — no awareness of articles, users, media, or any feature ## Must NOT import - Any feature package (`@repo/auth`, `@repo/blog`, etc.) - Any app package - Framework-specific code (Next.js, TanStack React Query) ## Public exports From `package.json`: - `.` — all utilities, Payload exports, tRPC init - `./payload` — Payload field/hook/block utilities only - `./trpc/init` — tRPC `initTRPC` instance + builders. **Plan 9:** also exports `t` (the raw `initTRPC.create({...})` instance) so feature packages can build their own procedures via `t.procedure.use(...)` - `./trpc/context` — tRPC context factory only - `./trpc/define-error-middleware` — **Plan 9:** factory that builds a tRPC middleware translating domain errors to `TRPCError`. Takes `ReadonlyArray` tuples; uses `instanceof` discrimination; preserves the original error as `.cause`. **Owned by features:** each feature passes its own constructors in via `integrations/api/procedures.ts`. core-shared never enumerates feature-specific error classes — this stays boundary-clean ## Test conventions - Tests colocated: `src/lib/slug-field.ts` → `src/lib/slug-field.test.ts` - Vitest environment: `node` - Alias: `@/` resolves to `src/` - Run: `pnpm test --filter @repo/core-shared` Covered areas: - Slug field generation + validation - Payload hooks (publish-at timestamp, slugify-if-missing) - Access control helpers