Architecture Deep Dive

March 5, 2026 · View on GitHub

This document covers advanced architectural details. For general usage, see README.md.

Agentic Control Stack

This plugin implements a complete agentic control loop architecture. Each layer maps to specific plugin components:

Layersd0x-dev-flow ImplementationKey Files
Feedforward Gate/precommit hooks, pre-edit-guard.sh, lint:fixhooks/pre-edit-guard.sh, commands/precommit.md
Feedback Loop (MAPE)/verify/codex-review-fast → fix → re-reviewrules/auto-loop.md
Hierarchical LoopsInner (hooks 30s) → Mid (review+precommit 10min) → Outer (PR review + rules)hooks/commands/rules/
Sensorsaudit.js, analyze.js, risk-analyze.js, skill-lint.jsskills/*/scripts/*.js
EffectorsEdit/Write tools, allowed-tools whitelist, diff budgetcommands/*.md frontmatter
Human Governancerules/ = Knowledge curation, ⚠️ Need Human sentinel = circuit breakerrules/auto-loop.md

Control Loop Pathology & Mitigation

Failure ModeSymptomMitigation in sd0x-dev-flow
OscillationFix test1 breaks test2, revert loops3-round limit on same issue → report blocker, request human
Local MinimumTests pass via hacks (deleted assertions)Independent Codex review (never feed conclusions) as second sensor
DivergenceDiff grows unbounded, unrelated changesallowed-tools whitelist limits effectors, git rules forbid direct push to main

Command Template Sandbox Rules

When writing ! backtick context checks in command templates, be aware of Claude Code sandbox restrictions:

ProblemSolution
ls/find on home-dir paths blocked in ! context checksUse bash -c 'test -f "$HOME/..." && echo ok || echo missing' 2>/dev/null || echo "unknown (sandbox)"
allowed-tools pattern must match ! check commandsIf allowed-tools: Bash(bash:*), wrap all ! checks in bash -c '...'
${CLAUDE_PLUGIN_ROOT} unavailable in command .mdCannot narrow allowed-tools to specific script paths; keep Bash(bash:*) until #9354 resolved

Script Fallback Pattern

Verification commands (/precommit, /verify, /dep-audit) use a Try → Fallback pattern:

  1. Try: If a runner script exists in the project root (scripts/precommit-runner.js, etc.), use it for fast, deterministic execution.
  2. Fallback: If no script is found, Claude detects the project ecosystem (Node.js, Python, Rust, Go, Java) and runs the appropriate commands directly.

The fallback works out of the box with no setup required. Runner scripts are bundled in this plugin repo but cannot be auto-resolved from plugin commands due to a Claude Code limitation (${CLAUDE_PLUGIN_ROOT} is unavailable in command markdown).