Repository navigation
Expand file tree
/
Copy path.coderabbit.config.ts
More file actions
216 lines (199 loc) · 15 KB
/
Copy path.coderabbit.config.ts
File metadata and controls
216 lines (199 loc) · 15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/**
* CodeRabbit's configuration. CodeRabbit bundles and evaluates this file
* itself, in a sandbox with no network and an empty environment, so it may
* import only `@coderabbitai/config` and relative files. That package gives
* it types alone: `bun run typecheck` at the root checks this file, since
* CodeRabbit drops keys it doesn't know without a word. A committed
* `.coderabbit.yaml` would win over this file, so there must never be one.
*
* `@coderabbitai configuration` on a pull request shows what CodeRabbit
* resolved, and where each value came from.
*/
import { defineConfig, type CodeRabbitConfig } from "@coderabbitai/config";
type Reviews = NonNullable<CodeRabbitConfig["reviews"]>;
type PreMergeChecks = NonNullable<Reviews["pre_merge_checks"]>;
type CustomCheck = NonNullable<PreMergeChecks["custom_checks"]>[number];
/**
* What a review of each part of the repository holds it to, as each part's
* README and CI state it. One list, so a directory and its rules can't drift
* apart.
*/
const areas = [
{
dir: "core",
rules: [
"core is the data layer the Worker (web/) and the CLI share: Effect services over Postgres, the public contract (src/contract.ts) and the migrations. core/README.md is its documentation; flag a change that contradicts it or leaves it stale.",
"Every public read builds its statement from src/catalog.ts. Flag a file that states one of its rules itself (which evenings are public, their order, ahead or ended, ours, a lineup's order) outside src/catalog.ts; tests/catalog-guard.test.ts enforces it, and its list of exceptions only shrinks.",
"Every command that writes takes --dry-run, which writes nothing (a rolled-back transaction, or reads only). Where a command issues an approval token, the write takes --approve <token> and refuses anything that moved since the dry run.",
"planning is private: site_reader and site_sync are never granted the schema (tests/planning-privacy.test.ts), and no seed, fixture or backfill holds planning rows.",
'Migrations follow core/README.md, "Migrations": one file per change with the next id, listed in migrations/index.ts, forward only and never edited after merge.',
],
},
{
dir: "web",
rules: [
"web is the Cloudflare Worker that serves allthings.dev: the pages, the v1 API, the MCP server, the draft preview (src/preview/) and the hourly Luma sync (src/sync/).",
"Reads build on core/src/catalog.ts, and the surfaces must agree: web/tests/parity.test.ts holds list_events, /api/v1, the feeds, the pages and the sitemap to the same evenings, people and order.",
"The pages run no JavaScript; forms post to the same page. The one exception is the lab (src/pages/lab/): its variants marked `scripted` load the site's own module (src/client/lab.ts) under `script-src 'self'`, and fall back to a still composition without it. Canonical URLs, the sitemap, feeds and link previews always name https://allthings.dev (ORIGIN), on every stage.",
"The Web Worker never reads a draft: only the preview Worker does, as draft_collab, behind Cloudflare Access.",
"Rendered HTML must pass the XSS scan (bun run xss-scan): flag any value written into markup without escaping.",
],
},
{
dir: "infra",
rules: [
"infra declares allthings' Cloudflare resources with Alchemy v2 in alchemy.run.ts. infra/README.md is its documentation; flag a change that contradicts it or leaves it stale.",
"When alchemy.run.ts declares more, ci-token.json gains every permission group the new declarations need to deploy that it doesn't hold already; when they need none it lacks (a binding that provisions nothing through the API, such as an Analytics Engine dataset, needs none), it stays as it is.",
"Each database role holds exactly the grants its script lists (scripts/site-reader.ts, site-sync.ts, draft-collab.ts) and is made with SQL by the database owner, never in Neon's console or API.",
"Secrets are never printed: they are read with `op read` into variables, and scripts pass tokens through memory only.",
"The Sync Worker is production's one sync writer (workerWrites in src/sync.ts). A change to SYNC in src/sync.ts is a one-line pull request of its own.",
"Media objects are never overwritten: a replacement goes under a new key.",
],
},
{
dir: "cli",
rules: [
"cli is `allthings`, the command-line client for people and agents. It reads the public MCP server at https://allthings.dev/mcp (src/config.ts).",
"Its --json output and its exit codes (0 ok, 1 service error, 2 usage error, 3 no such evening) are a public contract. cli/src/schemas.ts is held to core/src/contract.ts by core/tests/contract.test.ts.",
"The old name keeps working: the `atw` bin and ATW_MCP_URL and ATW_VERSION print a note on stderr only, so scripts reading stdout don't break.",
],
},
{
dir: "plugins",
rules: [
"plugins/allthings is the allthings plugin for coding agents: the MCP server, two skills, and a Claude Code mod with themes and an output style. Its README is its documentation.",
"plugin.json and mcp.json (the Agent Plugins manifest) and .claude-plugin/plugin.json (Claude Code's) describe the same plugin.",
"The mod reads the MCP server mcp.json configures and stays quiet when the site can't be reached.",
'The output style changes only the voice: evenings rather than events, "I\'m in" and never RSVP.',
],
},
{
dir: "brand",
rules: [
"brand/foundations.md is the rules every page, cover and line of copy is checked against; when tokens or components disagree with it, it wins.",
"The name is allthings, one word, always lowercase. Hosting companies are never called sponsors.",
"Every color pairing meets its APCA target and WCAG 2.2 AA (the token tests check both), and color never carries meaning alone.",
"Marks are generated: brand/marks/generate.py writes them, and `uv run --locked generate.py --check` in brand/marks must pass.",
],
},
] as const;
const pathInstructions: Reviews["path_instructions"] = areas.map(
({ dir, rules }) => ({
path: `${dir}/**`,
instructions: rules.map((rule) => `- ${rule}`).join("\n"),
}),
);
/** Lines of a check's instructions, numbered so a failure can name one. */
const numbered = (lines: readonly string[]): string =>
lines.map((line, index) => `${index + 1}. ${line}`).join("\n");
/**
* Says which pull requests a check is for, so it holds even when it is
* attached without knowing the changed files (see the default export).
*/
const scoped = (scope: string, rest: string): string =>
`This check is for pull requests that change ${scope}. One that changes none of them passes.\n\n${rest}`;
/** One rule, documented in core/README.md, "Migrations". */
const migrationsCheck: CustomCheck = {
name: "Migrations reach production safely",
mode: "error",
instructions: scoped(
"core/migrations/",
`Production applies migrations by id and name (core/README.md, "Migrations"). Pass only if every item holds; otherwise fail and name each that doesn't.
${numbered([
"Forward only, and never edited after merge: no migration that exists on the base branch is modified, renamed or deleted. To change something, the pull request adds a migration.",
"Each new core migration is migrations/NNNN_short_name.ts with the next id after the last, default-exporting statements([...]), listed in core/migrations/index.ts with no id skipped. Its number must be free: CI's migration guard (Migration numbers) compares it with what production has applied and with other open pull requests, and when it fails, the migration takes the number it names.",
"No CREATE INDEX CONCURRENTLY: each migration runs in one transaction with the others pending.",
"The lines a migration creates are added to core/tests/fixtures/production-schema.txt.",
"The code already on main keeps running on the migrated schema: a column or table is added before code uses it, and a drop or rename is a later migration, after the code stops using the old shape.",
"A migration reaches production before the code that needs it, since every stage's Web Worker, pull request previews included, reads production's database. The pull request description must say whether this pull request's migrations must be applied to production before it merges, and if so, that they will be run as core/README.md, \"Running them\", says: once approved and green, from the final head commit, `bun run migrate --dry-run` against production lists exactly this pull request's migrations as pending, then `bun run migrate`, then merge, with nothing pushed in between. Fail if the description doesn't say either way.",
])}`,
),
};
/** Documented in infra/README.md and the headers of infra/scripts/. */
const productionScriptsCheck: CustomCheck = {
name: "Production writes take their planned path",
mode: "error",
instructions: scoped(
"infra/",
`Pass only if every item holds; otherwise fail and name each that doesn't.
${numbered([
"A script or command that writes to production shows what it will do before it does it, and checks the result afterwards, as the existing ones do: `bun run plan --stage prod` before `bun run deploy --stage prod`, and every deploy proves uploads work by storing and deleting one object; copy-media.ts's plan, copy and verify, which never overwrites or deletes; dry runs that roll back or only read. A new production write without a dry run or plan before it, or a change that skips one, fails.",
"Tests and rehearsals never write to production. Tests run on PGlite or a disposable Postgres (CORE_TEST_POSTGRES_URL) made with the scripts' own statements, and nothing in them reaches Luma or Discord. A rehearsal that reads production (bun run sync:rehearse, web/scripts/sync-dry-run.ts) writes nothing: its transaction always rolls back, and it runs as site_sync.",
"The Sync Worker is production's one sync writer (workerWrites in src/sync.ts). A change to SYNC in src/sync.ts is a one-line pull request of its own.",
"When alchemy.run.ts declares more, ci-token.json gains, in the same pull request, every permission group the new declarations need to deploy that it doesn't hold already. It stays as it is only when none of them needs one it lacks (a binding that provisions nothing through the API, such as an Analytics Engine dataset, needs none beyond the Workers Scripts Write that uploads the script).",
])}`,
),
};
/** Documented in infra/README.md and the headers of infra/scripts/. */
const secretsCheck: CustomCheck = {
name: "Secrets are never printed",
mode: "error",
instructions: scoped(
"core/migrations/ or infra/",
`Pass only if every item holds for the code, scripts, workflows and documentation this pull request changes; otherwise fail and name each that doesn't.
${numbered([
"Credentials are read from the allthings 1Password vault with `op read` into a variable or straight into the command's environment, as in NEON_READER_URL=$(op read \"op://allthings/allthings site_reader/credential\") bun run deploy. The one exception is the database owner's connection string, which is stored nowhere, the vault included (core/README.md, \"The studio's connection\"): it is for migrations and the role scripts alone, and the maintainer fetches it with neonctl straight into the command's environment, as in OWNER_URL=$(bunx neonctl@latest connection-string … --role-name neondb_owner …) bun infra/scripts/studio.ts --dry-run. Nor are the Cloudflare sign-ins vault items: Alchemy deploys with its profile's OAuth login (`--profile allthings`, infra/README.md) and the cf CLI with its own (`bunx cf … --profile allthings`), so a resource provider that takes Alchemy's `Credentials` in memory, or a documented cf command run signed in, meets this item. No secret value is written into the repository, a command line's output, a log or a pull request.",
"Every connection string or token passed to a command is captured, never echoed: nothing prints, logs or interpolates it into output (no echo, console.log, set -x or error message that includes it). A script that makes a credential sends it straight into a repository secret or 1Password, and a failing command shows its stderr alone.",
"A Worker that is missing a secret names the binding, never a value.",
])}`,
),
};
/** Documented in infra/README.md, core/README.md and infra/scripts/. */
const rolesCheck: CustomCheck = {
name: "Database roles hold only listed grants",
mode: "error",
instructions: scoped(
"core/migrations/ or infra/",
`Pass only if every item holds; otherwise fail and name each that doesn't.
${numbered([
"site_reader and site_sync only ever get the grants their scripts list explicitly: site_reader may only SELECT the tables the public site reads (and the migrator's record) and starts every transaction read-only; site_sync holds exactly SITE_SYNC_GRANTS, the column privileges the sync's statements use, with no DELETE and no table the sync doesn't touch. No migration or script grants them anything else: no GRANT on ALL TABLES, on a whole schema, to PUBLIC, or as a default privilege that would reach them.",
"draft_collab holds exactly DRAFT_COLLAB_GRANTS and DRAFT_COLLAB_FUNCTIONS, with no UPDATE, DELETE or TRUNCATE anywhere, and row security applies to it.",
"Roles are made with SQL by the database owner (infra/scripts/login-role.ts), never in Neon's console or API, whose roles join neon_superuser.",
"site_reader and site_sync are never granted the planning schema, and the privacy tests cover it: a change to planning's tables or to a role's grants keeps core/tests/planning-privacy.test.ts proving both roles are refused, and keeps core/tests/site-sync.test.ts and core/tests/draft-collab.test.ts checking that each role can do what it needs and nothing else.",
])}`,
),
};
export default defineConfig((ctx) => {
const changed = ctx.pr?.changedFiles;
// Only a resolved list proves what a pull request leaves alone. Without
// one, every check is attached, and each passes a pull request outside
// its scope.
const known = changed?.status === "resolved";
const touches = (...prefixes: string[]) =>
ctx.pr != null &&
(!known ||
changed.paths.some((path) =>
prefixes.some((prefix) => path.startsWith(prefix)),
));
const migrations = touches("core/migrations/");
const infra = touches("infra/");
const customChecks: CustomCheck[] = [
...(migrations ? [migrationsCheck] : []),
...(infra ? [productionScriptsCheck] : []),
...(migrations || infra ? [secretsCheck, rolesCheck] : []),
];
return {
early_access: true,
reviews: {
profile: "assertive",
request_changes_workflow: true,
review_details: true,
fail_commit_status: true,
auto_apply_labels: true,
auto_assign_reviewers: true,
auto_review: { drafts: true },
finishing_touches: {
unit_tests: { enabled: false },
simplify: { enabled: true },
},
path_instructions: pathInstructions,
...(customChecks.length > 0
? { pre_merge_checks: { custom_checks: customChecks } }
: {}),
},
issue_enrichment: {
auto_enrich: { enabled: true },
labeling: { auto_apply_labels: true },
},
};
});