Skip to content

Open source alternative to Semrush and Ahrefs

Replace the Greptile config with maintainer review guidelines (#694)

Ben Senescu764ea28ceea6
diff --git a/.agents/skills/maintain-greptile-rules/SKILL.md b/.agents/skills/maintain-greptile-rules/SKILL.md
deleted file mode 100644
index 89fa7595..00000000
--- a/.agents/skills/maintain-greptile-rules/SKILL.md
+++ /dev/null
@@ -1,62 +0,0 @@
----
-name: maintain-greptile-rules
-description: Evaluate verified findings from merge-ready, Greptile, pull-request, CI, security, billing, and other code reviews, then promote durable review gaps into the version-controlled .greptile configuration. Use when a review uncovers a recurring or high-risk repository invariant that Greptile does not capture, when Greptile repeatedly produces a false positive, or when asked to audit or update OpenSEO's Greptile rules and context.
-metadata:
- internal: true
----
-
-# Maintain Greptile rules
-
-Keep `.greptile/` high-signal. A review finding is evidence to evaluate, not automatically a new rule.
-
-## 1. Verify the finding
-
-- Reproduce or trace the finding against the current repository, including the relevant call path, tests, and intentional exceptions.
-- Read `.greptile/config.json`, `.greptile/rules.md`, and `.greptile/files.json` before proposing a change.
-- Distinguish a newly introduced risk from adjacent legacy debt. Do not encode an unverified assumption or a one-off implementation detail.
-- Repository absence is not policy evidence. If a reviewer infers a preference only because no current example exists, leave Greptile, code, and CI unchanged unless an owner explicitly adopts the policy.
-
-## 2. Route it to the right mechanism
-
-- **One-off bug:** fix the code and add a focused regression test. Do not add a Greptile rule.
-- **Verified deterministic policy violation:** prefer TypeScript, Oxlint, Knip, a focused test, or CI.
-- **Repeatable, diff-enforceable invariant:** add or refine a scoped structured rule in `.greptile/config.json`.
-- **Architecture, preference, or false-positive calibration:** update `.greptile/rules.md`.
-- **Canonical implementation Greptile should consult:** add a narrowly scoped reference in `.greptile/files.json`.
-- **Small workflow friction:** use the `papercuts` skill and log it in `.agents/PAPERCUTS.md`.
-
-## 3. Apply the promotion bar
-
-Promote a finding only when all applicable checks pass:
-
-- It is verified against current code.
-- A future reviewer can observe it from the diff and relevant call path.
-- It is repository-specific or materially improves false-positive calibration.
-- It is likely to recur, or its impact is high enough to justify prevention: authorization, security, billing, data loss, or cross-database correctness.
-- Existing Greptile context and automated checks do not already cover it adequately.
-- The instruction can be specific, measurable, narrowly scoped, and explicit about legitimate exceptions.
-
-If the evidence or policy is ambiguous, leave the configuration and enforcement unchanged and report the candidate for human judgment.
-
-## 4. Edit conservatively
-
-- Keep one coherent concern per structured rule, with a stable lowercase ID, severity, and the narrowest future-safe scope.
-- Do not infer permanent policy merely because the current repository has zero examples of an alternative.
-- Prefer narrowing or replacing a noisy rule over layering on more prose.
-- Keep repository-specific rules in `.greptile/`. Verify and report whether a minimal **org-enforced** dashboard baseline protects external contributions, secrets, authentication, billing, CI, and attempts to weaken review controls. Do not create or change dashboard, MCP, or organization rules unless the user explicitly asks, and do not duplicate the full repository rule set there.
-- Treat changes to `.greptile/**`, `AGENTS.md`, `CLAUDE.md`, `.agents/skills/**`, and `.github/**` as review-control changes that must receive explicit maintainer review. CODEOWNERS requests that review; branch protection or a ruleset must separately require code-owner approval when available.
-- Update the smallest set of configuration files needed; do not duplicate rule bodies in separate documentation.
-
-## 5. Validate
-
-Run:
-
-```bash
-jq empty .greptile/config.json .greptile/files.json
-node_modules/.bin/prettier --check .greptile/config.json .greptile/files.json .greptile/rules.md
-git diff --check
-```
-
-Also verify that rule IDs are unique, severities are valid, every `files.json` path exists, and an independent reviewer cannot find a clear false positive in the new wording.
-
-During merge-ready work, evaluate only verified findings that clear the promotion bar. A merge-ready run does not need to change `.greptile/` when no durable review gap was found.
diff --git a/.agents/skills/maintain-greptile-rules/agents/openai.yaml b/.agents/skills/maintain-greptile-rules/agents/openai.yaml
deleted file mode 100644
index 989b5f6a..00000000
--- a/.agents/skills/maintain-greptile-rules/agents/openai.yaml
+++ /dev/null
@@ -1,4 +0,0 @@
-interface:
- display_name: "Maintain Greptile Rules"
- short_description: "Promote verified review gaps into Greptile"
- default_prompt: "Use $maintain-greptile-rules to evaluate verified review findings and update the repository Greptile configuration."
diff --git a/.agents/skills/merge-ready/SKILL.md b/.agents/skills/merge-ready/SKILL.md
index 5e898740..bc2632d9 100644
--- a/.agents/skills/merge-ready/SKILL.md
+++ b/.agents/skills/merge-ready/SKILL.md
@@ -25,7 +25,7 @@ This skill composes with feature work — it is not only a review pass:
## 2. Multi-axis subagent review
-Spawn independent review subagents **in parallel**, one per axis, each given repo access and the complete branch scope:
+Spawn independent review subagents **in parallel**, one per axis, each given repo access, `maintainer-docs/review-guidelines.md` as required reading (hard invariants plus the false-positive controls for deployment modes, fixtures, and generated files), and the complete branch scope:
- committed changes: `git diff origin/main...HEAD`
- staged changes: `git diff --cached`
@@ -50,8 +50,8 @@ For each `blocker` and `should-fix` finding, spawn verification subagents (in pa
After verification, route durable learnings without forcing every review to change policy:
-- If an **APPLY** or **APPLY-MODIFIED** finding reveals a recurring or high-risk repository invariant that existing `.greptile/` context and CI do not capture, use `maintain-greptile-rules` and apply its promotion bar.
-- Keep one-off bugs as code fixes and regression tests. Put deterministic mechanical checks in CI or lint instead of Greptile.
+- If an **APPLY** or **APPLY-MODIFIED** finding reveals a recurring or high-risk repository invariant that `maintainer-docs/review-guidelines.md` and CI do not capture, add a short paragraph there. A finding is evidence to evaluate, not automatically a rule.
+- Keep one-off bugs as code fixes and regression tests. Put deterministic mechanical checks in CI or lint instead of review prose.
- When a small tooling, documentation, or workflow frustration occurs, use `papercuts` to append it to `.agents/PAPERCUTS.md`; do not derail merge-ready work to fix it.
## 4. Fix, check, loop
diff --git a/.agents/skills/papercuts/SKILL.md b/.agents/skills/papercuts/SKILL.md
index 2481249f..cc87b22e 100644
--- a/.agents/skills/papercuts/SKILL.md
+++ b/.agents/skills/papercuts/SKILL.md
@@ -83,7 +83,7 @@ Carry out an authorized cleanup using the same triage:
resolving date or commit. Keep deferred reports separate from actionable open
work, with a reason and a concrete trigger to revisit. Route real bugs to
normal issue/fix work; route recurring
- review-policy gaps through `maintain-greptile-rules`.
+ review-policy gaps to `maintainer-docs/review-guidelines.md`.
Preserve useful history for genuinely-resolved papercuts; do not delete them
merely to make the file shorter. (Noise that never belonged — see step 1 — is
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 836a7886..491c41d1 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -1,9 +1,9 @@
# Request explicit maintainer review for review-control changes.
/.github/ @bensenescu
-/.greptile/ @bensenescu
/AGENTS.md @bensenescu
/CLAUDE.md @bensenescu
/.agents/skills/ @bensenescu
+/maintainer-docs/review-guidelines.md @bensenescu
# Plugin distribution — these files define the MCP endpoint and skills
# every plugin installer connects to; a silent change here ships to all
diff --git a/.greptile/config.json b/.greptile/config.json
deleted file mode 100644
index c386962c..00000000
--- a/.greptile/config.json
+++ /dev/null
@@ -1,136 +0,0 @@
-{
- "strictness": 2,
- "commentTypes": ["logic", "syntax"],
- "triggerOnUpdates": true,
- "ignorePatterns": "src/routeTree.gen.ts\nweb/src/routeTree.gen.ts\nworker-configuration.d.ts\ndrizzle/meta/**\ndrizzle-pg/meta/**",
- "rules": [
- {
- "id": "tenant-resource-scope",
- "rule": "At each external trust boundary, establish the appropriate authorization before dispatch: session middleware for user endpoints, withMcpProjectAuth for project-scoped MCP handlers, signed state or verified provider signatures for callbacks and webhooks, and an explicit documented decision for public routes. Active project-scoped server functions use requireProjectContext with a validated projectId. Reads and mutations keyed by caller-controlled resource IDs must include the verified project, organization, or user in the query, or first authorize through a canonical parent lookup. Never trust a client-supplied organization, user, or billing identity. Archived or lifecycle resources may use requireAuthenticatedContext plus an explicit organization-scoped lookup. Bare-ID lookups are acceptable in trusted internal Workflow or Durable Object paths only when the upstream authorization invariant is explicit.",
- "scope": [
- "src/lib/auth*.ts",
- "src/server.ts",
- "src/server/features/**",
- "src/serverFunctions/**",
- "src/server/mcp/**",
- "src/routes/api/**",
- "src/middleware/**",
- "web/src/routes/api/**"
- ],
- "severity": "high"
- },
- {
- "id": "normalized-product-data",
- "rule": "Store relationships and independently queried, constrained, or evolving product concepts in normalized tables with foreign keys and join tables. Do not put relational IDs in JSON or delimited text to avoid joins. JSON or text is acceptable for opaque provider payloads, immutable history, caches, or bounded non-relational value arrays when the reason is clear.",
- "scope": [
- "src/db/**",
- "drizzle/**",
- "drizzle-pg/**",
- "src/server/**/repositories/**",
- "src/server/**/*Repository.ts"
- ],
- "severity": "medium"
- },
- {
- "id": "dual-dialect-persistence",
- "rule": "A change to hand-authored application schema must update the SQLite and Postgres definitions and generated migrations for both providers. Preserve equivalent table, column, nullability, default, constraint, index, and foreign-key semantics while allowing intentional dialect-native representations and Better Auth exceptions. Queries, raw SQL, timestamp comparisons, conflict handling, and database-error classification must work on both providers or branch explicitly. Review provider-aware exports, schema-parity coverage, and D1-to-Postgres migration code when affected.",
- "scope": [
- "src/db/**",
- "drizzle/**",
- "drizzle-pg/**",
- "drizzle.config.ts",
- "drizzle-prod.config.ts",
- "drizzle-pg.config.ts",
- "src/lib/auth.ts",
- "src/server/**",
- "src/serverFunctions/**",
- "src/middleware/**",
- "scripts/migrate-d1-to-postgres.ts"
- ],
- "severity": "high"
- },
- {
- "id": "postgres-entrypoint-scope",
- "rule": "Every Worker, scheduled handler, Durable Object method or callback, or other entry point that can reach provider-aware Drizzle db from @/db without a guaranteed ambient request scope must establish withPgClient. Durable Object ctx.storage and framework-managed agent message persistence are not @/db access and do not need this wrapper. Every Cloudflare Workflow step uses pgStep; raw step.do is confined to the pgStep helper. Do not assume AsyncLocalStorage scope survives across Workflow steps or Durable Object callbacks.",
- "scope": [
- "src/server.ts",
- "src/server/**",
- "src/serverFunctions/**",
- "src/routes/api/**",
- "src/middleware/**"
- ],
- "severity": "high"
- },
- {
- "id": "atomic-multi-write",
- "rule": "When partial completion would violate an invariant, use runBatch and build every statement from its tx callback. executeInBatches is only for work where each committed chunk is independently safe or idempotent; it is not an all-or-nothing transaction. Hard concurrency or capacity admission must use a database constraint, transactional conditional write, or rollback-safe insert-first admission rather than count-then-act. Bound large inArray and bulk-value parameter lists for D1. Retryable Workflow writes need deterministic IDs, stable unique keys, or conflict-safe upserts.",
- "scope": [
- "src/server/**",
- "src/serverFunctions/**",
- "src/middleware/**",
- "src/db/runBatch.ts"
- ],
- "severity": "high"
- },
- {
- "id": "billable-dataforseo-seam",
- "rule": "Every billable hosted DataForSEO call uses createDataforseoClient with organization billing context. Preserve provider billing path and cost metadata when a billed response later fails parsing or validation so metering still occurs. Do not charge cache hits or provider-unbilled failures. Self-hosted calls, free location data, tests using SDK models, and queued task_get collection are intentional exceptions.",
- "scope": [
- "src/server/lib/dataforseo/**",
- "src/server/lib/dataforseoBillingClassification.ts",
- "src/server/features/**",
- "src/server/mcp/**",
- "src/server/workflows/**",
- "src/serverFunctions/**"
- ],
- "severity": "high"
- },
- {
- "id": "billing-fails-closed",
- "rule": "Every billable hosted provider path must check organization credits before paid execution and meter provider-reported spend through the established shared credit-spend helper after execution. A failed gate prevents the paid call. A bounded partial-success API may surface a failed billing check as an explicit item-level error, but it must not present the paid operation as successful. Authorization failures terminate the request. Never use a stale-positive cache that can authorize access or spend that a live check would deny, and ensure retries or Workflow replays cannot omit metering or double-charge.",
- "scope": [
- "src/shared/billing*.ts",
- "src/shared/rank-tracking.ts",
- "src/server.ts",
- "src/server/billing/**",
- "src/server/lib/chatAgent.ts",
- "src/server/lib/dataforseoBillingClassification.ts",
- "src/server/lib/openrouter.ts",
- "src/server/lib/audit/lighthouse.ts",
- "src/server/lib/dataforseo/**",
- "src/server/features/**",
- "src/server/mcp/**",
- "src/server/workflows/**",
- "src/serverFunctions/**",
- "src/routes/api/autumn/**"
- ],
- "severity": "high"
- },
- {
- "id": "untrusted-outbound-url",
- "rule": "Before fetching a user-derived initial target, call normalizeAndValidateStartUrl and use manual redirect handling. A redirect followed directly must be revalidated with normalizeAndValidateStartUrl before the next fetch. The audit crawler may record a redirect and enqueue its target instead; every discovered link, sitemap entry, or redirect target admitted to that crawl frontier must pass isCrawlableUrl plus the crawl's same-origin and robots policy before fetch. Never use automatic redirect following for an untrusted URL. Fixed provider URLs are exempt from SSRF screening but still follow their shared client's timeout, retry, and error policy.",
- "scope": ["src/server/**", "src/serverFunctions/**", "src/routes/api/**"],
- "severity": "high"
- },
- {
- "id": "safe-external-links",
- "rule": "A clickable URL from API, crawl, LLM, or provider data must use getSafeExternalUrl, ExternalUrlCell, SafeExternalLink, or the shared Markdown and MARKDOWN_COMPONENTS renderer. Do not render untrusted values through a raw href or a new ad hoc scheme-check regex. Static developer-authored URLs are exempt.",
- "scope": ["src/client/**", "src/routes/**/*.tsx"],
- "severity": "high"
- },
- {
- "id": "behavior-evidence",
- "rule": "A change that alters authentication or authorization, billing or metering, persistence or query behavior, schema or migrations, provider serialization, Workflow retry or state transitions, or URL, search, and query behavior must include a focused behavioral test unless an existing test directly covers the changed branch or failure mode. A bug fix should reproduce the old failure. Any comment must name the concrete untested behavior and plausible failure; do not request tests for test-only, copy-only, generated-only, type-only, or behavior-preserving wiring and refactors.",
- "scope": [
- "src/**",
- "drizzle/**",
- "drizzle-pg/**",
- "drizzle.config.ts",
- "drizzle-prod.config.ts",
- "drizzle-pg.config.ts",
- "scripts/migrate-d1-to-postgres.ts"
- ],
- "severity": "medium"
- }
- ]
-}
diff --git a/.greptile/files.json b/.greptile/files.json
deleted file mode 100644
index 94d29188..00000000
--- a/.greptile/files.json
+++ /dev/null
@@ -1,171 +0,0 @@
-{
- "files": [
- {
- "path": "specs/0001-project-scoping-for-server-functions.md",
- "description": "Canonical server-function project-scoping design and exceptions.",
- "scope": [
- "src/serverFunctions/**",
- "src/server/mcp/**",
- "src/middleware/**"
- ]
- },
- {
- "path": "src/serverFunctions/middleware.ts",
- "description": "Established authenticated and active-project context middleware.",
- "scope": ["src/serverFunctions/**"]
- },
- {
- "path": "src/server/mcp/project-auth.ts",
- "description": "Canonical project authorization wrapper for MCP handlers.",
- "scope": ["src/server/mcp/**"]
- },
- {
- "path": "src/db/schema-parity.test.ts",
- "description": "Cross-dialect structural guarantees and mechanical DB guards. Coverage includes only explicitly registered schema modules, so verify that every affected module participates; passing this test does not prove semantic query or migration portability.",
- "scope": [
- "src/db/**",
- "drizzle/**",
- "drizzle-pg/**",
- "src/lib/auth.ts",
- "src/server/**",
- "src/serverFunctions/**",
- "src/middleware/**"
- ]
- },
- {
- "path": "src/db/schema.ts",
- "description": "Provider-aware schema export surface for SQLite and Postgres.",
- "scope": [
- "src/db/**",
- "src/lib/auth.ts",
- "src/server/**",
- "src/serverFunctions/**",
- "src/middleware/**"
- ]
- },
- {
- "path": "scripts/migrate-d1-to-postgres.ts",
- "description": "Operational D1-to-Postgres copy and transformation assumptions.",
- "scope": [
- "src/db/**",
- "drizzle/**",
- "drizzle-pg/**",
- "scripts/migrate-d1-to-postgres.ts"
- ]
- },
- {
- "path": "src/db/runBatch.ts",
- "description": "Provider-aware atomic batch and chunked batch semantics.",
- "scope": ["src/server/**", "src/serverFunctions/**", "src/middleware/**"]
- },
- {
- "path": "src/server/workflows/pgStep.ts",
- "description": "Required Postgres request scope for database-touching Workflow steps.",
- "scope": ["src/server/workflows/**"]
- },
- {
- "path": "src/db/pg/client.ts",
- "description": "Request-scoped Postgres client and withPgClient contract for Worker and Durable Object entrypoints.",
- "scope": [
- "src/server.ts",
- "src/server/**",
- "src/serverFunctions/**",
- "src/routes/api/**",
- "src/middleware/**"
- ]
- },
- {
- "path": "src/server/lib/dataforseo/client.ts",
- "description": "Single authenticated and metered DataForSEO consumer seam, including hosted and self-hosted behavior.",
- "scope": [
- "src/server/lib/dataforseo/**",
- "src/server/lib/dataforseoBillingClassification.ts",
- "src/server/features/**",
- "src/server/mcp/**",
- "src/server/workflows/**",
- "src/serverFunctions/**"
- ]
- },
- {
- "path": "src/server/lib/dataforseo/envelope.ts",
- "description": "Provider response validation and billed-failure metadata semantics. Known existing gap: parseTaskItems can currently discard billing metadata when a billed payload fails item validation; do not treat that path as precedent.",
- "scope": [
- "src/server/lib/dataforseo/**",
- "src/server/lib/dataforseoBillingClassification.ts",
- "src/server/features/**",
- "src/server/mcp/**",
- "src/server/workflows/**"
- ]
- },
- {
- "path": "src/server/billing/subscription.ts",
- "description": "Canonical hosted credit checks, balance reads, spend ordering, and usage tracking.",
- "scope": [
- "src/shared/billing*.ts",
- "src/shared/rank-tracking.ts",
- "src/server.ts",
- "src/server/billing/**",
- "src/server/lib/chatAgent.ts",
- "src/server/lib/dataforseoBillingClassification.ts",
- "src/server/lib/openrouter.ts",
- "src/server/lib/audit/lighthouse.ts",
- "src/server/lib/dataforseo/**",
- "src/server/features/**",
- "src/server/mcp/**",
- "src/server/workflows/**",
- "src/serverFunctions/**",
- "src/routes/api/autumn/**"
- ]
- },
- {
- "path": "src/server/billing/autumn.ts",
- "description": "Single lazy Autumn client and the restricted retry policy for non-idempotent track calls.",
- "scope": [
- "src/shared/billing*.ts",
- "src/shared/rank-tracking.ts",
- "src/server.ts",
- "src/server/billing/**",
- "src/server/lib/chatAgent.ts",
- "src/server/lib/dataforseoBillingClassification.ts",
- "src/server/lib/openrouter.ts",
- "src/server/lib/audit/lighthouse.ts",
- "src/server/lib/dataforseo/**",
- "src/server/features/**",
- "src/server/mcp/**",
- "src/server/workflows/**",
- "src/serverFunctions/**",
- "src/routes/api/autumn/**"
- ]
- },
- {
- "path": "src/server/lib/audit/url-policy.ts",
- "description": "Shared SSRF, hostname, and crawlable-URL policy.",
- "scope": ["src/server/**", "src/serverFunctions/**", "src/routes/api/**"]
- },
- {
- "path": "src/server/mcp/output-schemas.ts",
- "description": "MCP structured-output schemas, including the SDK-class passthrough constraint.",
- "scope": ["src/server/mcp/**"]
- },
- {
- "path": "src/server/mcp/instrumentation.ts",
- "description": "Required MCP handler instrumentation for error capture, timing, metadata, and output validation.",
- "scope": ["src/server/mcp/**"]
- },
- {
- "path": "src/client/components/table/url.tsx",
- "description": "Canonical client-side external URL sanitization and rendering helpers.",
- "scope": ["src/client/**", "src/routes/**/*.tsx"]
- },
- {
- "path": "src/client/components/SafeExternalLink.tsx",
- "description": "Shared safe renderer for untrusted external links outside table cells.",
- "scope": ["src/client/**", "src/routes/**/*.tsx"]
- },
- {
- "path": "src/client/components/Markdown.tsx",
- "description": "Shared Markdown renderer with safe handling for untrusted links.",
- "scope": ["src/client/**", "src/routes/**/*.tsx"]
- }
- ]
-}
diff --git a/AGENTS.md b/AGENTS.md
index 8b582e70..fe5d0074 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -34,6 +34,6 @@ Do not mine an entire session for papercuts or start a broad cleanup unless the
## Preserve review learnings
-After a merge-ready or other code review verifies a finding, use `maintain-greptile-rules` only when the finding exposes a recurring or high-risk repository invariant that existing `.greptile/` context and automated checks do not capture. Do not promote one-off bugs or preferences into permanent review rules.
+Reviewer context lives in `maintainer-docs/review-guidelines.md`: the hard invariants (tenant scoping, dual-dialect persistence, billing seams, SSRF handling) and the false-positive controls that keep reviewers from flagging intentional behavior. After a merge-ready or other code review verifies a finding, add to that file only when the finding exposes a recurring or high-risk repository invariant that existing context and automated checks do not capture. Do not promote one-off bugs or preferences into permanent review rules.
-Changes to `.greptile/**`, `AGENTS.md`, `CLAUDE.md`, `.agents/skills/**`, and `.github/**` alter the review control plane and must receive explicit maintainer review. CODEOWNERS requests that review; where repository settings allow, enable GitHub's requirement for code-owner approval. Repository-specific rules live in `.greptile/`; maintainers should configure or retain a minimal org-enforced Greptile baseline for external-contribution, secret, authentication, billing, CI, and rule-tampering risks. Agents should report an unverified or missing baseline and must not mutate dashboard or organization rules without explicit user authorization.
+Changes to `AGENTS.md`, `CLAUDE.md`, `.agents/skills/**`, `.github/**`, and `maintainer-docs/review-guidelines.md` alter the review control plane and must receive explicit maintainer review. CODEOWNERS requests that review; where repository settings allow, enable GitHub's requirement for code-owner approval.
diff --git a/CLAUDE.md b/CLAUDE.md
index 2016729e..55d7ccca 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -40,6 +40,6 @@ Do not mine an entire session for papercuts or start a broad cleanup unless the
## Preserve review learnings
-After a merge-ready or other code review verifies a finding, use `maintain-greptile-rules` only when the finding exposes a recurring or high-risk repository invariant that existing `.greptile/` context and automated checks do not capture. Do not promote one-off bugs or preferences into permanent review rules.
+Reviewer context lives in `maintainer-docs/review-guidelines.md`: the hard invariants (tenant scoping, dual-dialect persistence, billing seams, SSRF handling) and the false-positive controls that keep reviewers from flagging intentional behavior. After a merge-ready or other code review verifies a finding, add to that file only when the finding exposes a recurring or high-risk repository invariant that existing context and automated checks do not capture. Do not promote one-off bugs or preferences into permanent review rules.
-Changes to `.greptile/**`, `AGENTS.md`, `CLAUDE.md`, `.agents/skills/**`, and `.github/**` alter the review control plane and must receive explicit maintainer review. CODEOWNERS requests that review; where repository settings allow, enable GitHub's requirement for code-owner approval. Repository-specific rules live in `.greptile/`; maintainers should configure or retain a minimal org-enforced Greptile baseline for external-contribution, secret, authentication, billing, CI, and rule-tampering risks. Agents should report an unverified or missing baseline and must not mutate dashboard or organization rules without explicit user authorization.
+Changes to `AGENTS.md`, `CLAUDE.md`, `.agents/skills/**`, `.github/**`, and `maintainer-docs/review-guidelines.md` alter the review control plane and must receive explicit maintainer review. CODEOWNERS requests that review; where repository settings allow, enable GitHub's requirement for code-owner approval.
diff --git a/maintainer-docs/README.md b/maintainer-docs/README.md
index 6b9dced8..c6795abb 100644
--- a/maintainer-docs/README.md
+++ b/maintainer-docs/README.md
@@ -4,4 +4,6 @@ Shared, versioned documentation for people maintaining OpenSEO. Put engineering
User-facing documentation belongs in `docs/` or `web/content/docs/`. This directory is not published to the documentation site, but its contents are tracked in the repository and must not contain secrets.
+`review-guidelines.md` is the shared context for code reviewers, human and agent: hard invariants plus the false-positive controls that keep reviewers from flagging intentional behavior.
+
Create documents when they will help future maintenance or when explicitly requested. Keep task status, PR review notes, and validation results in the PR description. Log repository friction in `.agents/PAPERCUTS.md`.
diff --git a/.greptile/rules.md b/maintainer-docs/review-guidelines.md
similarity index 50%
rename from .greptile/rules.md
rename to maintainer-docs/review-guidelines.md
index 2eee28dd..4c728418 100644
--- a/.greptile/rules.md
+++ b/maintainer-docs/review-guidelines.md
@@ -1,4 +1,78 @@
-# OpenSEO review context
+# Review guidelines
+
+Context for anyone or any agent reviewing an OpenSEO change: the merge-ready
+subagents, `/code-review`, and human reviewers. It began life as the
+repository's Greptile configuration; Greptile is no longer wired to this
+repository, but the invariants and the false-positive controls still describe
+how the codebase is meant to work. Keep this file high-signal: a review finding
+is evidence to evaluate, not automatically a new rule. One-off bugs get a code
+fix and a regression test, deterministic checks belong in CI or lint, and only
+recurring or high-risk invariants earn a paragraph here.
+
+## Hard invariants
+
+Each of these has a concrete failure mode in production. A change inside the
+listed scope that weakens one is a blocker until it is justified.
+
+### Tenant and resource scoping
+
+Applies to: `src/lib/auth*.ts`, `src/server.ts`, `src/server/features/**`, `src/serverFunctions/**`, `src/server/mcp/**`, `src/routes/api/**`, `src/middleware/**`, `web/src/routes/api/**`.
+
+At each external trust boundary, establish the appropriate authorization before dispatch: session middleware for user endpoints, withMcpProjectAuth for project-scoped MCP handlers, signed state or verified provider signatures for callbacks and webhooks, and an explicit documented decision for public routes. Active project-scoped server functions use requireProjectContext with a validated projectId. Reads and mutations keyed by caller-controlled resource IDs must include the verified project, organization, or user in the query, or first authorize through a canonical parent lookup. Never trust a client-supplied organization, user, or billing identity. Archived or lifecycle resources may use requireAuthenticatedContext plus an explicit organization-scoped lookup. Bare-ID lookups are acceptable in trusted internal Workflow or Durable Object paths only when the upstream authorization invariant is explicit.
+
+### Normalized product data
+
+Applies to: `src/db/**`, `drizzle/**`, `drizzle-pg/**`, `src/server/**/repositories/**`, `src/server/**/*Repository.ts`.
+
+Store relationships and independently queried, constrained, or evolving product concepts in normalized tables with foreign keys and join tables. Do not put relational IDs in JSON or delimited text to avoid joins. JSON or text is acceptable for opaque provider payloads, immutable history, caches, or bounded non-relational value arrays when the reason is clear.
+
+### SQLite and Postgres parity
+
+Applies to: `src/db/**`, `drizzle/**`, `drizzle-pg/**`, `drizzle.config.ts`, `drizzle-prod.config.ts`, `drizzle-pg.config.ts`, `src/lib/auth.ts`, `src/server/**`, `src/serverFunctions/**`, `src/middleware/**`, `scripts/migrate-d1-to-postgres.ts`.
+
+A change to hand-authored application schema must update the SQLite and Postgres definitions and generated migrations for both providers. Preserve equivalent table, column, nullability, default, constraint, index, and foreign-key semantics while allowing intentional dialect-native representations and Better Auth exceptions. Queries, raw SQL, timestamp comparisons, conflict handling, and database-error classification must work on both providers or branch explicitly. Review provider-aware exports, schema-parity coverage, and D1-to-Postgres migration code when affected.
+
+### Postgres client scope at entry points
+
+Applies to: `src/server.ts`, `src/server/**`, `src/serverFunctions/**`, `src/routes/api/**`, `src/middleware/**`.
+
+Every Worker, scheduled handler, Durable Object method or callback, or other entry point that can reach provider-aware Drizzle db from @/db without a guaranteed ambient request scope must establish withPgClient. Durable Object ctx.storage and framework-managed agent message persistence are not @/db access and do not need this wrapper. Every Cloudflare Workflow step uses pgStep; raw step.do is confined to the pgStep helper. Do not assume AsyncLocalStorage scope survives across Workflow steps or Durable Object callbacks.
+
+### Atomic multi-statement writes
+
+Applies to: `src/server/**`, `src/serverFunctions/**`, `src/middleware/**`, `src/db/runBatch.ts`.
+
+When partial completion would violate an invariant, use runBatch and build every statement from its tx callback. executeInBatches is only for work where each committed chunk is independently safe or idempotent; it is not an all-or-nothing transaction. Hard concurrency or capacity admission must use a database constraint, transactional conditional write, or rollback-safe insert-first admission rather than count-then-act. Bound large inArray and bulk-value parameter lists for D1. Retryable Workflow writes need deterministic IDs, stable unique keys, or conflict-safe upserts.
+
+### The billable DataForSEO seam
+
+Applies to: `src/server/lib/dataforseo/**`, `src/server/lib/dataforseoBillingClassification.ts`, `src/server/features/**`, `src/server/mcp/**`, `src/server/workflows/**`, `src/serverFunctions/**`.
+
+Every billable hosted DataForSEO call uses createDataforseoClient with organization billing context. Preserve provider billing path and cost metadata when a billed response later fails parsing or validation so metering still occurs. Do not charge cache hits or provider-unbilled failures. Self-hosted calls, free location data, tests using SDK models, and queued task_get collection are intentional exceptions.
+
+### Billing fails closed
+
+Applies to: `src/shared/billing*.ts`, `src/shared/rank-tracking.ts`, `src/server.ts`, `src/server/billing/**`, `src/server/lib/chatAgent.ts`, `src/server/lib/dataforseoBillingClassification.ts`, `src/server/lib/openrouter.ts`, `src/server/lib/audit/lighthouse.ts`, `src/server/lib/dataforseo/**`, `src/server/features/**`, `src/server/mcp/**`, `src/server/workflows/**`, `src/serverFunctions/**`, `src/routes/api/autumn/**`.
+
+Every billable hosted provider path must check organization credits before paid execution and meter provider-reported spend through the established shared credit-spend helper after execution. A failed gate prevents the paid call. A bounded partial-success API may surface a failed billing check as an explicit item-level error, but it must not present the paid operation as successful. Authorization failures terminate the request. Never use a stale-positive cache that can authorize access or spend that a live check would deny, and ensure retries or Workflow replays cannot omit metering or double-charge.
+
+### Untrusted outbound URLs
+
+Applies to: `src/server/**`, `src/serverFunctions/**`, `src/routes/api/**`.
+
+Before fetching a user-derived initial target, call normalizeAndValidateStartUrl and use manual redirect handling. A redirect followed directly must be revalidated with normalizeAndValidateStartUrl before the next fetch. The audit crawler may record a redirect and enqueue its target instead; every discovered link, sitemap entry, or redirect target admitted to that crawl frontier must pass isCrawlableUrl plus the crawl's same-origin and robots policy before fetch. Never use automatic redirect following for an untrusted URL. Fixed provider URLs are exempt from SSRF screening but still follow their shared client's timeout, retry, and error policy.
+
+### Safe external links
+
+Applies to: `src/client/**`, `src/routes/**/*.tsx`.
+
+A clickable URL from API, crawl, LLM, or provider data must use getSafeExternalUrl, ExternalUrlCell, SafeExternalLink, or the shared Markdown and MARKDOWN_COMPONENTS renderer. Do not render untrusted values through a raw href or a new ad hoc scheme-check regex. Static developer-authored URLs are exempt.
+
+### Behavioral evidence for risky changes
+
+Applies to: `src/**`, `drizzle/**`, `drizzle-pg/**`, `drizzle.config.ts`, `drizzle-prod.config.ts`, `drizzle-pg.config.ts`, `scripts/migrate-d1-to-postgres.ts`.
+
+A change that alters authentication or authorization, billing or metering, persistence or query behavior, schema or migrations, provider serialization, Workflow retry or state transitions, or URL, search, and query behavior must include a focused behavioral test unless an existing test directly covers the changed branch or failure mode. A bug fix should reproduce the old failure. Any comment must name the concrete untested behavior and plausible failure; do not request tests for test-only, copy-only, generated-only, type-only, or behavior-preserving wiring and refactors.
## Review posture
@@ -6,7 +80,7 @@ OpenSEO receives external contributions, including untested coding-agent output.
- Prioritize concrete correctness, security, authorization, billing, data-loss, portability, and user-facing regressions.
- Scrutinize new dependencies and install scripts, CI permissions, external destinations, secret reads, authentication scopes, webhook and OAuth changes, billing bypasses, disabled tests, encoded or dynamic execution, and broad unrelated rewrites.
-- Treat changes to `.greptile/**`, `AGENTS.md`, `CLAUDE.md`, `.agents/skills/**`, and `.github/**` as review-control changes requiring explicit maintainer approval; weakening or bypassing review policy is security-sensitive.
+- Treat changes to `AGENTS.md`, `CLAUDE.md`, `.agents/skills/**`, and `.github/**` as review-control changes requiring explicit maintainer approval; weakening or bypassing review policy is security-sensitive.
- Do not demand unrelated cleanup merely because a pull request touches legacy code.
- Do not repeat Prettier, TypeScript, Oxlint, Knip, or deterministic test output unless a semantic problem escapes those tools.
- Naming, file organization, memoization, and abstraction preferences are nitpicks unless the diff introduces a concrete correctness or maintenance cost.