project-brain 0.22.3 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +1 -1
  2. package/package.json +7 -7
  3. package/templates/skills/brain-audit/SKILL.md +174 -8
  4. package/templates/skills/brain-audit/references/abuse.md +34 -24
  5. package/templates/skills/brain-audit/references/accessibility.md +41 -21
  6. package/templates/skills/brain-audit/references/ai.md +28 -18
  7. package/templates/skills/brain-audit/references/analytics.md +73 -0
  8. package/templates/skills/brain-audit/references/api.md +27 -17
  9. package/templates/skills/brain-audit/references/backend.md +24 -16
  10. package/templates/skills/brain-audit/references/complexity.md +30 -17
  11. package/templates/skills/brain-audit/references/concurrency.md +28 -19
  12. package/templates/skills/brain-audit/references/consistency.md +32 -24
  13. package/templates/skills/brain-audit/references/contract-drift.md +30 -19
  14. package/templates/skills/brain-audit/references/cost.md +35 -24
  15. package/templates/skills/brain-audit/references/cross-surface-parity.md +70 -0
  16. package/templates/skills/brain-audit/references/database.md +42 -24
  17. package/templates/skills/brain-audit/references/dependencies-licensing.md +34 -23
  18. package/templates/skills/brain-audit/references/design-system.md +99 -0
  19. package/templates/skills/brain-audit/references/devops.md +38 -24
  20. package/templates/skills/brain-audit/references/documentation.md +35 -23
  21. package/templates/skills/brain-audit/references/failure.md +33 -21
  22. package/templates/skills/brain-audit/references/feature-flags.md +87 -0
  23. package/templates/skills/brain-audit/references/flow-integrity.md +58 -33
  24. package/templates/skills/brain-audit/references/frontend.md +36 -19
  25. package/templates/skills/brain-audit/references/functional.md +38 -17
  26. package/templates/skills/brain-audit/references/future.md +32 -12
  27. package/templates/skills/brain-audit/references/goal.md +19 -12
  28. package/templates/skills/brain-audit/references/i18n.md +37 -23
  29. package/templates/skills/brain-audit/references/idempotency.md +76 -0
  30. package/templates/skills/brain-audit/references/infrastructure.md +31 -22
  31. package/templates/skills/brain-audit/references/mobile.md +32 -23
  32. package/templates/skills/brain-audit/references/multi-tenancy.md +74 -0
  33. package/templates/skills/brain-audit/references/numeric.md +70 -0
  34. package/templates/skills/brain-audit/references/observability.md +36 -21
  35. package/templates/skills/brain-audit/references/packaging.md +27 -19
  36. package/templates/skills/brain-audit/references/performance.md +48 -21
  37. package/templates/skills/brain-audit/references/privacy.md +39 -25
  38. package/templates/skills/brain-audit/references/product.md +31 -12
  39. package/templates/skills/brain-audit/references/prompt-spec-gap.md +25 -18
  40. package/templates/skills/brain-audit/references/reachability.md +28 -20
  41. package/templates/skills/brain-audit/references/repo-history.md +65 -0
  42. package/templates/skills/brain-audit/references/scalability.md +35 -22
  43. package/templates/skills/brain-audit/references/security.md +50 -33
  44. package/templates/skills/brain-audit/references/state-model.md +73 -0
  45. package/templates/skills/brain-audit/references/supply-chain.md +64 -0
  46. package/templates/skills/brain-audit/references/temporal.md +66 -0
  47. package/templates/skills/brain-audit/references/testing.md +49 -24
  48. package/templates/skills/brain-audit/references/tooling-baseline.md +77 -0
  49. package/templates/skills/brain-audit/references/type-safety.md +68 -0
  50. package/templates/skills/brain-audit/references/versioning-compatibility.md +33 -22
  51. package/templates/skills/brain-audit/references/visual-design.md +89 -0
  52. package/templates/skills/brain-audit/references/web-metadata.md +72 -0
@@ -2,45 +2,55 @@
2
2
 
3
3
  What does running this bill? Gate: LLM/AI SDK calls, or metered cloud usage, was detected.
4
4
 
5
- Cost defects are unusual: they do not break anything, so nothing surfaces them until an invoice does. The audit is mechanical — find every metered operation, then find what bounds it.
5
+ Cost defects are unusual: they do not break anything, so nothing surfaces them until an invoice does. The audit is mechanical — find every metered operation, then find what bounds it. Most checks below establish an absence — no bound, no cache, no attribution — which is `read` once the probe confirms the thing is genuinely missing. A cost finding that only speculates about volume with no probe run is `inferred`, and per the Evidence Contract that caps it at `Medium` regardless of how large the invoice could theoretically be.
6
+
7
+ The FinOps Foundation's Framework (2026 refresh, now scoped beyond cloud to AI/ML, SaaS, and licensing spend) names this same arc as three phases run as a loop, not a one-time project: Inform (visibility — inventory and attribution, below), Optimize (cut waste), Operate (the ongoing bounds that keep it from recurring). Useful vocabulary when reporting a finding back to a team that already runs FinOps.
6
8
 
7
9
  ## Inventory the meters
8
10
 
9
- - [ ] Every operation that bills: model calls, per-request cloud services, egress, storage, function invocations, third-party API calls.
10
- - [ ] For each one, the unit it bills on — tokens, requests, gigabytes, seconds, rows scanned.
11
- - [ ] For each one, **what bounds it**. If the answer is "nothing", that is the finding regardless of current volume.
12
- - [ ] Metered calls reachable by an unauthenticated caller. Cross-reference `abuse.md` — that is someone else spending your money.
11
+ - [ ] Every operation that bills: `get_architecture` for the dependency manifest, then `search_code` the provider SDK imports — model calls, cloud services, payment SDKs, email/SMS providers. Build the meter list from what actually imports, not from what the project claims to use.
12
+ - [ ] For each one, the unit it bills on: `find_symbol`/read the client construction and call site to identify the billed dimension — tokens, requests, gigabytes, seconds, rows scanned.
13
+ - [ ] For each one, **what bounds it**: `search_code` near each call site for a limit, quota check, or cap (`maxTokens`, `limit`, `maxRetries`). If nothing is there, that is the finding regardless of current volume.
14
+ - [ ] Metered calls reachable by an unauthenticated caller: `trace_path` (or `find_callers`) from an unauthenticated route to the metered call. A path that exists here is `traced`, not `inferred` — that is someone else spending your money. Cross-reference `abuse.md`.
13
15
 
14
16
  ## Bounds
15
17
 
