Enforce Strict Maintainability Standards

Flags one-off booleans and special cases in shared code, pass-through wrappers, copy-pasted logic, silent fallbacks, and files pushed past 1,000 lines.

What it flags

Flaggedsrc/checkout/shipping.ts
export function calculateShipping(
  order: Order,
  isExpress?: boolean,
  isAcmeCorp?: boolean,
  skipSurcharge?: boolean,
): number {
  let cost = order.weightKg * 1.5;
  if (isExpress) cost *= 2;
  // One customer's contract terms inside the shared pricing path
  if (isAcmeCorp && order.country === 'DE') cost = 0;
  if (!skipSurcharge && order.country !== 'US') cost += 12;
  if (isAcmeCorp && isExpress) cost = Math.min(cost, 25);
  return cost || 5;
}
Passessrc/checkout/shipping.ts
import { contractShippingRate } from './contract-rates';
import type { Order, ShippingSpeed } from './types';

const RATE_PER_KG = 1.5;
const EXPRESS_MULTIPLIER = 2;
const INTERNATIONAL_SURCHARGE = 12;
const MINIMUM_CHARGE = 5;

export function calculateShipping(order: Order, speed: ShippingSpeed): number {
  const contractRate = contractShippingRate(order, speed);
  if (contractRate !== undefined) return contractRate;

  let cost = order.weightKg * RATE_PER_KG;
  if (speed === 'express') cost *= EXPRESS_MULTIPLIER;
  if (order.country !== 'US') cost += INTERNATIONAL_SURCHARGE;
  return Math.max(cost, MINIMUM_CHARGE);
}

Why it matters

Most maintainability damage arrives one reasonable-looking special case at a time: a boolean parameter, a customer-specific branch, a fallback that hides an unclear invariant. Each change passes review because it is small and correct on its own, until a shared function has more modes than anyone can test. Flagging the regression when it is introduced, and naming the abstraction that would absorb it, costs far less than untangling it later.

Agent instructions

cubic checks every pull request against these instructions. Paste them into AGENTS.md or Cursor rules and your AI coding tool follows them while it writes code.

AGENTS.md

Add this section to AGENTS.md at the repository root. Codex, Cursor, and other AI coding tools read it.

## Enforce Strict Maintainability Standards

Review changes for structural maintainability regressions. Behavior-correct code can still violate this rule if it makes the codebase harder to understand, extend, or decompose.

Be ambitious about structural simplification. Look for reframings that delete whole branches, helpers, modes, conditionals, or layers instead of adding more of them. Prefer solutions that remove complexity rather than rearrange it.

Flag PRs that:
- Push a file from under 1,000 lines to over 1,000 without a strong reason or clear organization. Prefer extracting helpers, subcomponents, modules, or local abstractions first.
- Add ad-hoc conditionals, scattered special cases, one-off booleans, nullable modes, or flags into already busy shared flows instead of a dedicated abstraction, helper, state machine, policy object, or separate module.
- Introduce thin wrappers, identity abstractions, or pass-through helpers that add indirection without reducing complexity.
- Use brittle, ad-hoc, or "magic" mechanisms that hide simple data-shape assumptions.
- Rely on unnecessary casts, any, unknown, or optional parameters when a clearer type boundary or explicit model would simplify control flow.
- Use silent fallbacks to paper over unclear invariants instead of making the boundary explicit.
- Duplicate existing helpers or put logic in the wrong layer when a canonical utility or module already owns the concept.
- Leak feature-specific logic into general-purpose or shared paths.
- Copy-paste logic instead of extracting a shared helper or pure function.
- Handle narrow edge cases in the middle of an already busy function.
- Refactor in ways that move complexity around without reducing the number of concepts a reader must hold in their head.
- Add "temporary" branching that is likely to become permanent debt.
- Serialize obviously independent work or leave related updates in a non-atomic shape when a cleaner structure is available.

Prioritize findings in this order:
1. Structural code-quality regressions
2. Missed opportunities for dramatic simplification
3. Spaghetti or branching complexity increases
4. Boundary, abstraction, or type-contract problems
5. File-size and decomposition concerns
6. Modularity and legibility concerns

Do not flag cosmetic nits when a larger structural issue is present. Prefer a smaller number of high-conviction findings over a long list of minor notes. Only report violations on changed lines with clear evidence from the diff.

Checks every changed file.

Related agents

Included in the React, TypeScript, Node.js, Python, and Spring Boot code review standards.

Run this agent on every pull request

cubic reviews every pull request against the agents you turn on and comments on the lines that break them.

Catch this in your code