Protection System

Mark critical code as protected to prevent AI-induced regressions.

Why Protection Matters

AI assistants are powerful but can accidentally break working code:

Common AI Mistakes

  • • Refactoring a function that other code depends on
  • • Changing return types without updating callers
  • • Removing "unused" code that's actually used elsewhere
  • • "Simplifying" code that handles edge cases

Protection annotations tell AI: "This code works. Don't change it without good reason."

Protection Levels

@immutable

Immutable

Never modify. This code is battle-tested and any change risks breaking critical functionality.

/**
 * @immutable
 * REASON: Core authentication logic - validated through security audit
 * VALIDATED: 2025-01-10 by security team
 */
function validateJWT(token: string): TokenPayload {
  // ... tested, working code
}
@protected

Protected

Modify with caution. Changes require understanding dependencies and running tests.

/**
 * @protected
 * REASON: Used by 12 other components - changes have ripple effects
 * DEPENDENCIES: UserProfile, Dashboard, Settings, ...
 */
function formatUserData(user: User): FormattedUser {
  // ... working code with many dependents
}
@maintainable

Maintainable

Open for improvement. Can be refactored, but maintain the same interface and behavior.

/**
 * @maintainable
 * INTERFACE: Must accept (items: T[]) and return T[]
 * BEHAVIOR: Must preserve order, remove duplicates
 */
function deduplicateArray<T>(items: T[]): T[] {
  // Implementation can be improved
}

Adding Protection

Manual Annotation

Add JSDoc-style comments above functions:

/**
 * @protected
 * REASON: Payment processing - must not break
 * VALIDATED: 2025-01-15
 */
async function processPayment(amount: number): Promise<Receipt> {
  // ...
}

Using the /protect Command

Use the built-in skill to analyze and protect code:

/protect src/auth/

This scans the directory and suggests protection levels based on usage patterns.

How AI Respects Protection

When protection annotations are in your code, AI assistants like Claude Code and Cursor will:

  • Avoid modifying @immutable code entirely
  • Warn before suggesting changes to @protected code
  • Preserve interface and behavior for @maintainable code
  • Explain why they're avoiding certain changes

The annotations work because AI models are trained to recognize and respect these patterns when they see them in code.

Best Practices

  • 1.Don't over-protect - Only mark truly critical code
  • 2.Include REASON - Explain why code is protected
  • 3.Add VALIDATED date - Shows when protection was verified
  • 4.List DEPENDENCIES - Helps AI understand impact
  • 5.Review periodically - Remove protection when code can safely change