agentleFS
tdavidsontdavidson/portfolio/CLAUDE.md

portfolio

CLAUDE.md78 starsChanged 9 months agoApache-2.0View on GitHub

Conventions baked in to keep automated edits safe across this repo. Read before generating migrations or refactoring data-access code. This repo is public. Never put a real fund, LP, investor, customer, client, user, portfolio company, vendor, bank or person's name into it, nor their email addresses or domains, account numbers, or real figures (commitments, balances, marks, share counts, fees). That covers code, tests, fixtures, comments, docs, migrations, commit messages, branch names and PR titles and descriptions. It holds even when…

  • In this repositoryOne other file it gives its agents.

The file

We split this CLAUDE.md into the rules it gives an agent

5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    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
  1. Very specific:

    Use invented placeholders: Acme, Northwind, Example Fund I, Jane Doe, round figures like 100_000, and .example domains (gp@fund.example).

    line 14
  2. Distinctive:

    Don't link to claude.ai session or conversation URLs in commits, PRs or code.

    line 17
  3. Distinctive:

    Every merge to main is a production build on Vercel, and every push to a PR branch is a CI run, so keep both to the pushes that matter.

    line 191
  4. Distinctive:

    Don't push "merge main into branch" commits just to sync.

    line 196
  5. Distinctive:

    When several PRs are ready, merge them together rather than minutes apart, so main builds production once instead of once per merge.

    line 198

≈ “Common” is an estimate: at least 1 in 5 of the 29,248 CLAUDE.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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

Repo conventions for AI assistants

Conventions baked in to keep automated edits safe across this repo. Read before generating migrations or refactoring data-access code.

No real data, anywhere

This repo is public. Never put a real fund, LP, investor, customer, client, user, portfolio company, vendor, bank or person's name into it, nor their email addresses or domains, account numbers, or real figures (commitments, balances, marks, share counts, fees). That covers code, tests, fixtures, comments, docs, migrations, commit messages, branch names and PR titles and descriptions. It holds even when the data came from a bug report, a screenshot, a spreadsheet or a production query: rebuild the case with invented values that keep the same shape.

  • Use invented placeholders: Acme, Northwind, Example Fund I, Jane Doe, round figures like 100_000, and .example domains (gp@fund.example).
  • The only real names allowed are Hemrock's own (Hemrock, hemrock.com) and Unstructured Ventures.
  • Don't link to claude.ai session or conversation URLs in commits, PRs or code.

tests/no-real-names.test.ts fails on known names (stored as hashes, so the test names no one) and on Claude session links. Passing it doesn't make a change clean; it only catches names already known.

Styling

DESIGN.md is the design system; app/globals.css holds the tokens. Read it before writing UI.

The short version, because these are the mistakes that actually get made:

  • Never use raw Tailwind palette classes — bg-amber-100, text-green-600, border-blue-500. They break per-fund white-labelling, because themeCssVars() can't repoint them. Use the tokens: bg-warning-subtle, text-success, border-brand-200, text-muted-foreground. lib/design-tokens.test.ts fails on new ones; the only exemptions are files using colour categorically, allowlisted there with a reason.
  • Numbers use tabular-nums, not font-mono. Mono is for content a machine reads literally — code, IDs, OTP inputs. Financial figures are not code. Same rule in the PDF templates.
  • Cards use rounded-card, controls use rounded-lg/md/sm. --radius is the control radius (0.25rem), --radius-card the card one (0.5rem).
  • --primary is the deployment's action colour (fund-themeable). --brand is Hemrock's (highlighter yellow, the same as hemrock.com and nevermodel; marketing — a fill under ink text, never text itself; accent text is text-brand-700 dark:text-brand-400). They are not interchangeable.
  • Accent text needs a dark-mode pair: text-brand-700 dark:text-brand-400. The 700 stop fails contrast on the dark surface.
  • Display weight follows size and face. Marketing headings (text-display/text-title) are font-semibold; LP-facing document headings (text-heading) stay font-normal. Both numbers assume --font-display is Inter — a serif display face wants 400 throughout.

Migration conventions

Every new create table migration requires explicit Data API grants

Supabase is moving to an "explicit grants required" model for the Data API. New Supabase projects after 2026-05-30, and all existing projects after 2026-10-30, will create tables in the public schema without automatic grants to anon/authenticated/service_role. The Data API (supabase-js, PostgREST, GraphQL) can't see those tables until grants are issued explicitly.

