gate_stats
Retrieve gate enforcement statistics including blocked and warned counts with top gate insights to monitor access control patterns.
Instructions
Get gate enforcement statistics -- blocked count, warned count, top gates
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- scripts/gate-stats.js:21-71 (handler)The calculateStats function processes gate definitions (manual and auto-promoted) and computes statistics like block counts, warnings, top blocked gate, and estimated time saved.
function calculateStats() { const autoGatesPath = getAutoGatesPath(); const manualGates = loadGatesFile(MANUAL_GATES_PATH); const autoGates = loadGatesFile(autoGatesPath); const allGates = [...manualGates, ...autoGates]; let autoPromotedData = { promotionLog: [] }; if (fs.existsSync(autoGatesPath)) { try { autoPromotedData = JSON.parse(fs.readFileSync(autoGatesPath, 'utf-8')); } catch {} } const promotionLog = autoPromotedData.promotionLog || []; const blockGates = allGates.filter((g) => g.action === 'block'); const warnGates = allGates.filter((g) => g.action === 'warn'); // Count total blocks/warns from occurrences in auto-promoted gates const totalBlocked = autoGates .filter((g) => g.action === 'block') .reduce((sum, g) => sum + (g.occurrences || 0), 0); const totalWarned = autoGates .filter((g) => g.action === 'warn') .reduce((sum, g) => sum + (g.occurrences || 0), 0); // Top blocked gate const topBlocked = [...allGates] .sort((a, b) => (b.occurrences || 0) - (a.occurrences || 0)) .find((g) => g.action === 'block') || null; // Last promotion event const lastPromotion = promotionLog.length > 0 ? promotionLog[promotionLog.length - 1] : null; // Time saved estimate: ~15 min per blocked mistake const estimatedMinutesSaved = (totalBlocked + totalWarned) * 15; const estimatedHoursSaved = (estimatedMinutesSaved / 60).toFixed(1); return { totalGates: allGates.length, manualGates: manualGates.length, autoPromotedGates: autoGates.length, blockGates: blockGates.length, warnGates: warnGates.length, totalBlocked, totalWarned, topBlocked, lastPromotion, estimatedHoursSaved, gates: allGates, }; } - adapters/mcp/server-stdio.js:422-423 (handler)The MCP tool handler calls loadGateStats (from gates-engine) and returns the result as a text result for the "gate_stats" tool.
case 'gate_stats': return toTextResult(loadGateStats()); - bin/cli.js:1074-1076 (handler)CLI command "gate-stats" triggers the gate statistics reporting logic.
case 'gate-stats': gateStats(); break;