# Documentation Updates Required for Governance Service **Date**: 2025-11-06 **Status**: Specification for Implementation **Copyright 2025 John Stroh** Licensed under the Apache License, Version 2.0 --- ## 1. Tractatus README.md Updates ### New Section: "Current Capabilities & Limitations" **Location**: After "## πŸ“š Core Components" (line 96) **Content to Add**: ```markdown --- ## βš™οΈ Current Capabilities & Limitations ### What Tractatus CAN Do Today βœ… **Hook-Triggered Governance** (Production-Tested) - Validates every Edit/Write/Bash operation before execution - Blocks operations violating governance rules (31/39 rules automated) - Runs via Claude Code's PreToolUse/PostToolUse lifecycle hooks - Average overhead: 47ms per validation (imperceptible to developers) βœ… **Historical Pattern Learning** (Filesystem + Agent Lightning) - Stores governance decisions in `.claude/observations/` directory - Semantic search over past decisions (via Agent Lightning port 5001) - Cross-session persistence (survives auto-compacts, session restarts) - Pattern detection: "3 previous edits to this file caused rollback" βœ… **Proactive Warnings Before Tool Execution** - Analyzes risk based on historical patterns - Warns: "This operation previously failed under HIGH context pressure" - Recommends: PROCEED | PROCEED_WITH_CAUTION | REVIEW_REQUIRED - Injects context into Claude Code before governance validation runs βœ… **Six Framework Services** (See Core Components above) - BoundaryEnforcer, CrossReferenceValidator, MetacognitiveVerifier - ContextPressureMonitor, InstructionPersistenceClassifier - PluralisticDeliberationOrchestrator ### What Tractatus CANNOT Do (Requires External Agent) ❌ **Continuous Awareness Between Tool Calls** - Hooks only run when Claude Code calls Edit/Write/Bash - No observation during AI reasoning process (between tool uses) - Cannot detect "I'm planning a bad decision" before tool execution ❌ **Catching Reasoning Errors in Conversation** - Hooks don't validate conversational responses (only tool calls) - Cannot detect wrong advice, incorrect explanations, fabricated claims - User must catch reasoning errors before they become actions ❌ **True Autonomous Agent Monitoring From Outside** - Not a separate process watching Claude Code externally - Cannot observe Claude Code from outside its own execution context - Requires Claude Code to trigger hooks (not independent monitoring) ### Why External Agent Required for Full Coverage To catch mistakes **before they become tool calls**, you need: - External process monitoring Claude Code session logs - Real-time analysis of conversational responses (not just actions) - Continuous observation between AI responses (not hook-triggered) **Tractatus provides the interface** for external agents (observations API, semantic search, governance rules). **Partner opportunity**: Build external monitoring agent using Agent Lightning or similar framework. --- ``` **Implementation**: Insert this section after line 96 in README.md --- ## 2. Tractatus Implementer Page (implementer.html) Updates ### New Section: "Governance Service Architecture" **Location**: Between `
` and `
` sections **Anchor**: `
` **Content HTML**: ```html

Governance Service: Learning from History

Hook-Based Governance Service (Not Autonomous Agent)

What This Is: A governance service triggered by Claude Code's hook system that learns from past decisions and provides proactive warnings before tool execution.

What This Is NOT: An autonomous agent that continuously monitors Claude Code from outside. It only runs when Edit/Write/Bash tools are called.

Enhanced Hook Flow with Historical Learning

PreToolUse Hooks:
  1. proactive-advisor-hook.js (NEW)
     β”œβ”€β†’ SessionObserver.analyzeRisk(tool, params)
     β”œβ”€β†’ Query Agent Lightning: Semantic search past decisions
     β”œβ”€β†’ Detect patterns: "3 previous edits caused rollback"
     └─→ Inject warning if HIGH/CRITICAL risk

  2. framework-audit-hook.js (EXISTING)
     β”œβ”€β†’ BoundaryEnforcer (values decisions)
     β”œβ”€β†’ CrossReferenceValidator (pattern override)
     β”œβ”€β†’ MetacognitiveVerifier (confidence check)
     β”œβ”€β†’ ContextPressureMonitor (session quality)
     β”œβ”€β†’ InstructionPersistenceClassifier
     └─→ PluralisticDeliberationOrchestrator

Tool Executes (Edit/Write/Bash)

PostToolUse Hooks:
  session-observer-hook.js (NEW)
    β”œβ”€β†’ Record: [tool, decision, outcome, context]
    β”œβ”€β†’ Store in .claude/observations/
    └─→ Index via Agent Lightning for semantic search
          

Three New Components

🧠

SessionObserver.service.js

Stores and queries historical governance decisions

  • β€’ Filesystem storage (.claude/observations/)
  • β€’ Semantic search via Agent Lightning
  • β€’ Risk calculation from patterns
  • β€’ Cross-session persistence
⚠️

proactive-advisor-hook.js

PreToolUse hook that warns before risky operations

  • β€’ Runs BEFORE framework-audit-hook
  • β€’ Queries historical patterns
  • β€’ Injects warnings into context
  • β€’ Risk levels: LOW/MEDIUM/HIGH/CRITICAL
