Add SSOT-distilled AI development principles

What does this MR do and why?

Adds 23 distilled development principle files extracted from 91 docs.gitlab.com pages and the agent context loading mechanism so every AI agent session immediately benefits from GitLab-specific conventions.

This is MR 1 of 2 for #597599. It ships the principles content and delivery mechanism. MR 2 will add the automation pipeline (sync script, sources manifest, baselines, distillation prompt) that keeps principles current.

Depends on !234174 (merged), which introduced the YAML-driven ai-harness-doctor allowlist that exempts .claude/skills/gitlab-coding-principles/SKILL.md from the forbidden committed files check.

Part of gitlab-org&21742.

Motivation

A controlled A/B experiment (#597403, harness: https://gitlab.com/pedropombeiro/ai-experiment) validated the effectiveness of these principles across 120 agent runs (6 tasks × 2 conditions × 10 repetitions):

  • stub_feature_flags(...: true) anti-pattern occurrences: 64 → 0
  • Feature-flag milestone correctness: 0/10 → 10/10
  • GraphQL request-path compliance: consistent across runs
  • let_it_be:let ratio in specs: improved
  • Token overhead: 28% per task on average ($0.07/task on Sonnet 4.6)

See #597403 for the full experiment design, lessons learned, and per-task breakdowns.

Post-merge feedback is collected in #598596 (closed) — please file false positives, missing principles, agent confusion, or sync staleness reports there.

What is included

23 distilled principle files (.ai/principles/distilled/*.md)

Split into focused sub-domains for reduced token cost and better agent focus:

Database (4 files): database-fundamentals, database-migrations, database-schema, database-queries Backend (3 files): backend-ruby, backend-architecture, backend-ee Frontend (4 files): frontend-vue, frontend-style, frontend-haml, frontend-a11y Testing (2 files): qa-rspec, qa-jest Unchanged (10 files): graphql, rest-api, workers, security, performance, feature-flags, code-review, documentation, analytics, clickhouse

Rules are written in imperative voice (325 "DO NOT" rules, 0 "No ..." rules) based on experiment findings that agents ignore descriptive statements when they conflict with patterns in existing code.

Agent context loading

This MR ships a unified skill-based delivery mechanism used by both Claude Code and OpenCode:

  • .agents/skills/gitlab-coding-principles/SKILL.md — OpenCode skill. Auto-discovered by the agent from .agents/skills/ when the task description matches. Contains the full routing table mapping task types (database, frontend, GraphQL, etc.) to the relevant principle files in .ai/principles/distilled/. The Plan agent reads the skill and loads the matching principles before producing its plan.
  • .claude/skills/gitlab-coding-principles/SKILL.md — Claude Code project-scope skill with identical content. Claude Code auto-discovers .claude/skills/ and loads the skill when the task description matches. Validated against Claude Code 2.1.116 — auto-discovery and principle routing both confirmed working.

Both files are identical and will be auto-generated from sources.yml by the sync pipeline (MR 2). Delivering the same skill to both tools achieves full parity and removes the need for per-tool delivery mechanisms.

AGENTS.md and CLAUDE.md remain identical and intentionally minimal — they no longer contain a Context Loading section, since the experiment found that neither tool reliably loads principles from AGENTS.md references (see Lesson Learned #14 (closed) in #597403).

Documentation

  • .ai/README.md — explains the principles system, how to contribute, and how the distillation pipeline works. Updated to describe the unified skill delivery.
  • .ai/principles/distilled/README.md — auto-generated file notice.

Tooling updates

  • tooling/config/validate_codeowners_coverage.yml — added .claude/ to excluded directories (same justification as .ai/ — auto-generated AI configuration owned via catch-all).

Key design decisions

These were validated through the A/B experiment (#597403):

  1. Imperative framing: All rules use "DO NOT" for prohibitions and action verbs for positive conventions. Descriptive statements ("feature flags are enabled by default") are insufficient -- agents ignore them when they conflict with patterns in existing code.
  2. Sub-domain splitting: Large principles (database, backend, qa, frontend) are split into focused sub-domains (e.g., database-migrations, database-queries). Each file is under 200 lines, reducing token cost and improving agent focus compared to monolithic 200+ line files.
  3. No directory-scoped AGENTS.md files: Neither OpenCode nor Claude Code auto-loads them. Per OpenCode docs, "opencode doesn't automatically parse file references in AGENTS.md." Claude Code reads CLAUDE.md, not AGENTS.md. The effective mechanism is the gitlab-coding-principles skill, which both tools discover natively.
  4. Unified skill delivery: Both OpenCode (.agents/skills/) and Claude Code (.claude/skills/) use the same skill file with identical content. Delivering the same skill to both tools achieves full parity and simplifies maintenance. The skill approach was validated to work on Claude Code 2.1.116, which added first-class project-scope skill support, and on OpenCode (validated across dozens of agent runs in #597403).
  5. Skill-based loading for OpenCode: Earlier iterations placed the routing table in AGENTS.md between BEGIN/END GENERATED markers. The Build agent in one-shot mode consistently failed to evaluate all relevant groups (see Lessons Learned #9 (closed)–#11 (closed), #14 (closed) in #597403). Moving the routing into a self-discovered skill reliably triggers principle loading without prompt scaffolding.
  6. AGENTS.md and CLAUDE.md are identical: Required by the ai-harness-doctor parity check.

What is NOT included (MR 2)

  • .ai/principles/sources.yml — SSOT doc URL manifest (91 source pages)
  • .ai/principles/distillation_prompt.md — Duo distillation prompt (with rule 11 imperative framing)
  • .ai/principles/baselines/*.md — hand-curated supplementary rules (13 files)
  • scripts/ai/sync_principles.rb — distillation sync script (with --rewrite flag); also regenerates both skill files from sources.yml
  • spec/scripts/ai/ — sync script specs

How to validate

The principles are static content -- no runtime code changes. To verify:

  1. Check that AGENTS.md and CLAUDE.md have identical content (and are intentionally minimal — no Context Loading section).
  2. Check that .agents/skills/gitlab-coding-principles/SKILL.md and .claude/skills/gitlab-coding-principles/SKILL.md have identical content and route all 23 principles by task type, grouped by domain.
  3. Spot-check a few principle files (e.g., qa-rspec.md, database-queries.md) for accuracy against the corresponding docs.gitlab.com pages.

MR acceptance checklist

  • Principles content is accurate and up-to-date with docs.gitlab.com
  • .agents/skills/gitlab-coding-principles/SKILL.md and .claude/skills/gitlab-coding-principles/SKILL.md have identical content and route all 23 principles by task type, grouped by domain
  • AGENTS.md and CLAUDE.md are identical and minimal (no Context Loading section)
  • .ai/README.md accurately describes the unified skill delivery

References

  • #597599 -- Implement SSOT-driven principles distillation pipeline (this MR is 1 of 2)
  • !234174 (merged) -- prerequisite that introduced the YAML-driven doctor allowlist (merged)
  • #597403 -- A/B experiment measuring effectiveness (120 runs, 6 tasks, 10 reps per condition)
  • #598596 (closed) -- Post-merge feedback collection (false positives, missing principles, sync staleness)
  • gitlab-org&21742 -- parent epic
  • !227521 (closed) -- original MR (superseded; closing in favour of incremental approach)
Edited by Pedro Pombeiro

Merge request reports

Loading
Loading