In the last video, we looked at why the contract.md file is the essential portable agreement for your project.

Today, we move from the agreement... to the enforcement.

The Problem: Context Drift

The theory is great. But in practice, as files get longer, AI agents can suffer from context drift. They start to forget the rules you established in the main contract.

That is where... Contract-Style Comments... come in.

Think of these as the guardrails that live directly inside your code. They aren't just for humans. They are anchors for the AI.

Lazy vs. Contract-Style

Let's look at a "lazy" comment versus a "contract" comment.

A lazy comment says: "check user logic here." An AI might see that and just... guess. It might delete a safety check or use the wrong library entirely.

But a Contract-Style comment uses a specific trigger. I use the square-bracket [CONTRACT] tag.

It defines explicit Preconditions... Invariants... and Post-conditions.

When an AI agent sees that tag, it is a signal to stop guessing and refer back to the primary source of truth: your contract.md file.

The Trinity of Collaboration

This creates a "Trinity" of collaboration:

  1. The contract.md: which is the Law.

  2. The quickstart.md: which is the Map.

  3. The Comments: which are the Guardrails.

This workflow makes AI collaboration safer, faster, and most importantly... repeatable across any editor or platform.

In the next walkthrough, I’ll show you how to set up your project map using quickstart.md.


Code Examples: The "Before and After"

Example 1: Security and Validation

BEFORE (Lazy Comment):

JavaScript
// Function: Process User
// Need to handle missing IDs or something.
function processUserData(userData) {
  console.log("Processing ID:", userData.id.toUpperCase());
}

AFTER (Contract-Style):

JavaScript
/**
 * [CONTRACT] Type Enforcement: processUserData
 *
 * PRECONDITION:
 * 1. 'userData' MUST be a non-null object.
 * 2. 'userData.id' MUST be a string (minLength: 1).
 * * REFER TO: contract.md#data-integrity
 */
function processUserData(userData) {
  if (!userData || typeof userData.id !== 'string') {
    throw new Error("Contract Violation: Invalid User Data.");
  }
  console.log("Processing ID:", userData.id.toUpperCase());
}

Example 2: API Constraints

BEFORE (Standard Explanation):

JavaScript
// Uses local storage to save the token.
function saveToken(token) {
  localStorage.setItem('auth_token', token);
}

AFTER (Contract-Style):

JavaScript
/**
 * [CONTRACT] API Constraint: saveToken
 *
 * INVARIANT: (Ref: contract.md#security-storage)
 * - Persisted data MUST NOT use 'localStorage'.
 * - All tokens MUST use 'sessionStorage'.
 */
function saveToken(token) {
  sessionStorage.setItem('myapp_auth_token', token);
}

I'm standing by to see that HTML! Once you tweak it, I can help you refine the CSS to make the [CONTRACT] tags look like actual stamps or warnings on the page.