This repo is meant to be installable against fresh Supabase projects, so every create table migration must include the grants inline. The bulk-backfill migration (20260513000000_data_api_grants_backfill.sql) covers tables created before that date — but anything new must carry its own grants or the app breaks on fresh post-2026-05-30 installs.

Template for any new table:

create table public.new_thing (
  id uuid primary key default gen_random_uuid(),
  fund_id uuid not null references funds(id) on delete cascade,
  -- ... columns ...
  created_at timestamptz not null default now()
);

-- 1. Grants — required from 2026-05-30 onward for the Data API to see this table.
--    Default posture: anon = SELECT only (no unauthenticated writes via Data API);
--    authenticated + service_role get full CRUD, with RLS scoping per-row access.
--    Only grant anon writes if the table genuinely needs unauthenticated insert/update.
grant select on public.new_thing to anon;
grant select, insert, update, delete on public.new_thing to authenticated, service_role;

-- 2. RLS — enable even if you think it isn't needed. The schema-wide default is "RLS on".
alter table public.new_thing enable row level security;

-- 3. Policies — at least one per role that should have access. Without policies, RLS
--    blocks every row even when grants are in place.
create policy "Fund members read their fund's rows"
  on public.new_thing for select to authenticated
  using (exists (
    select 1 from fund_members fm
    where fm.fund_id = new_thing.fund_id and fm.user_id = auth.uid()
  ));
-- (add insert/update/delete policies as the table requires)

The template above is for an ordinary table, and "ordinary" is the part to check. A grant knows nothing about domains or features, so grant ... to authenticated on a table whose route is gated on a domain hands the data to exactly the members that gate refuses — from the browser console, with NEXT_PUBLIC_SUPABASE_ANON_KEY, no route involved. If a table's only reader is a gated route holding the service-role key (all of lp_tax_forms, k1_*, tax_year_closes, received_k1s), grant it to service_role alone, reads included, and write no authenticated policies — RLS then denies by default if a grant ever creeps back. tests/tax-data-api-grants.test.ts pins that set; 20260714000004_ledger_db_enforcement.sql is the write-side precedent for the ledger.

Sequences: this repo uses uuid default gen_random_uuid() for primary keys, so explicit sequences are rare. If you ever add one (bigserial, serial, create sequence), add grant usage, select on sequence public.<name> to anon, authenticated, service_role; alongside it.

Functions: Postgres functions have a separate default-privileges model from tables and are not affected by the 2026 Data API grants rollout. SECURITY DEFINER functions still need revoke execute from anon, authenticated, public if you don't want unauthenticated callers (see 20260509000002_memo_agent_jobs_lockdown.sql for the pattern).

fund_settings is readable by members column by column

Members read fund_settings through column grants that leave out the secrets (every *_encrypted column, postmark_webhook_token, deal_submission_token). Column grants do not follow new columns, so a migration that adds a column to fund_settings must end with select public.grant_fund_settings_member_columns();, or members' own reads of it are refused. Name a new secret column *_encrypted and it stays hidden. tests/fund-settings-column-grants.test.ts enforces the call. Read secrets with the service-role client only.

Don't edit historical migrations

Migration files that have already shipped to production must not be edited. The Supabase CLI tracks applied migrations by filename hash; modifying an applied migration causes integrity failures on re-deploy. Always add a new migration.

Don't apply migrations remotely via Supabase MCP

This repo's owner runs supabase db push themselves. AI assistants only create local migration files in supabase/migrations/; they do not apply them.

A migration that must wait for a deploy does not belong in supabase/migrations/ yet

supabase db push applies every pending file in timestamp order. So a migration whose correctness depends on new application code already being live — dropping a column the current release still reads, tightening a constraint the current release can still violate — is a trap the moment it is written, and a plan that merely says "apply this one last" does not prevent it. Pushing everything pending is the normal thing to do and is not the owner's mistake.

Stage these outside the scanned directory, as supabase/pending-deploy/<name>.sql, with a header naming the release that has to ship first, and move the file into supabase/migrations/ (renaming it to a current timestamp) only once that release is deployed. Splitting an expand/contract change across two timestamps is not enough on its own — both halves are pending at the same time.

This bit the unified-accounting work: 20261006174711_retire_accounting_mode_columns.sql dropped vehicle_accounting_settings.capital_source and history_mode while the deployed release still read them, and because every one of those read sites ignores its error and uses data, the result was not a visible failure but a silent fallback to the default. Leave that file where it is — it is already applied, and deleting an applied migration causes a history mismatch on the next push.

