# How Ponytail Enforces Its Code Generation Rules: Inside the Lazy-Senior-Dev Pipeline

> Discover how Ponytail enforces its lazy senior developer code generation rules using a three-layered pipeline runtime tracking dynamic injection and CI checks for strict adherence.

- Repository: [DietrichGebert/ponytail](https://github.com/DietrichGebert/ponytail)
- Tags: internals
- Published: 2026-08-29

---

**Ponytail enforces its "lazy senior developer" philosophy through a three-layered enforcement pipeline that combines runtime mode tracking, dynamic rule-set injection into every prompt, and CI-time integrity checks to ensure every LLM response adheres to strict code-generation constraints.**

The **DietrichGebert/ponytail** repository implements a novel approach to controlling AI-assisted coding. Rather than relying on post-generation linting, Ponytail intercepts prompts at the system level and prepends a filtered rule block derived from [`SKILL.md`](https://github.com/DietrichGebert/ponytail/blob/main/SKILL.md), guaranteeing that every generated snippet respects YAGNI, minimalism, and safety invariants before the LLM ever processes the request.

## The Three-Pillar Enforcement Architecture

Ponytail’s enforcement mechanism rests on three tightly coupled subsystems that operate during the prompt lifecycle. Each component handles a distinct phase: rule preparation, session state management, and configuration resolution.

### Rule-Set Builder and Mode Filtering

At the heart of the enforcement engine sits [`hooks/ponytail-instructions.js`](https://github.com/DietrichGebert/ponytail/blob/main/hooks/ponytail-instructions.js). This module exposes `getPonytailInstructions()`, which loads the canonical [`SKILL.md`](https://github.com/DietrichGebert/ponytail/blob/main/SKILL.md) file, strips its YAML frontmatter, and filters the content based on the active intensity level.

The `filterSkillBodyForMode()` function parses the markdown table structure and example blocks to return only the rules relevant to the current mode—`lite`, `full`, or `ultra`. If the skill file is unreadable, the system falls back to a hard-coded rule set embedded directly in the source, ensuring the enforcement pipeline never runs dry.

```js
// hooks/ponytail-instructions.js
function filterSkillBodyForMode(body, mode) {
  const effectiveMode = normalizeMode(mode) || DEFAULT_MODE;
  const withoutFrontmatter = String(body || '').replace(/^---[\s\S]*?---\s*/, '');

  return withoutFrontmatter
    .split(/\r?\n/)
    .filter(line => {
      const tableLabel = line.match(/^\|\s*\*\*(.+?)\*\*\s*\|/);
      if (tableLabel) {
        const labelMode = normalizeMode(tableLabel[1].trim());
        if (labelMode) return labelMode === effectiveMode;
      }
      const exampleLabel = line.match(/^-\s*([^:]+):\s*"/);
      if (exampleLabel) {
        const labelMode = normalizeMode(exampleLabel[1].trim());
        if (labelMode) return labelMode === effectiveMode;
      }
      return true; // keep ordinary rule bullets
    })
    .join('\n');
}

```

This function ensures that a `/ponytail lite` request receives only the foundational rules, while `/ponytail ultra` injects the complete ladder of heuristics and safety checks.

### Mode Tracking and Prompt Injection

The [`hooks/ponytail-mode-tracker.js`](https://github.com/DietrichGebert/ponytail/blob/main/hooks/ponytail-mode-tracker.js) module handles command parsing and state persistence. Using the `UserPromptSubmit` hook, it detects slash commands like `/ponytail lite` or `/ponytail full`, validates the requested intensity, and stores the mode via `setMode()`.

Crucially, this hook intercepts **every** subsequent prompt. Before the request reaches the LLM, the tracker calls `writeHookOutput()` to prepend the filtered instruction block returned by `getPonytailInstructions()`. For the Qoder backend, it folds the mode-change confirmation into the same JSON payload, ensuring the user receives immediate feedback while the rule block remains invisible in the context window.

```js
// hooks/ponytail-mode-tracker.js
if (/^[/@$]ponytail/.test(prompt)) {
  const parts = prompt.split(/\s+/);
  const cmd = parts[0].replace(/^[@$]/, '/');
  const arg = parts[1] || '';

  if (cmd === '/ponytail' && arg !== 'default') {
    let mode = { lite: 'lite', full: 'full', ultra: 'ultra', off: 'off' }[arg];
    if (mode) {
      setMode(mode);
      writeHookOutput('UserPromptSubmit', mode,
        `PONYTAIL MODE CHANGED — level: ${mode}`);
    }
  }
}
...
// Later, for each prompt (including Qoder)
if (currentMode && currentMode !== 'off') {
  const header = modeSwitched ?
    `PONYTAIL MODE CHANGED — level: ${currentMode}\n\n` : '';
  writeHookOutput('UserPromptSubmit', currentMode,
    header + getPonytailInstructions(currentMode));
}

```

Because the rules are injected as **system prompt context**, the LLM treats them as non-negotiable constraints rather than suggestions.

### Configuration and Default Resolution

The [`hooks/ponytail-config.js`](https://github.com/DietrichGebert/ponytail/blob/main/hooks/ponytail-config.js) module provides the entry point for determining baseline behavior. Its `getDefaultMode()` function resolves the startup intensity from environment variables, user configuration files, or built-in fallbacks.

The `normalizeMode()` function acts as a gatekeeper, restricting persistent defaults to runtime-compatible levels: `off`, `lite`, `full`, or `ultra`. The `review` mode—intended for session-only analysis—cannot be set as a default, preventing accidental persistence of verbose diagnostic outputs.

```js
// hooks/ponytail-config.js (conceptual usage)
const DEFAULT_MODE = 'lite';
const VALID_MODES = ['off', 'lite', 'full', 'ultra'];
const SESSION_ONLY_MODES = ['review'];

export function normalizeMode(input) {
  const normalized = input?.toLowerCase().trim();
  if (VALID_MODES.includes(normalized)) return normalized;
  if (SESSION_ONLY_MODES.includes(normalized)) return 'full'; // fallback
  return null;
}

```

## How the Rule Pipeline Works at Runtime

The enforcement flow follows a strict sequence that guarantees zero-leakage of unconstrained prompts:

1. **Startup**: `getDefaultMode()` initializes the session to `lite`, `full`, or `ultra` based on configuration.
2. **Command Interception**: When the user types `/ponytail ultra`, the mode tracker validates the input, calls `setMode('ultra')`, and emits a confirmation.
3. **Prompt Preparation**: Every subsequent user prompt triggers the hook, which retrieves the filtered rule block via `getPonytailInstructions(currentMode)`.
4. **Context Injection**: The hook prepends the rule block to the system context, ensuring the LLM receives the constraints before any user code or natural language instructions.

This architecture means the LLM **never** receives a request without the full set of Ponytail constraints, effectively enforcing the "lazy senior developer" philosophy at the transport layer.

## Ensuring Rule Integrity Across Deployments

Ponytail maintains consistency across multiple IDE plugins—Cursor, Windsurf, Copilot, and Qoder—through a CI-time validation script.

### The CI Sanity Check

[`scripts/check-rule-copies.js`](https://github.com/DietrichGebert/ponytail/blob/main/scripts/check-rule-copies.js) runs during the build process to guarantee that every copy of the rules stays byte-for-byte identical to the canonical source. It reads [`AGENTS.md`](https://github.com/DietrichGebert/ponytail/blob/main/AGENTS.md) (the short copy) and compares it against host-specific copies located in directories like `.cursor/rules/ponytail.mdc` and [`.windsurf/rules/ponytail.md`](https://github.com/DietrichGebert/ponytail/blob/main/.windsurf/rules/ponytail.md).

The script also validates that invariant phrases—such as "lazy senior developer" and "prevents data loss"—appear unchanged in both [`SKILL.md`](https://github.com/DietrichGebert/ponytail/blob/main/SKILL.md) and [`AGENTS.md`](https://github.com/DietrichGebert/ponytail/blob/main/AGENTS.md). Any drift triggers a build failure, forcing maintainers to propagate changes across all targets.

```js
// scripts/check-rule-copies.js
const copies = [
  ['.cursor/rules/ponytail.mdc', stripFrontmatter],
  ['.windsurf/rules/ponytail.md', text => text.trim()],
  // … other hosts
];
for (const [relPath, normalize] of copies) {
  const actual = normalize(read(relPath));
  if (actual !== canonical) {
    console.error(`${relPath} drifted from AGENTS.md`);
    failed = true;
  }
}

```

This prevents configuration rot and ensures that a developer using the Cursor extension receives the exact same safety invariants as a developer using the Qoder backend.

## Summary

- **Dynamic filtering**: `filterSkillBodyForMode()` in [`hooks/ponytail-instructions.js`](https://github.com/DietrichGebert/ponytail/blob/main/hooks/ponytail-instructions.js) extracts only the rules relevant to the active intensity level (`lite`, `full`, or `ultra`) from [`SKILL.md`](https://github.com/DietrichGebert/ponytail/blob/main/SKILL.md).
- **Prompt injection**: [`hooks/ponytail-mode-tracker.js`](https://github.com/DietrichGebert/ponytail/blob/main/hooks/ponytail-mode-tracker.js) intercepts every prompt and prepends the rule block via `writeHookOutput()`, ensuring the LLM context always contains the constraints.
- **Immutable defaults**: [`hooks/ponytail-config.js`](https://github.com/DietrichGebert/ponytail/blob/main/hooks/ponytail-config.js) restricts persistent modes to runtime-compatible values and prevents the `review` mode from leaking into saved configurations.
- **CI enforcement**: [`scripts/check-rule-copies.js`](https://github.com/DietrichGebert/ponytail/blob/main/scripts/check-rule-copies.js) validates that all host-specific rule copies match the canonical [`AGENTS.md`](https://github.com/DietrichGebert/ponytail/blob/main/AGENTS.md), aborting builds on drift.
- **Zero-leakage**: Because rules are injected as system prompt context, the LLM processes constraints before user input, eliminating the possibility of unconstrained code generation.

## Frequently Asked Questions

### How does Ponytail prevent the LLM from ignoring its rules?

Ponytail injects the rule block directly into the **system prompt context** (or as a hidden SessionStart message) rather than appending it to user-visible text. This positioning causes the LLM to treat the constraints as core instructions with higher priority than user queries, significantly reducing the likelihood of rule violation.

### What happens if the SKILL.md file is missing or corrupted?

The `getPonytailInstructions()` function in [`hooks/ponytail-instructions.js`](https://github.com/DietrichGebert/ponytail/blob/main/hooks/ponytail-instructions.js) includes a hard-coded fallback containing the full ladder of rules. If the file system read fails, the system immediately falls back to this embedded copy, ensuring the enforcement pipeline continues to function without interruption.

### Can I set `review` mode as my default for all projects?

No. The `normalizeMode()` function in [`hooks/ponytail-config.js`](https://github.com/DietrichGebert/ponytail/blob/main/hooks/ponytail-config.js) explicitly excludes `review` from the `VALID_MODES` array used for persistent storage. This mode is restricted to session-only use to prevent accidental overhead in automated workflows or shared environments.

### How does Ponytail maintain consistency across different IDEs?

The [`scripts/check-rule-copies.js`](https://github.com/DietrichGebert/ponytail/blob/main/scripts/check-rule-copies.js) CI script performs byte-for-byte comparisons between the canonical [`AGENTS.md`](https://github.com/DietrichGebert/ponytail/blob/main/AGENTS.md) and host-specific copies (e.g., `.cursor/rules/ponytail.mdc`). It validates invariant phrases and aborts the build if any copy drifts, forcing synchronized updates across all distribution channels.