16
- - [ ] Metered calls inside loops. `find_callees` on the loop body — a per-item model call over an unbounded list is the classic runaway.
17
- - [ ] Input size bounded before a token-billed call, not after. Cross-reference `ai.md`.
18
- - [ ] Output length capped. An unbounded max-tokens setting bills for whatever the model decides to say.
19
- - [ ] Retries bounded and backed off. An unbounded retry against a failing paid endpoint bills for every attempt — this is both a cost and a reliability defect.
20
- - [ ] Fan-out bounded: one user action must not trigger an unbounded number of paid calls.
21
- - [ ] A hard ceiling exists somewhere — quota, budget alert, circuit breaker. Something that stops the bleeding without a human.
18
+ - [ ] Metered calls inside loops: `find_callees` on the loop body — a per-item model call over an unbounded list is the classic runaway.
19
+ - [ ] Input size bounded before a token-billed call, not after: read the call site's input construction for a truncation or size check before the payload is sent. Cross-reference `ai.md`.
20
+ - [ ] Output length capped: `search_code` for `max_tokens`/`maxOutputTokens` (or the SDK's equivalent) at each LLM call site. Missing, or set far above what the feature needs, bills for whatever the model decides to say.
21
+ - [ ] Retries bounded and backed off: `search_code` for a retry wrapper near each paid client call; read its config for max attempts and backoff. An unbounded retry against a failing paid endpoint bills for every attempt — this is both a cost and a reliability defect.
22
+ - [ ] Fan-out bounded: `find_callers` on each metered call to check whether it sits behind a loop over user-supplied input or a per-webhook handler — one user action must not trigger an unbounded number of paid calls.
23
+ - [ ] A hard ceiling exists somewhere, not only a notification: `search_code` for a rate limiter, spend cap, or circuit breaker that actually stops calls once a threshold is crossed, versus a budget alert that only notifies a human. A notify-only alert with nothing enforcing a stop is a weaker control than it looks — call that out distinctly from having neither, which is the stronger finding.
22
24
 
23
25
  ## Waste
24
26
 
25
- - [ ] Repeated identical paid calls with no cache. Cross-reference the caching checks in `performance.md`; here the missing cache costs money rather than latency.
26
- - [ ] Cache in place but the key omits a dimension, so it never hits.
27
- - [ ] The most expensive tier used for work a cheaper one handles — a large model for classification, a premium instance for a cron job.
28
- - [ ] Paid calls whose results are discarded, made speculatively, or duplicated across code paths.
29
- - [ ] Provisioned capacity far above observed use. Cross-reference `infrastructure.md`.
30
- - [ ] Storage with no retention policy — it only grows, and it bills monthly forever. Cross-reference `privacy.md`, where retention is also a compliance question.
31
- - [ ] Egress from chatty cross-region or cross-zone traffic.
27
+ - [ ] Repeated identical paid calls with no cache: `search_code` near each metered call site for a cache check preceding it, the same technique as the caching checks in `performance.md`. Here the missing cache costs money rather than latency.
28
+ - [ ] Cache in place but the key omits a dimension: `find_symbol` the cached call's signature, then read the key expression against every parameter that affects cost or output — a missing parameter means it never hits for varying inputs.
29
+ - [ ] The most expensive tier used for work a cheaper one handles: read the model/instance parameter at each call site (a literal model name, an instance size) and compare it against the task — a large model doing pure classification, a premium instance running a cron job.
30
+ - [ ] Paid calls whose results are discarded, made speculatively, or duplicated across code paths: `find_callers` on each metered call for a count greater than one with no shared cache between the call sites, or a returned value that is never assigned or used.
31
+ - [ ] Provisioned capacity far above observed use: read the IaC/deploy config for instance size or plan tier alongside any usage figure surfaced in code, config, or comments. This is usually `inferred` without a real usage number — say so. Cross-reference `infrastructure.md`.
32
+ - [ ] Storage with no retention policy: `search_code` for a TTL/retention/cleanup job on the bucket or table backing metered storage — it only grows, and it bills monthly forever. Cross-reference `privacy.md`, where retention is also a compliance question.
33
+ - [ ] Egress from chatty cross-region or cross-zone traffic: `search_code` for multi-region client construction or replication config paired with per-request (rather than batched) calls across that boundary.
32
34
 
33
35
  ## Development and test cost
34
36
 
35
- - [ ] Tests do not hit paid endpoints. A test suite that bills per run is a cost defect and a flake source. Verify the fakes are actually used.
36
- - [ ] Development and staging have their own, smaller budgets and cannot reach production-scale resources.
37
- - [ ] Nothing left running by default in non-production — idle instances bill exactly like busy ones.
37
+ - [ ] Tests do not hit paid endpoints: `search_code` test setup/fixtures for a mock or stub of each paid SDK (`jest.mock(`, a fake client); then check whether any `*.test.*` file still constructs the real client. A test suite that bills per run is a cost defect and a flake source.
38
+ - [ ] Development and staging have their own, smaller budgets: read the per-environment config (`.env.staging`, an environment-scoped IaC file) for instance size or quota values distinct from production.
39
+ - [ ] Nothing left running by default in non-production: `search_code` the deploy/IaC config for an auto-shutdown or scale-to-zero setting on non-production environments — its absence means idle instances bill exactly like busy ones.
38
40
 
39
41
  ## Attribution
40
42
 
41
- - [ ] Spend is attributable to a feature, tenant, or endpoint. Without attribution you can see the total and change nothing.
42
- - [ ] Usage is recorded per operation where it bills per unit, so a spike is diagnosable. Cross-reference `observability.md`.
43
- - [ ] Someone would notice a 10× increase within a day. If the only detection is the monthly invoice, that is the finding.
43
+ - [ ] Spend is attributable to a feature, tenant, or endpoint: `search_code` for a cost-allocation tag, a billing label, or a tenant/feature identifier passed alongside each metered call — the dimensions that cover most real chargeback needs are team, project, environment (dev/staging/prod), model-or-resource-name, and cost-centre. Without attribution across at least some of these you can see the total and change nothing.
44
+ - [ ] Usage is recorded per operation where it bills per unit: `search_code` for a usage metric emitted alongside each metered call, the same probe technique as the coverage check in `observability.md`. Without it, a spike is undiagnosable.
45
+ - [ ] Someone would notice a 10× increase within a day: `search_code` for a budget alert or spend-threshold config (an IaC alert resource, a billing webhook handler). If the only detection mechanism found is the monthly invoice, that is the finding.
46
+
47
+ ## Out of static reach
48
+
49
+ - The actual dollar amount billed — nothing here is checked against a real invoice.
50
+ - Real traffic volume through a metered path, and whether it is trending upward.
51
+ - Whether a cache or fallback actually hits at a meaningful rate in production.
52
+ - Whether a configured budget alert or quota has ever fired, versus merely being present.
53
+ - True cross-region egress volume and its cost.
44
54
 
45
55
  ## Severity guidance
46
56
 
@@ -57,4 +67,5 @@ Cost defects are unusual: they do not break anything, so nothing surfaces them u
57
67
  | Storage with no retention policy | Medium |
58
68
  | Expensive tier used for work a cheaper one handles | Medium |
59
69
  | No spend attribution per feature or tenant | Medium |
70
+ | Budget alert is notify-only, nothing enforces a stop | Medium |
60
71
  | Idle non-production resources left running | Low |
@@ -0,0 +1,70 @@
1
+ # Cross-Surface Parity
2
+
3
+ Do the rules stated on both sides still agree? Gate: two surfaces in one repo, or shared types across them.
4
+
5
+ `contract-drift.md` owns the *schema* — OpenAPI, GraphQL, protobuf, shared type definitions — the shape of the data. This module owns something a schema cannot capture: **behavioural rules restated in prose or logic on both sides**, each internally valid, that have quietly diverged. A schema says a field is a string; it says nothing about the regex both sides are supposed to enforce on it. That gap is this module's entire scope — do not re-run `contract-drift.md`'s field-shape checks here.
6
+
7
+ Every check below has the same shape: find the rule on surface A, find its counterpart on surface B, and diff the literal values. A rule that exists on only one side is also a finding — not a match to compare, but a gap.
8
+
9
+ ## Validation rules stated twice
10
+
11
+ - [ ] Max/min length constraints: `search_code` for the field name near a length check on both client and server (`maxLength`, `.max(`, `LENGTH(`, a schema `maxLength`). Diff the numbers literally — a client capping a bio at 500 characters while the server truncates or rejects at 280 is a rule that only ever fires on one side.
12
+ - [ ] Regex/format validation — email, phone, postal code, username character set — implemented independently on both sides. `search_code` for `RegExp(`, a bare `/.../ ` pattern literal, or the field name near `.test(`/`.match(` on each side; two regex literals for "valid email" are almost never identical, so diff them character by character, not by eye.
13
+ - [ ] Required-field sets: `search_code` the field name near `required`/`.notNull()`/a schema's `required: true` on the server, and near a form library's `required` prop or resolver rule on the client. A field optional client-side while the server 400s without it is bad UX, not a bug; the server accepting it as optional while the client always sends it masks a real gap — nothing ever exercises the server's optional path.
14
+ - [ ] Allowed value ranges — quantity minimums/maximums, rating scales, percentage bounds — `search_code` the field name near `min`/`max`/`.gte(`/`.lte(` on both sides and diff the literal numbers; duplicated magic numbers with no shared source are the finding even before they diverge.
15
+ - [ ] File upload limits: size cap and accepted MIME/extension list, checked independently client-side (for UX) and server-side (for safety). The server-side check is the one that matters for security — cross-reference `security.md` if the client is the *only* place a limit is enforced.
16
+
17
+ ## Enum and constant sets
18
+
19
+ - [ ] A set of allowed values — category names, role names, tier names — hardcoded independently in a client dropdown and a server validator. `search_code` the value literals (`'admin'`, `'editor'`, `'viewer'`) on both sides and diff the member lists. This is the same shape as `state-model.md`'s duplicated-state-set check; if the set in question is a status/state field, report it there instead and cross-reference from here.
20
+ - [ ] Feature-gating constants (plan limits, quota thresholds): `search_code` the numeric literal or its named constant on both sides — a client-side display string ("up to 10 seats") copy-pasted rather than imported from the server's own limit means an updated limit changes enforcement but not what the UI tells the user.
21
+ - [ ] Rate-limit or quota numbers shown to the user (`"5 requests remaining"`): `search_code` the display string's source value and diff it against the server's actual configured limit — the UI promises a number the backend doesn't honour, in either direction.
22
+
23
+ ## Error codes
24
+
25
+ - [ ] Enumerate every error code the server emits (`search_code` the error-construction sites, an error-code enum, or a error-response builder) and every code the client branches on (`search_code` the client's error-handling switch). Diff in both directions:
26
+ - A code the server emits that the client has no branch for — falls through to a generic error message, losing whatever specific recovery UX was intended.
27
+ - A code the client explicitly handles that the server never actually emits — dead client logic, and a signal the server-side behaviour changed without the client being updated.
28
+
29
+ ## Defaults
30
+
31
+ - [ ] The same field defaulting to different values on client and server: `search_code` the field name near a form's `defaultValue`/initial state on the client and near `DEFAULT`/`??`/a schema default on the server, and diff the literal values. Only reachable in practice when the client fails to send the field at all (a bug elsewhere), but when it happens the two defaults silently disagree.
32
+
33
+ ## Query parameter contracts
34
+
35
+ - [ ] Pagination: page-size defaults and maximums, cursor vs. offset — what the client sends versus what the server actually reads and clamps to. A client requesting `pageSize=200` against a server capping at 50 works, silently, until someone assumes the requested size was honoured.
36
+ - [ ] Sorting and filtering parameter names and accepted values: `search_code` the query-param name the client builds (`sort=`, `filter[`) versus the param name the server's route handler actually reads — a client sending `sort=createdAt` against a server that only recognises `sortBy` fails silently to a default sort, not an error.
37
+
38
+ ## Authorisation decided twice
39
+
40
+ - [ ] A permission or role check performed client-side to hide a UI element: `search_code` the role/permission constant on the client, then `find_callers`/`trace_path` from the corresponding write endpoint on the server to confirm the same check exists there too. An unenforced server-side check means the client-side check is the *only* thing stopping the action, which anyone can bypass by calling the API directly. **Escalates to `security.md`**; report the finding there with a pointer back here for the parity evidence.
41
+ - [ ] The inverse, less common but real: server-side authorisation stricter than what the client believes, so the client renders an action it cannot actually complete, and the user hits an opaque 403 mid-flow.
42
+ - [ ] Session/token expiry duration: `search_code` the client's refresh-timer literal (a hardcoded interval, "refresh every 55 minutes") against the server's actual configured TTL (a JWT expiry constant, a session config value) — a client refreshing too late gets a surprise 401 mid-action instead of a seamless renewal.
43
+
44
+ ## Formatting rules
45
+
46
+ - [ ] Date/time formatting and timezone handling: `search_code` for a date library import (`date-fns`, `dayjs`, `Intl.DateTimeFormat`) on each surface and check whether both call the same shared formatting function/config, or each reimplement "display in user's local time" with different rounding/timezone assumptions.
47
+ - [ ] Number and currency formatting: `search_code` for `toFixed(`, `Intl.NumberFormat`, or a hand-rolled currency string-builder on each surface — locale, decimal separator, currency symbol placement and rounding mode should trace to one shared formatter, not one per surface.
48
+ - [ ] Rounding and precision: `search_code` the monetary calculation's rounding call (`toFixed(2)`, `Math.round`, a decimal library's rounding mode) on the server and diff it against the client's own rounding of the same value. A calculation rounding to 2 decimal places on the server while the client displays more (or fewer) produces a total that visibly doesn't match its line items. Cross-reference `numeric.md` for the calculation-correctness angle; this module only checks whether the *rule* is stated consistently.
49
+
50
+ ## Out of static reach
51
+
52
+ - Whether an observed divergence has actually caused a production incident, versus being latent.
53
+ - Runtime-only defaults supplied by infrastructure (a load balancer, an API gateway) that never appear in either codebase.
54
+ - Behaviour of third-party SDKs embedded in either surface that apply their own undocumented validation.
55
+ - Locale-dependent formatting differences that only manifest for locales not exercised by any test or by the auditor's reading.
56
+
57
+ ## Severity guidance
58
+
59
+ | Situation | Severity |
60
+ |---|---|
61
+ | Client-only authorisation check with no server-side enforcement | Critical (defer to `security.md`) |
62
+ | Error code the client branches on that the server never emits | High |
63
+ | Validation rule enforced client-side only, unenforced server-side | High |
64
+ | File upload limit enforced only on the client | High |
65
+ | Diverged max/min or regex validation between surfaces | Medium |
66
+ | Server error code with no client handling (falls to generic message) | Medium |
67
+ | Diverged default value between client and server | Medium |
68
+ | Pagination/sort parameter mismatch silently falling back to a default | Medium |
69
+ | Formatting/rounding rule reimplemented per surface | Medium |
70
+ | Duplicated enum/constant set not yet diverged | Low |
@@ -6,42 +6,57 @@ The highest-value checks here are the declared-vs-used inverse pairs from `reach
6
6
 
7
7
  ## Schema integrity
8
8
 
9
- - [ ] Every table has a primary key.
10
- - [ ] Foreign keys are declared as constraints, not merely implied by a naming convention. An implied relationship is not enforced by anything.
11
- - [ ] Nullability is deliberate. A nullable column that code never checks for null is a latent crash.
12
- - [ ] Enum-like columns are constrained (check constraint, enum type, or lookup table), not free-text.
13
- - [ ] Unique constraints exist wherever the code assumes uniqueness. `search_code` for the lookup that assumes one row.
14
- - [ ] Timestamps record what they claim — created vs. updated vs. deleted — and are timezone-explicit.
9
+ The database is the only enforcement point every writer passes through — a second application, an ops script, or a migration backfill all bypass application-level validation but not a constraint. An invariant the business genuinely cannot tolerate being violated (uniqueness, a required relationship, a valid enum) belongs here even when the app also checks it for UX; app-only enforcement of a hard invariant is one bypass away from silent corruption, and that is the finding, not a style preference.
10
+
11
+ - [ ] Every table has a primary key. Read the migration files for a `CREATE TABLE` with no `PRIMARY KEY`/`id` column, or `find_symbol` each model and confirm a primary key field.
12
+ - [ ] Foreign keys are declared as constraints, not merely implied by a naming convention. `search_code` for a `_id`-suffixed column and confirm a matching `REFERENCES`/`FOREIGN KEY` in the same migration — a naming match with no constraint is the finding.
13
+ - [ ] Nullability is deliberate. `find_callers` on a nullable column's accessor and confirm at least one caller null-checks it; if none do, either the column should be `NOT NULL` or every caller is a latent crash.
14
+ - [ ] Enum-like columns are constrained (check constraint, enum type, or lookup table), not free-text. Read the column type in the migration, then `search_code` the value literals used against it — a `VARCHAR`/`TEXT` column code treats as a fixed set of values is unconstrained.
15
+ - [ ] Unique constraints exist wherever the code assumes uniqueness. `search_code` for a `.findOne`/`SELECT ... LIMIT 1` filtered on the column, then confirm a `UNIQUE` constraint exists on it in the migration.
16
+ - [ ] Timestamps record what they claim — created vs. updated vs. deleted — and are timezone-explicit. Read the migration's column type (`TIMESTAMP` vs `TIMESTAMPTZ`/`WITH TIME ZONE`), then `find_callers` on the model's update method to confirm `created_at`/`updated_at`/`deleted_at` are set where their names promise.
15
17
 
16
18
  ## Schema vs. code
17
19
 
18
- - [ ] Every column read or written by code exists in a migration. **Code reading a column no migration creates is `Critical`.**
19
- - [ ] Every column a migration creates is read or written somewhere. Unused columns are `Low`, but they are also where stale assumptions hide.
20
- - [ ] Model/entity definitions match the migrated schema — types, nullability, defaults. Drift here means the ORM lies to every caller.
21
- - [ ] Indexes exist for the columns actual queries filter and sort on, and no index exists for columns nothing queries.
20
+ - [ ] Every column read or written by code exists in a migration. `search_code` the field name across the codebase, then confirm a migration creates it. **A code reference with no creating migration is `Critical`.**
21
+ - [ ] Every column a migration creates is read or written somewhere. `search_code` the field name; zero hits outside the migration and model definition make it `Low`, but keep the candidate list — stale assumptions cluster around these columns.
22
+ - [ ] Model/entity definitions match the migrated schema — types, nullability, defaults. `find_symbol` the model and diff its field declarations against the migration that created the table.
23
+ - [ ] Indexes exist for the columns actual queries filter and sort on, and no index exists for columns nothing queries. `search_code` for `WHERE`/`.where(`/`ORDER BY` on a column, then confirm an index migration covers it; the inverse — an index `search_code` finds no matching query for — is the companion finding.
22
24
 
23
25
  ## Query quality
24
26
 
25
- - [ ] No query is built by string concatenation with a value that came from outside. Parameterised or nothing. This is `Critical` and belongs in `Security` too — report it once, cross-reference.
26
- - [ ] No N+1: a query inside a loop over a previous query's results. `find_callees` on the loop body.
27
- - [ ] `SELECT *` in code that only needs two columns — cheap to fix, and it silently widens every future schema change's blast radius.
28
- - [ ] Queries that can scan the whole table have a bound, or a stated reason they cannot grow.
29
- - [ ] Aggregations and counts on large tables are not on a request's hot path.
27
+ - [ ] No query is built by string concatenation with a value that came from outside. `search_code` for string concatenation or template-literal interpolation immediately adjacent to a query-execution call. This is `Critical` and belongs in `Security` too — report it once, cross-reference.
28
+ - [ ] No N+1: a query inside a loop over a previous query's results. `find_callees` on the loop body for a second query call, and confirm the outer loop iterates over the first query's result set.
29
+ - [ ] `SELECT *` in code that only needs two columns. `search_code` for `SELECT *`/`.select()` with no column list, then `find_callers` to see how few fields the caller actually destructures.
30
+ - [ ] Queries that can scan the whole table have a bound, or a stated reason they cannot grow. `search_code` for a query against a large table with no `LIMIT`/indexed `WHERE` clause.
31
+ - [ ] Aggregations and counts on large tables are not on a request's hot path. `find_callers` on the handler wrapping a `COUNT`/`GROUP BY` query — a request-path caller with no cache in front of it is the finding.
32
+ - [ ] No implicit type coercion defeats an index. `search_code` a `WHERE`/filter comparing a column against a literal of a different type — a `text`/`varchar` column compared to a bare integer, or (MySQL) a string column compared to a numeric literal. Check which side the coercion falls on before flagging it: when the *column* is cast to match the literal, a plain index on that column can't be used; when the *constant* is cast to match the column instead (Postgres does this for `int_col = '123'`), the index still applies.
30
33
 
31
34
  ## Migrations
32
35
 
33
- - [ ] Migrations are ordered, immutable once applied, and recorded. An edited applied migration means two environments have different schemas with the same version.
34
- - [ ] Every migration is reversible, or its irreversibility is stated.
35
- - [ ] Destructive migrations (drop, rename, narrow a type) are separated from deploys that still read the old shape. A single-step rename breaks every running instance of the previous version.
36
- - [ ] Data migrations are idempotent and bounded — a single `UPDATE` over a large table locks it.
37
- - [ ] Migrations run to completion or roll back; there is no half-applied resting state.
36
+ The safest sequencing for a schema change with more than one deploy in flight is expand → migrate → contract ("parallel change"): add the new shape without touching the old one, dual-run until every writer and reader has moved, then remove the old shape in its own later migration. In practice, the step teams skip is the last one — the contract migration — because the visible benefit already shipped once expand and migrate land, and cleanup has no deadline pulling it forward. An expand-phase artefact (dual-write code, a paired old/new column, a compatibility shim) with no tracked removal is therefore a specific, checkable finding, not a hypothetical one.
37
+
38
+ - [ ] Migrations are ordered, immutable once applied, and recorded. Read the migrations directory listing for a gap in the sequence, or a timestamp/hash that does not match the tool's recorded checksum, where the tool tracks one.
39
+ - [ ] An expand-phase artefact has a tracked contract-phase removal. `search_code` for a dual-write (the old column/field still being written alongside a newer one), a compatibility shim, or an `_old`/`_new`/`_v2`-style column pair, then check for a follow-up migration, ticket reference, or dated TODO that removes it. One with no removal plan anywhere in the repo is the finding this pattern is named for.
40
+ - [ ] Every migration is reversible, or its irreversibility is stated — but a `down` that would silently discard the data the forward migration removed is not a real reversal. Read each migration file for a `down`/`Down`/rollback method on a destructive statement; current practice favours roll-forward (a new migration that fixes the mistake) over a `down` that pretends a lossy change is undoable. What matters is not the presence of a rollback method but whether the destructive step is isolated in its own migration — see the next check — so its blast radius is contained even without one.
41
+ - [ ] Destructive migrations (drop, rename, narrow a type) are separated from deploys that still read the old shape. Read the migration for `DROP`/`RENAME COLUMN`/type-narrowing statements, then `search_code` for the old column name still referenced elsewhere in the same change.
42
+ - [ ] Data migrations are idempotent and bounded. Read the migration for an `UPDATE`/backfill statement with no `WHERE` scoping it and no batching — a single unbounded `UPDATE` over a large table locks it.
43
+ - [ ] Migrations run to completion or roll back; there is no half-applied resting state. Read the migration runner/tool config for transactional-DDL support; its absence on a multi-statement migration is the finding.
44
+ - [ ] A DDL statement that blocks writes for a full table scan is not run against a table expected to be large when a non-blocking form was available. This is version-dependent. **Postgres (11+):** `ADD COLUMN ... DEFAULT <const>` is safe (no rewrite, catalog-only); a volatile default, a combined `NOT NULL DEFAULT`, or `ALTER COLUMN TYPE` forces a full-table rewrite under `ACCESS EXCLUSIVE`; `SET NOT NULL` skips its scan only (12+) if a validated `CHECK (col IS NOT NULL)` already exists — the safe path is `ADD CONSTRAINT ... NOT VALID` then `VALIDATE CONSTRAINT` (which only takes `SHARE UPDATE EXCLUSIVE`) then `SET NOT NULL`; a bare `CREATE INDEX` blocks writes where `CREATE INDEX CONCURRENTLY` does not. **MySQL (8.0.12+):** `ADD`/`DROP COLUMN` at the end of the table qualifies for `ALGORITHM=INSTANT` (no rebuild); `ADD INDEX` supports `ALGORITHM=INPLACE, LOCK=NONE`; most column type changes fall back to `ALGORITHM=COPY`, which blocks concurrent writes for the full rebuild. Read the migration for the blocking form where the non-blocking one applied, or for an explicit `ALGORITHM`/`LOCK` clause missing entirely — an unspecified algorithm can silently fall back to `COPY`.
38
45
 
39
46
  ## Transactions and integrity
40
47
 
41
- - [ ] Related writes share a transaction.
42
- - [ ] Read-modify-write is protected against concurrent execution — optimistic version column, row lock, or an atomic single statement.
43
- - [ ] Cascade behaviour is declared deliberately, not inherited by default. An unintended cascade delete is `Critical`.
44
- - [ ] Soft deletes are respected by every read path. `find_callers` on the model — one query missing the `deleted_at` filter resurrects deleted data.
48
+ - [ ] Related writes share a transaction. `find_callees` on a function performing more than one write and confirm they sit inside one `BEGIN`/transaction call, not sequential independent calls.
49
+ - [ ] Read-modify-write is protected against concurrent execution. `search_code` for a read followed by a write of the same row with no version-column check, row lock, or atomic single statement between them.
50
+ - [ ] Cascade behaviour is declared deliberately, not inherited by default. Read the foreign key's `ON DELETE`/`ON UPDATE` clause in the migration; an unstated cascade is `Critical`.
51
+ - [ ] Soft deletes are respected by every read path. `find_callers` on the model's query method and confirm each includes the `deleted_at IS NULL`/equivalent filter — one caller missing it resurrects deleted data.
52
+
53
+ ## Out of static reach
54
+
55
+ - Actual query plans (`EXPLAIN`/`EXPLAIN ANALYZE`) — this module reads query and schema source, it cannot execute a query the way a live planner would.
56
+ - Real table cardinality — whether "large table" means ten rows or ten million; the migration and query source carry no row counts.
57
+ - Actual lock contention and duration under concurrent write load.
58
+ - Whether an index is actually used by the planner versus merely present — an unused index looks identical to a used one from source.
59
+ - Replication lag and its effect on read-after-write consistency.
45
60
 
46
61
  ## Severity guidance
47
62
 
@@ -56,4 +71,7 @@ The highest-value checks here are the declared-vs-used inverse pairs from `reach
56
71
  | Missing index on a filtered column of a growing table | Medium |
57
72
  | N+1 query | Medium |
58
73
  | Unconstrained enum-like column | Medium |
74
+ | Blocking DDL run against an unbounded table when a non-blocking form exists | Medium |
75
+ | Implicit type coercion on the column side of a filter, defeating an index | Medium |
59
76
  | Column created by a migration that nothing reads | Low |
77
+ | Expand-phase artefact with no tracked contract-phase removal | Low |
@@ -2,45 +2,55 @@
2
2
 
3
3
  Gate: a lockfile or dependency manifest was detected.
4
4
 
5
- Two questions: is each dependency worth its cost, and are you allowed to ship it?
5
+ Two questions: is each dependency worth its cost, and are you allowed to ship it? Lifecycle scripts, lockfile-integrity attacks (dependency confusion, typosquatting), SBOM, and provenance — OWASP Top 10:2025's A03 "Software Supply Chain Failures" — are `supply-chain.md`'s territory — this module stops at whether a dependency is declared, used, licensed, and current, and does not repeat that work.
6
6
 
7
7
  ## Declared vs. used
8
8
 
9
9
  Both directions, and both matter — this is the `reachability.md` inverse-gap check applied to the manifest.
10
10
 
11
11
  - [ ] Declared but never imported. Dead weight in the install, and an attack surface for nothing. `search_code` each package name to confirm.
12
- - [ ] **Imported but not declared.** Resolving today only because a transitive dependency hoisted it; the next lockfile update breaks the build or, worse, production. This is `High`.
13
- - [ ] Runtime dependencies sitting in the dev section — fails only for consumers. Cross-reference `packaging.md`.
14
- - [ ] Dev dependencies imported by runtime code.
12
+ - [ ] **Imported but not declared.** Resolving today only because a transitive dependency hoisted it; the next lockfile update breaks the build or, worse, production. `search_code` each top-level import against the manifest — rule out inline: language builtins and core modules (`fs`, `path`, `os`, `net`, and their equivalents) are not dependencies, exclude them before flagging. This is `High`.
13
+ - [ ] Runtime dependencies sitting in the dev section — fails only for consumers. Read the manifest's `dependencies` vs `devDependencies`, cross-check every runtime-imported package against the section it's declared in. Cross-reference `packaging.md`.
14
+ - [ ] Dev dependencies imported by runtime code. `search_code` runtime source files — excluding test and build directories — for imports of packages declared only under `devDependencies`.
15
15
 
16
16
  ## Weight
17
17
 
18
- - [ ] Large dependencies used for a fraction of their surface. Name the specific function used and the size of what it drags in.
19
- - [ ] Dependencies that duplicate the standard library or the runtime.
20
- - [ ] Multiple packages solving the same problem — two date libraries, two HTTP clients, two validation libraries. Pick one; the other is a migration nobody finished.
21
- - [ ] Duplicate versions of the same package in the lockfile. Bloat, and a source of "instanceof fails across copies" bugs.
18
+ - [ ] Large dependencies used for a fraction of their surface. For each suspect dependency, `search_code` how many distinct exports are actually imported; name the specific function used and cite `file:line`, not just the dependency name.
19
+ - [ ] Dependencies that duplicate the standard library or the runtime. Cross-check the import list against the language's builtins — a padding or deep-clone library where the runtime already ships one is the concrete case.
20
+ - [ ] Multiple packages solving the same problem — two date libraries, two HTTP clients, two validation libraries. Cross-check the manifest for known-overlapping categories, name the specific packages found, then `search_code` each one's actual call sites — a decommissioned one still imported somewhere is the migration nobody finished. Pick one; the other is dead weight with a name.
21
+ - [ ] Duplicate versions of the same package in the lockfile. Read the lockfile for multiple resolved versions of one package name — bloat, and a source of "instanceof fails across copies" bugs.
22
22
 
23
23
  ## Health
24
24
 
25
- - [ ] Unmaintained dependencies — last release long past, open issues unanswered, archived repository. Note the migration cost now, before it is forced.
26
- - [ ] Single-maintainer packages on the critical path. Not a defect, but a risk worth naming.
27
- - [ ] Known vulnerabilities. Cite the advisory; do not guess. Cross-reference `security.md`.
28
- - [ ] Postinstall scripts. Each one executes arbitrary code at install time — enumerate them.
25
+ Live CVE and exploitability status needs a registry query this module cannot make and goes stale the moment it's written down — that belongs under Out of static reach, not here. What is checkable from source is whether the project has a *process* for staying current.
26
+
27
+ - [ ] Declared update process. `search_code` for `renovate.json`, `.github/dependabot.yml`, or a documented update cadence in `CONTRIBUTING` — the same signal OpenSSF Scorecard's `Dependency-Update-Tool` check looks for. Its absence means updates are ad hoc, and the first one will be a forced multi-major jump across the whole tree at once.
28
+ - [ ] Version gap as a staleness signal. Read the manifest's declared range against the lockfile's actually-resolved version for each critical-path dependency — a large gap between what's allowed and what's installed is a signal worth naming, but true maintenance status (last release, open-issue backlog, archival) needs the registry and belongs under Out of static reach.
29
+ - [ ] Audit step in CI. `search_code` the pipeline for `npm audit`, `pip-audit`, `osv-scanner`, or an equivalent step — cross-reference `devops.md`. Confirm the process exists; do not cite a specific advisory from here, that's a live lookup this module doesn't make.
30
+ - [ ] Single-maintainer packages on the critical path. Not a defect, but a risk worth naming when found — read the manifest's declared critical dependencies for a known single-maintainer project. This approximates what OpenSSF Scorecard's `Maintained` and `Contributors` checks measure directly against live registry and commit data; without that data, name the package and let the reader verify.
29
31
 
30
32
  ## Version discipline
31
33
 
32
- - [ ] Lockfile present and committed. Absent lockfile means no two installs are the same build.
33
- - [ ] Ranges are deliberate. Floating major versions on a runtime dependency accept breaking changes automatically.
34
- - [ ] Pins with a comment explaining a workaround — verify the workaround is still needed. Cross-reference `future.md`.
35
- - [ ] Something updates dependencies on a cadence. No process means the first update will be a forced emergency across many majors at once.
34
+ - [ ] Lockfile present and committed. Confirm via the file listing or `get_architecture`, then check `.gitignore` does not exclude it. Absent lockfile means no two installs are the same build.
35
+ - [ ] Ranges are deliberate. Read each *runtime* dependency's version specifier — `^`, `*`, or no pin at all accepts breaking changes automatically and is the finding. Rule out inline: the same pattern on a devDependency carries materially lower risk since it never ships; note the distinction rather than flagging both at the same severity.
36
+ - [ ] Pins with a comment explaining a workaround. `search_code` for comments like "pinned because" or "TODO remove pin" near a version pin, then check whether the constraint they describe still holds. Cross-reference `future.md`.
37
+ - [ ] Something updates dependencies on a cadence. This is the same Renovate/Dependabot check made under Health — cross-reference it rather than re-checking.
36
38
 
37
39
  ## Licensing
38
40
 
39
- - [ ] Every dependency's license is known, including transitive ones. Unknown is not the same as permissive.
40
- - [ ] No license incompatible with how this project ships. Copyleft in a proprietary distributed product is the classic case — flag it and say what it obligates rather than giving legal advice.
41
- - [ ] The project's own declared license matches the file it ships and the headers in its source.
42
- - [ ] Attribution requirements are met where licenses require notices.
43
- - [ ] Vendored or copy-pasted third-party code retains its original license and attribution. `search_code` for pasted headers.
41
+ - [ ] Every dependency's license is known, including transitive ones. Read the manifest/lockfile license fields, or a generated license report if one exists in-repo — a checked-in SBOM (CycloneDX ≥1.4 or SPDX ≥2.3 both carry a license field per component) counts as this report — and flag any `UNKNOWN` or missing entry. Unknown is not the same as permissive.
42
+ - [ ] No license incompatible with how this project ships. For each declared license, name the specific obligation it carries — GPL requires derivative-works disclosure, for instance — checked against the project's own declared license and its shipping model (proprietary vs. open, distributed vs. SaaS). Flag the obligation; do not give a legal verdict.
43
+ - [ ] The project's own declared license matches the file it ships and the headers in its source. Read the `LICENSE` file, compare it against the manifest's `license` field and any source header block.
44
+ - [ ] Attribution requirements are met where licenses require notices. `search_code` for a `NOTICE` or `THIRD_PARTY_LICENSES` file; confirm one exists when any dependency's license requires it.
45
+ - [ ] Vendored or copy-pasted third-party code retains its original license and attribution. `search_code` for `Copyright` strings inside `vendor/`, `third_party/`, or other copied directories.
46
+
47
+ ## Out of static reach
48
+
49
+ - Live vulnerability and exploitability status of any dependency — registry-dependent, and stale the moment it's recorded.
50
+ - Actual maintenance activity and community health of a dependency — last release date, issue-response time, contributor count — needs registry or GitHub API data.
51
+ - Whether a copyleft obligation has actually been triggered by how the code is combined and distributed — needs legal judgement, not a source read.
52
+ - Real bundle-size impact of a heavy dependency — needs a build to measure.
53
+ - Whether a vendored license notice is legally sufficient — the file existing is checkable; its adequacy is not.
44
54
 
45
55
  ## Severity guidance
46
56
 
@@ -48,11 +58,12 @@ Both directions, and both matter — this is the `reachability.md` inverse-gap c
48
58
  |---|---|
49
59
  | Dependency license incompatible with how the project ships | Critical |
50
60
  | Imported package absent from the manifest | High |
51
- | Known vulnerability in a reachable dependency | High |
61
+ | No declared process for staying current (no Renovate/Dependabot, no audit step in CI) | High |
52
62
  | No lockfile committed | High |
53
63
  | Runtime dependency in the dev section | High |
54
64
  | Vendored third-party code with attribution stripped | High |
55
- | Unmaintained dependency on the critical path | Medium |
65
+ | Large version gap between allowed range and resolved version on a critical-path dependency | Medium |
66
+ | Single-maintainer package on the critical path | Medium |
56
67
  | Unknown license on any dependency | Medium |
57
68
  | Floating major version on a runtime dependency | Medium |
58
69
  | Two packages solving the same problem | Low |
@@ -0,0 +1,99 @@
1
+ # Design System
2
+
3
+ Does the UI agree with itself? Gate: a UI framework was detected.
4
+
5
+ `consistency.md` asks whether the *code* agrees with itself. This module asks the same question of the *rendered surface*: are colours, spacing, type, radii, shadows and component variants drawn from one declared vocabulary, or reinvented per file?
6
+
7
+ The method is the same as `consistency.md` — comparison, not taste. Find the declared vocabulary, then find what ignores it. **A value that deviates from the dominant pattern is the finding; the dominant pattern is the standard even if you would have chosen differently.**
8
+
9
+ Everything here is verifiable from source. Design-system audits are usually described as a visual exercise — screenshot every component across breakpoints and record mismatches. That needs a running app. It is not needed: the defects have textual signatures, because the values are literals in the code. What genuinely cannot be checked statically is listed at the end, and naming it is a coverage-gap finding, not a silent omission.
10
+
11
+ ## Establish the vocabulary first
12
+
13
+ Nothing below means anything until you know what the project declared. Find it before you judge anything.
14
+
15
+ - [ ] Locate the token source. `search_code` for `tailwind.config`, `@theme`, `:root {`, `--color-`, `theme.ts`, `tokens.json`, `styled-components` theme, `ThemeData`, `MaterialTheme`, or the platform equivalent.
16
+ - [ ] Record the declared scales — spacing steps, type sizes, radii, shadow levels, breakpoints, colour roles — by reading the token source located above and enumerating its declared values verbatim. This list is the yardstick for every later check.
17
+ - [ ] **If no token source exists at all, that is the finding — `High` — and the rest of the module becomes "every value is ad hoc", not thirty separate deviations.** Report it once, with the count of distinct raw values `search_code` turns up for a single representative category (colour is usually the fastest to count) as evidence of the scale that never existed.
18
+
19
+ ## Token adoption
20
+
21
+ Score it; do not eyeball it. Per category — colour, spacing, radius, typography, shadow, z-index:
22
+
23
+ ```
24
+ adoption = token_references / (token_references + hardcoded_literals)
25
+ ```
26
+
27
+ - [ ] Report the number **per category with raw counts**, using the probes below for each category. A project can sit at 95% on colour and 20% on spacing, and a single average hides exactly the category that needs work.
28
+ - [ ] Hardcoded colour outside the token file: `search_code` for `#[0-9a-fA-F]{3,8}`, `rgba?(`, `hsla?(`. Each hit outside the declared source is a missing token.
29
+ - [ ] Hardcoded dimension: `search_code` for a raw `[0-9]+px` inside `margin`, `padding`, `gap`, `width`, `height`, or `font-size` declarations. Each hit outside the token scale is a missing token.
30
+ - [ ] Escape-hatch syntax in utility-class stacks: `search_code` for the pattern `-[` inside class strings (`w-[137px]`, `text-[#3b82f6]`, `mt-[13px]`) and count hits against total class-string occurrences project-wide. A handful is pragmatism. A third of the class strings means there is no system left, only a colour-coordinated accident.
31
+ - [ ] A literal repeated in more than one file is a token that was never created. `search_code` a suspect hex or pixel value found above across the repo — two or more files sharing the exact same raw value is the finding; report it once with every site, not once per site.
32
+
33
+ ## Scale discipline
34
+
35
+ - [ ] Spacing values come from a constrained scale (4 / 8 / 12 / 16 / 24 / 32 / 48 / 64 …). Cross-reference the raw `px` hits from Token adoption above and list every value that is not on the declared scale, or — absent a declared scale — not a multiple of a consistent base unit, and where each occurs.
36
+ - [ ] Type sizes come from one scale — a modular ratio or an explicit named ramp. `search_code` for `font-size` declarations outside the token file and list each resolved value; a size that appears exactly once across the codebase is drift, not a considered addition.
37
+ - [ ] Radii, border widths, shadow levels and z-index each have a bounded set. `search_code` for `z-index:`/`z-` utility classes and list every distinct raw value found outside the token file — more than a handful means there is no stacking policy and overlays will fight. Repeat the sweep for `border-radius` and `box-shadow`.
38
+ - [ ] Breakpoints are declared once and referenced, not retyped per component. `search_code` for `@media` queries or breakpoint utility prefixes (`sm:`, `md:`, `lg:`) carrying a raw pixel value instead of the declared token — each is a breakpoint retyped locally. Device-named breakpoints (iPhone, iPad widths) are a further smell — breakpoints belong where the layout breaks.
39
+
40
+ ## Token architecture
41
+
42
+ Where a three-tier structure exists — primitive → semantic → component — the tiering is only real if it is respected:
43
+
44
+ - [ ] A token references **exactly one tier below**. `find_symbol` each component-tier token and read what it resolves to — a value pointing straight at a hex or raw px (skipping the semantic tier), or reaching sideways into an unrelated branch, defeats the indirection the tiers exist to provide.
45
+ - [ ] Semantic and component tokens are named for their **role**, never their value. `search_code` semantic/component token names for a colour or size word baked in (`red`, `blue`, `large`) — `color.brand.red` is a primitive name wearing semantic clothes: harmless at tier 1, a trap at tier 2, where the whole point of the name is that the value can change.
46
+ - [ ] No two tokens hold near-identical values. Read the token file's colour values sorted — `#3b82f6` and `#3b82f7` sitting as separate named entries is drift, not intent.
47
+ - [ ] Deprecated tokens are marked and have a stated replacement, not silently kept alive by their remaining call sites. `search_code` for a `deprecated`/`@deprecated` marker in the token file, then `find_callers` each marked token — live call sites with no stated replacement is a trap for the next person who reaches for it.
48
+
49
+ ## Two sources of truth
50
+
51
+ The most expensive defect in this module, and the easiest to miss by reading one file:
52
+
53
+ - [ ] Only one place defines each foundation. `search_code` for a second file matching the same token-source patterns as the one located earlier — a `variables.scss` **and** a `tailwind.config`/`@theme` block both declaring brand colours will drift, and by the time anyone notices, both are load-bearing. Diff them literally, value by value.
54
+ - [ ] Design-tool exports (Figma tokens, Style Dictionary output) are generated into the codebase, not hand-maintained alongside it. `search_code` for a Style Dictionary config or a generated-file header comment in the token file — its absence alongside evidence of a Figma-variables integration means the file is hand-edited and will drift from the design tool silently.
55
+ - [ ] Theme values are not duplicated between web and native targets in a shared-code project. `search_code` the same colour-role name across the web token file and the native theme file (`Colors.ts`, platform theme) — a role holding different values on each platform is cross-surface drift; cross-reference `contract-drift.md`.
56
+
57
+ ## Component vocabulary
58
+
59
+ - [ ] One implementation per concept. `search_code` a distinctive class string or markup shape from a button, card, input, modal — duplicates are the finding. Cross-reference the copy-paste check in `frontend.md`; report the *divergence in values* here and the *structural duplication* there.
60
+ - [ ] Variants live in one place — a variant helper (`cva`, `tv`, or the project's own), not inline ternaries on `className`. `search_code` for a variant-helper import versus a ternary chain building `className` inside a component — inline variant logic means the variant set is defined N times and will diverge.
61
+ - [ ] Conditional classes go through a merge helper (`cn()` / `clsx` + `twMerge` or equivalent). `search_code` for `cn(`, `clsx(`, `twMerge(` versus a template-literal or `+` concatenation building a class string — without a merge helper, a conditional class silently loses to source order and the bug looks like "sometimes the style does not apply".
62
+ - [ ] Component APIs for the same role have the same shape. `find_symbol` each component sharing a role (button, input, badge) and diff their prop names for the same concept — a `size` prop that takes `sm|md|lg` in one component and `small|medium|large` in another is two vocabularies for one idea.
63
+
64
+ ## Theming
65
+
66
+ - [ ] Every colour role has a counterpart in every declared theme. `search_code` for `dark:` / `[data-theme]` / `prefers-color-scheme` and check the coverage is total, not partial — a half-themed surface is worse than an unthemed one, because it only breaks on some screens.
67
+ - [ ] Theme switching goes through tokens, not through per-component conditionals. `search_code` for `theme ===`/`isDarkMode ?` branching inline in component style logic, as opposed to a CSS variable or token swap driven by a theme class/attribute — a per-component conditional is a theme implemented N times instead of once.
68
+ - [ ] Contrast holds **in every theme**, not just the default one. Extract the colour pairs from each theme found via the token source above and compute the ratio per pair — do not eyeball it. Cross-reference `accessibility.md`.
69
+
70
+ ## Enforcement
71
+
72
+ - [ ] A lint rule enforces what the token system declares. `search_code` for a stylelint rule (a `declaration-property-value-disallowed-list` on hex/`color`) or an eslint rule on Tailwind arbitrary values (`eslint-plugin-tailwindcss`) — its absence means the discipline above is a convention nobody enforces at commit time.
73
+ - [ ] CI actually runs that rule. `search_code` the CI workflow files for the lint command found above — a rule declared in config but absent from the CI script list runs only on a developer's machine, if at all. A declared standard nothing enforces is optional, and optional standards decay. Cross-reference the tooling check in `consistency.md`.
74
+ - [ ] Visual-regression or theme coverage exists in the test suite. `search_code` for a visual-regression tool import (Chromatic, Percy, Playwright's `toHaveScreenshot`) or a theme-toggle test — its absence is reported under `testing.md`, not silently skipped here.
75
+
76
+ ## Out of static reach
77
+
78
+ - Rendered contrast where colours composite — overlays, opacity, gradients.
79
+ - Reflow at 320px and at 200% zoom.
80
+ - Perceived hierarchy and visual balance.
81
+ - Whether the dominant pattern is the *intended* one, when no token source exists to declare it.
82
+ - Whether a value flagged as off-scale is a deliberate, argued exception or an unnoticed accident — source shows the deviation, not the intent behind it.
83
+
84
+ ## Severity guidance
85
+
86
+ | Situation | Severity |
87
+ |---|---|
88
+ | Two conflicting sources of truth for the same foundation | High |
89
+ | No spacing or type scale declared anywhere — every value ad hoc | High |
90
+ | A theme declared but only partially covered | High |
91
+ | Token adoption below ~50% in a category | Medium |
92
+ | Duplicate implementations of one component that have diverged | Medium |
93
+ | Variant logic inline instead of centralised | Medium |
94
+ | Off-scale one-off values in a minority of components | Medium |
95
+ | No merge helper for conditional classes | Medium |
96
+ | Unbounded z-index set | Medium |
97
+ | Redundant near-identical tokens | Low |
98
+ | Semantic token named after its value | Low |
99
+ | Token lint rule declared but not run in CI | Low |