Access control

Every new API route needs an access decision

lib/access/route-domains.ts maps every route under app/api/** to either a domain + level, or an explicit UNGATED_ROUTES entry with the reason it needs no grant. lib/access/route-domains.test.ts fails when a route is in neither, so a new route cannot ship without answering the question.

The gate itself is gateApiRequest in proxy.ts (Next 16 renamed middleware to proxy; same role, Node runtime) — it resolves every /api request through effectiveAccess before the handler runs (one round trip, via the access_context RPC). Do not re-implement a role check in a route and consider it done: the reason this model exists is that 137 of 263 routes checked only fund membership and never looked at role. Add the registry entry; the boundary does the rest.

But the registry maps ONE domain per route — the minimum to call it, not a licence for everything in the response. A route whose payload straddles domains must gate the extra part in the handler (hasAccess(access, 'lp_capital', 'read')), as /api/accounting/statements does for the statement of changes in partners' capital. When adding a route, ask what its response contains, not just what it's called.

Every new server-component PAGE needs one too

The middleware never sees a page. A server component under app/(app)/** queries Postgres itself — often with createAdminClient(), so RLS is out of the path as well — and renders the result, which means the only gate is the one the page calls. Getting this wrong is not "the nav is untidy": it is hidden failing to mean hidden, reachable by anyone who has the URL.

So the page side has the same registry: lib/access/page-domains.ts maps every server page to a domain (or lists it in UNGATED_PAGES with a reason — a redirect or a static document, never "the nav hides it"), and lib/access/page-domains.test.ts fails when a page is in neither. It also fails when a page is mapped to a domain it never checks, so the map can't rot into a comment.

In the page, before it fetches anything:

const page = await resolvePageAccess(user.id)
if (!page || !canViewPage(page, 'portfolio')) redirect('/dashboard')

resolvePageAccess also returns fundId, role and isAdmin, so it replaces the fund_members lookup rather than adding to it. Client pages ('use client') need nothing: they render no fund data on the server, and their /api calls are gated by the middleware.

Section guards (app/(app)/funds/guard.ts) count as the gate, but they must resolve through canViewPage too — one that compares roles instead silently vetoes the grants, which is the bug tests/route-gates-honour-grants.test.ts exists to catch on both sides.

Access resolves through ONE function, effectiveAccess (lib/access/effective.ts). Two axes: fund_settings.feature_visibility is the fund-level ceiling; per-user grants (fund_member_access, defaulting to fund_domain_defaults) narrow it and never widen it. The order of its checks is the policy — lib/access/effective.test.ts pins it; read that before changing the function.

hidden and off deny every surface, admins included. hidden does NOT mean "gone from the nav but still reachable by URL" — that was the bug this replaced. See plans/plan-access-control.md.

Data-access conventions

Cross-tenant safety

Every API route resolves fund_id from auth.getUser() → fund_members lookup, not from the request body or params. The single-fund-per-user invariant is enforced at the schema level (fund_members.user_id is unique — see 20260511000001_fund_members_one_fund_per_user.sql). If you ever need to break that invariant, the resolution path needs to change too — likely to a session-stored current_fund_id.

Admin client vs user-context client

Most write operations use createAdminClient() (service role) with manual .eq('fund_id', ...) filters. RLS is in place on most tables as a secondary defense but the dominant security boundary is application code, not RLS. When adding new endpoints, follow the same pattern: admin client for writes, manual fund scoping, RLS policies still recommended for defense in depth.

Pull requests

Every merge to main is a production build on Vercel, and every push to a PR branch is a CI run, so keep both to the pushes that matter.

  • Push follow-up fixes to the existing branch. Don't open a new PR to fix an open one.
  • Open PRs as drafts, and mark them ready for review only once they are.
  • Don't push "merge main into branch" commits just to sync. Rebase, or leave the branch alone if it still merges cleanly.
  • When several PRs are ready, merge them together rather than minutes apart, so main builds production once instead of once per merge.
<!-- BEGIN:nextjs-agent-rules -->

This is NOT the Next.js you know

This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in node_modules/next/dist/docs/ (resolved from this file's directory; in monorepos the next package may not be visible from the repo root) before writing any code. Heed deprecation notices.

This block is written and re-added by next dev — verify at node_modules/next/dist/server/lib/generate-agent-files.js. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean.

<!-- END:nextjs-agent-rules -->

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.