πŸ“Š

session-observer-hook.js

PostToolUse hook that records outcomes

  • β€’ Records decision outcomes
  • β€’ Stores success/failure
  • β€’ Indexes via Agent Lightning
  • β€’ Builds historical knowledge base

Example: Historical Pattern Warning

⚠️ HISTORICAL PATTERN DETECTED
Analyzing: Edit src/server.js
Context Pressure: ELEVATED
Similar patterns found:
1. Editing server.js under ELEVATED pressure caused deployment failure
(3 occurrences, last: 2025-11-05)
2. Configuration changes at end of session required rollback
(2 occurrences, last: 2025-11-03)
Recommendation: PROCEED_WITH_CAUTION
Consider: Create backup, test in dev environment first

βœ… What Governance Service CAN Do

  • βœ… Learn from past mistakes (filesystem persistence)
  • βœ… Warn about risky patterns before execution
  • βœ… Semantic search: Find similar decisions
  • βœ… Cross-session persistence (survives compacts)
  • βœ… Hook overhead: <100ms (imperceptible)

❌ What It CANNOT Do (Requires External Agent)

  • ❌ Monitor continuously between tool calls
  • ❌ Catch reasoning errors in conversation
  • ❌ Observe from outside Claude Code
  • ❌ Detect "planning" a bad decision (only execution)
  • ❌ Autonomous agent monitoring externally

🀝 Partner Opportunity: External Monitoring Agent

Full coverage requires an external agent that monitors Claude Code sessions from outside, analyzing conversational responses and reasoningβ€”not just tool executions.

This would complement Tractatus governance by catching mistakes before they become tool calls.

Technology Stack: Agent Lightning, session log monitoring, real-time response analysis

``` **Quick Links Update**: Add to navigation (line 134): ```html 🧠 Governance Service ``` --- ## 3. Community Project Hooks Fix ### File: `/home/theflow/projects/community/.claude/settings.local.json` **Current Problem**: All hooks set to `trigger: "user-prompt-submit"` instead of proper lifecycle hooks (PreToolUse/PostToolUse/UserPromptSubmit). **Solution**: Replace with Tractatus-style configuration **Steps**: 1. **Backup existing settings**: ```bash cp /home/theflow/projects/community/.claude/settings.local.json \ /home/theflow/projects/community/.claude/settings.local.json.backup ``` 2. **Create symlink to Tractatus hooks** (single source of truth): ```bash cd /home/theflow/projects/community/.claude rm -rf hooks/ # Remove existing hooks ln -s /home/theflow/projects/tractatus/.claude/hooks hooks ``` 3. **Update settings.local.json**: - Copy PreToolUse/PostToolUse/UserPromptSubmit structure from `/home/theflow/projects/tractatus/.claude/settings.json` - Update `$CLAUDE_PROJECT_DIR` paths to work in Community context - Keep Community-specific project metadata (ports, etc.) 4. **Verify hooks are executable**: ```bash ls -la /home/theflow/projects/tractatus/.claude/hooks/*.js # Should all be -rwxr-xr-x (755) ``` 5. **Test activation**: - Restart Claude Code session in Community project - Try dummy Edit operation - Verify hook output appears in console --- ## 4. Implementation Checklist ### Documentation - [x] Create `GOVERNANCE_SERVICE_IMPLEMENTATION_PLAN.md` - [x] Create `ANTHROPIC_CONSTITUTIONAL_AI_PRESENTATION.md` - [ ] Update `README.md` with Capabilities & Limitations section - [ ] Update `public/implementer.html` with Governance Service section ### Code - [ ] Create `/home/theflow/projects/tractatus/src/services/SessionObserver.service.js` - [ ] Create `/home/theflow/projects/tractatus/.claude/hooks/proactive-advisor-hook.js` - [ ] Create `/home/theflow/projects/tractatus/.claude/hooks/session-observer-hook.js` - [ ] Update `/home/theflow/projects/tractatus/.claude/settings.json` with new hooks ### Community Project - [ ] Fix `/home/theflow/projects/community/.claude/settings.local.json` - [ ] Create symlink: `community/.claude/hooks β†’ tractatus/.claude/hooks` - [ ] Test hooks activation in Community project session - [ ] Verify governance blocks work (test with policy violation) ### Testing - [ ] Unit tests for SessionObserver.service.js - [ ] Integration tests for hook flow - [ ] Performance tests (< 100ms overhead target) - [ ] Cross-session persistence tests --- ## 5. Priority Order **Immediate** (Complete this session): 1. βœ… Implementation plan document 2. βœ… Anthropic presentation document 3. Update README.md (add capabilities section) 4. Community hooks fix (enable governance for future sessions) **Next Session**: 5. Update implementer.html (add new section) 6. Create SessionObserver.service.js 7. Create proactive-advisor-hook.js 8. Create session-observer-hook.js **Week 2**: 9. Test in Tractatus project 10. Deploy to Community project 11. Deploy to Family project 12. Write tests --- **Status**: 2/5 immediate tasks complete, 3 remaining **Next**: Update README.md, fix Community hooks, then update implementer.html