How coderifts/agent-guard works
@coderifts/agent-guard is a fail-closed runtime boundary for AI-agent tool calls: it detects and preflights contract-changing mutations, verifies a decision, then conditionally permits deferred execution. The graph follows registry construction through guard evaluation and execution, with separate branches for adapters, freshness/CAS safeguards, monitoring, and proof. README documents execution-state rechecks and post-commit observation; source excerpts establish key control and adapter links, while unsampled subsystem wiring is not assumed.
Main entry points: guard.ts Tool-call guard · execution-proof.ts Execution proof · final-answer-proof.ts Final-answer proof · with-coderifts.ts CodeRifts composition
Components 22
Agent integration
- Framework adapters
src/adapters - CodeRifts composition
src/with-coderifts.ts - Guarded tool registry
src/tool-registry.ts
Preflight and decision
- Tool-call guard
src/guard.ts - Change detection
src/detector.ts - Artifact resolution
src/artifact-resolver.ts - Decision and policy
src/read-decision.ts
Execution safeguards
- Freshness checks
src/freshness.ts - Execution-state recheck
src/auto-recheck.ts - Conditional write contract
src/conditional-write.ts - CAS adapters
src/cas-adapters - Commit observation
src/commit-observation.ts - Deferred tool execution
src/execute-tool-call.ts
Evidence and monitoring
- Coverage observation
src/coverage-observed.ts - Monitoring delivery
src/monitoring-delivery.ts - Monitoring attestation
src/monitoring-attestation.ts - Execution proof
src/execution-proof.ts - Final-answer proof
src/final-answer-proof.ts - CAS attestation
src/cas-attestation.ts
Other components
- Agent host
- CodeRifts SDK
- Host resource store
Connections 26
- Agent host → Framework adapters: uses
README.md - Framework adapters → CodeRifts composition: wraps
src/adapters/openai.ts - CodeRifts composition → Guarded tool registry: constructs
src/with-coderifts.ts - Guarded tool registry → Tool-call guard: guards calls
src/tool-registry.ts - Guarded tool registry → Deferred tool execution: dispatches
src/tool-registry.ts - Tool-call guard → Change detection: detects changes
src/guard.ts - Tool-call guard → Decision and policy: reads verdict
src/guard.ts - Tool-call guard → Freshness checks: checks freshness
src/guard.ts - Tool-call guard → Execution-state recheck: rechecks state
- Tool-call guard → Conditional write contract: requires contract
src/guard.ts - Change detection → Artifact resolution: resolves artifacts
- Tool-call guard → CodeRifts SDK: preflights
README.md - Deferred tool execution → Host resource store: host writes
README.md - CAS adapters → Conditional write contract: executes conditionally
src/cas-adapters/fs.ts - Host resource store → CAS adapters: reads and writes
- Commit observation → CAS adapters: observes after write
src/commit-observation.ts - CodeRifts composition → Coverage observation: observes tool traffic
src/with-coderifts.ts - Monitoring delivery → Monitoring attestation: attests delivery
src/monitoring-attestation.ts - Tool-call guard → Monitoring delivery: delivers events
src/guard.ts - Tool-call guard → Execution proof: builds proof
src/guard.ts - Execution proof → Coverage observation: includes observation
src/execution-proof.ts - Final-answer proof → Execution proof: renders proof
src/final-answer-proof.ts - Final-answer proof → Monitoring delivery: formats delivery
src/final-answer-proof.ts - Final-answer proof → Monitoring attestation: formats attestation
src/final-answer-proof.ts - CAS attestation → CodeRifts SDK: verifies token
src/cas-attestation.ts - CAS attestation → Execution proof: binds proof
src/cas-attestation.ts