Commit graph

2 commits

Author SHA1 Message Date
TheFlow
f56703c46d feat: enhance hooks with metrics tracking and admin dashboard
Implements comprehensive monitoring and fixes hook execution issues.

Hook Validator Enhancements:
- Fixed stdin JSON input reading (was using argv, now reads from stdin)
- Changed exit codes from 1 to 2 for proper blocking (Claude Code spec)
- Added metrics logging to all validators (Edit and Write hooks)
- Metrics track: executions, blocks, success rates, timestamps

Admin Dashboard:
- Created /admin/hooks-dashboard.html - Real-time metrics visualization
- Shows: total executions, blocks, block rates, hook breakdown
- Displays recent blocked operations and activity feed
- Auto-refreshes every 30 seconds

API Integration:
- Created /api/admin/hooks/metrics endpoint
- Serves metrics.json to admin dashboard
- Protected by admin authentication middleware

Metrics Storage:
- Created .claude/metrics/hooks-metrics.json
- Tracks last 1000 executions, 500 blocks
- Session stats: total hooks, blocks, last updated
- Proven working: 11 hook executions logged during implementation

Bug Fix:
- Resolved "non-blocking status code 1" issue
- Hooks now properly receive tool parameters via stdin JSON
- Exit code 2 properly blocks operations per Claude Code spec

Impact:
- Framework enforcement is now observable and measurable
- Admin can monitor hook effectiveness in real-time
- Validates architectural enforcement approach

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-15 20:17:11 +13:00
TheFlow
7394740a91 feat: implement continuous framework enforcement architecture
Implements architectural enforcement to prevent framework fade (voluntary
compliance failures). This addresses Case Study #27028 where AI skipped
session-init.js despite explicit CRITICAL warnings while implementing
anti-fade enforcement mechanisms.

## New Components

### Hook Validators (scripts/hook-validators/)
- validate-file-edit.js: Pre-Edit enforcement (CSP, conflicts, boundaries)
- validate-file-write.js: Pre-Write enforcement (overwrites, boundaries)
- check-token-checkpoint.js: Prevents checkpoint fade at 50k/100k/150k

### Documentation
- CONTINUOUS_ENFORCEMENT_ARCHITECTURE.md: Technical architecture
- BOOTSTRAPPING_SOLUTION.md: Solves auto-run session-init problem
- PRE_APPROVED_COMMANDS.md: Extracted from CLAUDE.md (context reduction)
- Case Study #27028: Framework fade during anti-fade implementation

### Session Initialization Enhancement
- scripts/session-init.js: Added Section 8 (Hook Architecture Status)
- Reports hook validator installation and pre-approved commands

### CLAUDE.md Reduction (Not Committed - .gitignored)
- Reduced from 235 lines to 86 lines (63% reduction)
- Philosophy: "If it can be enforced in code, it should not be documented"

## Key Findings

Case Study #27028 proved documentation-based governance fundamentally
cannot work. AI skipped session-init.js despite "⚠️ CRITICAL" warning
while actively implementing anti-fade enforcement. This validates the
thesis that architectural enforcement (code that runs automatically)
is the only viable solution.

## Next Steps

Bootstrapping solution required: session-init.js needs automatic
invocation on continued sessions. Without this, framework fade will
recur. Options documented in BOOTSTRAPPING_SOLUTION.md.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-15 19:55:12 +13:00