External-comparison ship pattern — pre-emptive Law 1 grep + reasoning-chain pre-build

Pattern: When user asks to compare AJ’s stack vs an external reference (gstack, BMAD, etc.) and approves shipping the gaps, two avoidable Stop-hook ping-pongs commonly occur — both addressable pre-emptively.

Gotcha 1 — Law 1 grep BEFORE design, not mid-build: The grep for existing infra (/root/.claude/hooks/, /root/aj-workspace/scripts/, ~/.claude/skills/) for each proposed component should run BEFORE the design phase, not after. In session 25-Apr-2026 gstack ship: caught existing /root/.claude/hooks/continuous-checkpoint.py mid-build → adjusted scope to “build only the missing CLI companion.” Saved design-then-discard cost. Pattern: for each component name in the comparison report, grep -rn <keyword> /root/.claude/hooks/ /root/aj-workspace/scripts/ /home/claude/.claude/skills/ BEFORE writing.

Gotcha 2 — completion-gate-validator distinguishes reasoning-chain from metacog: Already documented in hooks-registry.md lines 74-77/104. Operational rule: when user approves SUBSTANTIAL build (≥9 mutations OR memory-touched), pre-emptively run ONE reasoning-chain tool (add_thought / add_hypothesis / generate_hypotheses / add_evidence / first_principles_decomposition / decision_matrix) ALONGSIDE the STARTUP block — not retroactively after Stop hook fires. premortem_analysis and assess_reasoning_quality satisfy metacog (gate #2) only, NOT reasoning-chain (gate #1). Both gates require separate satisfaction.

Apply when: user request matches “compare against [external repo X] and ship the gaps” / “audit my setup vs Y”. Trigger: session is implicitly SUBSTANTIAL the moment user approves the gap list.

Pre-emptive checklist:

  1. grep existing infra for each proposed component name (Law 1 redundancy gate)
  2. drop duplicate/redundant builds from scope; document the catch explicitly
  3. before first Edit/Write call: run first_principles_decomposition or decision_matrix to choose which deferrable risks to fix in-session vs defer-to-outcome-review
  4. record_decision with proper tags (<domain>,<reversibility>,st-derived) at end

Concrete reference (this session): gstack comparison → caught continuous-checkpoint duplicate → scope reduced 4→3.5 builds → 2 ST decisions recorded (id=7591e1dc design + fe1a9e0d risk-triage) tagged gstack-comparison,risk-mitigation for 30/90d review → PRISTINE verdict.

Anti-pattern: running assess_reasoning_quality to satisfy the gate after-the-fact — it’s an audit tool, not a chain-builder. Build the chain first.