# Best Practices

The working patterns the pipeline is built on, and where each one applies.

## 1. Symlink Distribution

**Problem**: Copying pipeline files on install duplicates ~10K tokens of content per session.
**Solution**: `--link` flag creates symlinks instead of copies. Updates propagate instantly.

```bash
npx @mmerterden/multi-agent-pipeline install --link
```

**Trade-off**: Requires the source package to remain installed. Best for development; use copy mode for production installs.

## 2. Fix First

**Rule**: When a bug or test failure is discovered during development, fix it immediately before continuing with the current task. Never defer fixes to "later".

Applied in Phase 2 (Dev):

- If a test fails → fix the failing test before writing new code
- If lint errors appear → fix them before the next TDD cycle
- If a build breaks → stop and fix before proceeding

## 3. Parallel Exploration

**Rule**: Explore the codebase in parallel, and only as deep as the task needs.

Applied in Phase 1 (Plan): parallel Explore agents scan the files related to the task,
the existing patterns and conventions, and the likely impact areas. Their thoroughness
follows the task: light when a fresh code graph already ranked the files or the scope
is one named site, medium when project knowledge exists, very thorough otherwise
(`phases/phase-1-plan.md`).

## 4. Test-First TDD

**Rule**: Tests are written strictly before implementation. No exceptions.

Applied in Phase 2 (Dev):

1. RED - Write the failing test
2. Verify it fails for the RIGHT reason
3. GREEN - Write minimal code to pass
4. Verify ALL tests pass
5. REFACTOR - Clean up without changing behavior

## 5. Deterministic Quality Gates

**Rule**: Every phase transition must pass an explicit gate. No implicit transitions.

| Gate        | Condition                                               | Blocks |
| ----------- | ------------------------------------------------------- | ------ |
| Phase 1 → 2 | Plan approved, no unanswered questions                  | Dev    |
| Phase 2 → 3 | Build passes, lint clean, tests green                   | Review |
| Phase 3 → 4 | All blocking findings resolved                          | Commit |
| Phase 4 → 5 | Push successful, PR created                             | Report |

## 6. 3-Iteration Hard Kill

**Rule**: Any retry loop (build fix, test fix, API call) is killed after 3 attempts. The agent must escalate to the user instead of spinning.

```
Attempt 1 → fix → retry
Attempt 2 → different fix → retry
Attempt 3 → STOP → ask user for guidance
```

## 7. Layer-Based Memory

**Problem**: Loading full project context at session start wastes tokens.
**Solution**: Lazy-load reference files only when the current phase needs them.

Applied via modular loading:

- **L0 (always)**: Main command routing (~300 tokens)
- **L1 (on demand)**: Phase definitions, rules (~2K tokens each)
- **L2 (rare)**: Platform guides, knowledge base (~5K tokens each)

## 8. Single Source of Truth

**Rule**: Every configuration, rule, or standard exists in exactly one authoritative location. All other instances are derived.

Applied via `/multi-agent:sync`:

- Claude Code commands → source of truth
- Pipeline repo → derived (genericized, personal data scrubbed)
- Copilot CLI and Codex CLI → derived from the pipeline repo
- Website → derived from `docs/facts.json` (`gen-facts.mjs`)
