{"slug": "centralized-rule-structures", "title": "Centralized Rule Structures", "summary": "A developer proposes a centralized rule architecture for AI agents in CrystaCode projects to prevent logic divergence and execution failure. The system uses a single source of truth in AGENTS.md, with secondary files acting as routing parameters, and a PowerShell hook enforces compliance by gating file modifications based on session markers.", "body_md": "**Enforcing AI Agent Adherence Through Single-Source Architecture in CrystaCode projects**\n\nAI agents require strict directory structures to execute project rules without logic divergence. Rule duplication causes execution failure. Establish a single source of truth. Define each rule in exactly one location. Secondary files function exclusively as routing parameters.\n\n```\nAGENTS.md                        # Primary entry file\nCLAUDE.md                        # Pointer to AGENTS.md\n\nagents/\n  rules/\n    productA.md                  # Component directives\n    productB.md\n  skills/\n    styling-guidelines-a/SKILL.md\n    styling-guidelines-b/SKILL.md\n  hooks/\n    styling-guard.ps1            # Interceptor execution script\n\ndocs/\n  Conventions/\n    ProductA/styling-guidelines.md   # Absolute rule text\n    ProductB/styling-guidelines.md\n\n.claude/\n  settings.json                  # Claude hook directive\n  skills/*/SKILL.md              # Auto-generated artifacts\n\n.github/\n  instructions/*.instructions.md # GitHub agent pointers\n  hooks/preToolUse.json          # GitHub hook directive\n```\n\n**AGENTS.md**: The mandatory initialization file. Contains routing matrices. Outlines file extension triggers and maps them to specific requisite documents.\n\n**CLAUDE.md**: Contains a single pointer instructing the parser to evaluate `AGENTS.md`\n\n.\n\n**.github/instructions/**: Pointers redirecting GitHub Copilot to module-specific rules.\n\n**agents/rules/**: Isolated procedural steps and checklists mapped to specific project modules. Defers rule definitions to the skills directory.\n\n**agents/skills/**: Contextual triggers dictating exact pre-conditions for operation. Defers absolute rule text to the `docs/`\n\nrepository.\n\n**docs/**: The definitive repository. Contains complete technical specifications and rule text. The sole location for rule definitions.\n\n**.claude/skills/**: Automated mirror of `agents/skills`\n\n. Manual modification is strictly prohibited.\n\nThe `styling-guard.ps1`\n\nhook enforces compliance by gating execution based on session markers.\n\n**Intercept Request:**\n\nThe script intercepts the AI file modification request pre-execution.\n\n**Evaluate Target Parameters:**\n\nThe file extension is evaluated against target parameters (`.scss`\n\n, `.razor`\n\n). Unmatched files bypass interception.\n\n**Ascertain Product Association:**\n\nThe script evaluates the target file path to identify the associated project module.\n\n**Query Session Data:**\n\nThe script checks session data for an existing execution marker corresponding to the file type and module. If present, the AI bypasses interception.\n\n**Halt Execution:**\n\nIf the marker is absent, execution is blocked. The AI receives an explicit directive to parse the required skill documentation.\n\n**Write Execution Marker:**\n\nThe script writes the execution marker to session data. Subsequent modification attempts in the same session proceed without interruption.\n\n**Interceptor Implementation Logic**\n\nThe interception mechanism outputs explicit standard error directives to halt execution when session markers are absent:\n\n```\nif ($category -eq 'scss') {\n    [Console]::Error.WriteLine(\n        \"MANDATORY styling gate: this is the first .scss edit in this session for the \" +\n        \"'$product' product. Invoke the '$skill' skill (canonical rules: $doc), apply its \" +\n        \"rules -- $checklist -- then retry this exact edit. $forbidden \" +\n        \"This gate fires once per session per product per file category.\")\n} else {\n    [Console]::Error.WriteLine(\n        \"MANDATORY component gate: this is the first .razor edit in this session for the \" +\n        \"'$product' product. Before this edit: (1) invoke the '$skill' skill (canonical \" +\n        \"rules: $doc) for color/typography/component conventions -- use $components. \" +\n        \"(2) invoke the 'localize-app-strings' skill -- never hardcode user-facing text, \" +\n        \"always route through IStringLocalizer<AppStrings>. Then retry this exact edit. \" +\n        \"This gate fires once per session per product per file category.\")\n}\n```\n\n`AGENTS.md`\n\n).`docs/`\n\n) as the single source of truth.`.claude`\n\n, `.github`\n\n) to pointer artifacts.Enjoy it: [CrystaCode](https://crystacode.ai/)", "url": "https://wpnews.pro/news/centralized-rule-structures", "canonical_source": "https://dev.to/hamedhajiloo/the-agent-constitution-1gmk", "published_at": "2026-07-30 08:38:53+00:00", "updated_at": "2026-07-30 09:00:55.431493+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools"], "entities": ["CrystaCode", "GitHub Copilot", "Claude"], "alternates": {"html": "https://wpnews.pro/news/centralized-rule-structures", "markdown": "https://wpnews.pro/news/centralized-rule-structures.md", "text": "https://wpnews.pro/news/centralized-rule-structures.txt", "jsonld": "https://wpnews.pro/news/centralized-rule-structures.jsonld"}}