[AIG-868] Wire guardrails into review-loop + expose as Hook - #49
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR integrates guardrail validation gates into the review loop (AIG-868). The loop now validates configured input requirements before code generation and validates generated outputs before proceeding, with configurable fail-closed input behavior and optional non-blocking output violations. The implementation includes configuration extensions, core gating logic, public API exports, comprehensive tests, and user documentation. ChangesGuardrail Gate Integration
Sequence Diagram(s)sequenceDiagram
participant ReviewLoop as Review Loop
participant InputGate as Input Gate
participant Coder as Coder Agent
participant OutputGate as Output Gate
participant Adversarial as Adversarial Agent
participant State as Loop State
ReviewLoop->>InputGate: validate requirements
alt input violation
InputGate->>State: record failure, mark failed
InputGate-->>ReviewLoop: throw GuardrailError
else input pass
InputGate-->>Coder: proceed
Coder->>Coder: generate code
Coder-->>OutputGate: return response
OutputGate->>OutputGate: validate output
alt output violation
alt outputNonBlocking
OutputGate->>State: record failure
OutputGate-->>Adversarial: proceed
else blocking
OutputGate->>State: record failure, mark failed
OutputGate-->>ReviewLoop: throw GuardrailError
end
else output pass
OutputGate-->>Adversarial: proceed
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
[AIG-868] Wire dei guardrails nel review-loop + esposizione come Hook
Il motore guardrails (
src/guardrails/) era implementato e testato ma orfano: non agganciato al review-loop ne esportato dalla public API. Questa PR lo collega come gate effettivo e ne documenta l'uso come hook nativo di Claude Code.Cosa cambia
Gate nel review-loop (
src/coordination/review-loop.ts)runGuardrailGate(payload, direction).failed, failure registrate instate.guardrailFailures, audit log, ethrow new ReviewLoopGuardrailError(direction, outcome). Nessun proseguimento silenzioso.Public API (
src/index.ts): esportati motore (runGuardrails,withGuardrails,initGuardrails), built-in (secretsGuardrail,piiGuardrail,promptInjectionGuardrail,zodSchemaGuardrail), registry e i tipi principali; piuReviewLoopGuardrailError(anche dasrc/coordination/index.ts).Config opt-in (
src/types.ts,src/utils/config.ts): estesaGuardrailsConfigin modo additivo coninput,output,aggregateTimeoutMs,outputNonBlocking(schema zod aggiornato). Disattivata di default (enabled: false) -> nessun impatto sulle installazioni esistenti.Documentazione (
docs/GUARDRAILS.md): nuova sezione sul gate del review-loop e su come usare i guardrail come hookPreToolUsedi Claude Code (script + config.claude/settings.json). Riusa il sistema hook nativo, non lo duplica.Test d'integrazione (
tests/integration/guardrails-gate.test.ts): blocco su secret e PII (carta LUHN-valida) in OUTPUT, blocco su prompt-injection in INPUT (coder mai invocato), no-op a gate disabilitato, percorsooutputNonBlocking, e caso pulito che non blocca.Note
Closes AIG-868
Summary by CodeRabbit
New Features
Configuration
Documentation
Tests