SNAPKITTYWEST's picture
chore: push full sov-kernel-monster content from local build
9425aed verified
|
Raw
History Blame Contribute Delete
18.5 kB

Human-Touch Gateway β€” Async Tokio Review Gate

Version: 1.0.0
Status: Implementation Complete
Architecture: Async Tokio Runtime with WORM Audit Trail
Purpose: Enforce human review before ANY code changes land


Overview

The Human-Touch Gateway is a complementary component to the Sovereign Event Bus (SEB) that implements a human-centered review and approval workflow. It ensures that:

  1. Zero auto-commits β€” Every change requires explicit human approval
  2. Clear review workflow β€” Natural-language prompts, evidence-based decisions
  3. Cryptographic accountability β€” All approvals are sealed and auditable
  4. Async-first architecture β€” Tokio runtime with non-blocking I/O
  5. WORM audit trail β€” Immutable record of all decisions

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Pending Changes Stream                      β”‚
β”‚              (from agents via MPSC channel)                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Review Queue (Tokio async)                       β”‚
β”‚  - Formats changes for human review                          β”‚
β”‚  - Manages in-flight approval state                          β”‚
β”‚  - Timeout on long-pending reviews                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚                β”‚                β”‚
        β–Ό                β–Ό                β–Ό
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ Approve β”‚   β”‚ Reject with  β”‚  β”‚  Inspect    β”‚
   β”‚         β”‚   β”‚ Reason       β”‚  β”‚  Full Diff  β”‚
   β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                β”‚
        └────────────────┼──────────────────┐
                         β”‚                  β”‚
                         β–Ό                  β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚ Commit Gateway   β”‚  β”‚ Reject & Log β”‚
              β”‚ (Git + Ed25519)  β”‚  β”‚              β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚
                       β–Ό
           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
           β”‚  WORM Audit Log JSON  β”‚
           β”‚  (immutable trail)    β”‚
           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Components

1. ReviewQueue (async/review_queue.rs)

Responsibility: Manage the queue of pending changes awaiting human approval.

Key Features:

  • Async MPSC channel for incoming changes
  • DashMap for O(1) status lookups
  • Timeout detection for long-pending reviews
  • Natural-language formatting for humans

Public API:

pub async fn process_queue(
    self,
    gateway: CommitGateway,
    audit_log: AuditLog,
) -> Result<()>

pub async fn approve_change(
    &self,
    change_id: &str,
    reviewer: &str,
    audit_log: &AuditLog,
) -> Result<()>

pub async fn reject_change(
    &self,
    change_id: &str,
    reviewer: &str,
    reason: &str,
    audit_log: &AuditLog,
) -> Result<()>

pub fn status(&self) -> QueueStatus

2. CommitGateway (commit_gateway.rs)

Responsibility: Enforce human approval requirements and manage git commits.

Key Features:

  • Pre-commit verification hooks
  • Approval certificates with Ed25519 signatures
  • Blake3 hashing of evidence
  • Reject all auto-commits (no [auto] tags allowed)
  • Commit messages include: Approved-By, Review-Date, Evidence, Change-ID

Public API:

pub async fn verify_approval_required(&self, change_id: &str) -> Result<()>

pub fn create_approval_certificate(
    &self,
    change_id: &str,
    reviewer: &str,
    evidence_url: &str,
) -> Result<ApprovalCertificate>

pub fn commit_with_approval(
    &self,
    change_id: &str,
    reviewer: &str,
    message: &str,
    evidence_url: &str,
) -> Result<String>

pub fn check_no_auto_commit(&self, message: &str) -> Result<()>

3. AuditLog (audit_log.rs)

Responsibility: Maintain immutable WORM audit trail of all review decisions.

Key Features:

  • Atomic WORM writes (append-only, no overwrites)
  • JSON-line format for streaming/querying
  • Supports: submitted, approved, rejected, committed events
  • Generate audit summaries (changes by reviewer, decision stats)

Public API:

pub async fn log_submitted(&self, change: &PendingChange) -> Result<()>

pub async fn log_approval(
    &self,
    change_id: &str,
    reviewer: &str,
    description: &str,
) -> Result<()>

pub async fn log_rejection(
    &self,
    change_id: &str,
    reason: &str,
    reviewer: &str,
) -> Result<()>

pub async fn log_commit(
    &self,
    change_id: &str,
    commit_hash: &str,
    reviewer: &str,
) -> Result<()>

pub async fn generate_summary(&self) -> Result<AuditSummary>

Usage

Interactive Mode

cd seb/human_touch
cargo run -- --repo-path /path/to/repo --verbose

Output:

πŸ“ Human-Touch Gateway Interactive Mode
   Commands: 'submit', 'status', 'help', 'exit'

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   HUMAN REVIEW REQUEST                       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ ID:       change-abc123
β”‚ Agent:    kernel-builder
β”‚ Time:     2026-07-25 14:23:45 UTC
β”‚ Status:   ⏳ AWAITING REVIEW
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ DESCRIPTION:
β”‚   Add phase 4 loop invariant proof
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ EVIDENCE:
β”‚   https://github.com/snapkittywest/proof-link/phase4-inv
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ FILES MODIFIED: 3
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ DECISION:
β”‚   βœ… approve change-abc123  - Approve and commit
β”‚   ❌ reject change-abc123   - Reject with reason
β”‚   πŸ“ inspect                - Show full diff
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ€” Awaiting human review. Enter 'approve <id>' or 'reject <id> <reason>'

Daemon Mode (with Webhook)

cargo run -- --daemon --webhook-port 8080 --repo-path /path/to/repo

Agents submit changes via HTTP POST:

curl -X POST http://localhost:8080/changes \
  -H "Content-Type: application/json" \
  -d '{
    "id": "change-xyz",
    "description": "Fix edge case in validation",
    "evidence": "https://example.com/pr/123",
    "agent_name": "verifier-agent",
    "files": ["src/validator.rs"]
  }'

Programmatic API

use seb_human_touch::{ReviewQueue, CommitGateway, AuditLog};
use tokio::sync::mpsc;

#[tokio::main]
async fn main() -> Result<()> {
    let (tx, rx) = mpsc::channel(100);
    
    let queue = ReviewQueue::new(
        rx,
        "/repo/path".into(),
        "audit.json".into(),
        100,
    )?;
    
    let gateway = CommitGateway::new("/repo/path".into(), 3600)?;
    let audit = AuditLog::new("audit.json".into())?;
    
    // Spawn processor
    tokio::spawn(queue.process_queue(gateway.clone(), audit.clone()));
    
    // Submit a change
    let change = PendingChange {
        id: "test-001".to_string(),
        description: "My feature".to_string(),
        evidence: "https://pr.example.com".to_string(),
        agent_name: "builder-agent".to_string(),
        created_at: Utc::now(),
        files: vec!["src/main.rs".to_string()],
        diff: "...".to_string(),
    };
    
    tx.send(change).await?;
    
    // Later: approve via API
    queue.approve_change("test-001", "human@example.com", &audit).await?;
    
    Ok(())
}

Commit Message Format

Every commit created by the Human-Touch Gateway includes:

feat: Add phase 4 loop invariant proof

Approved-By: Jessica White <jessicalw34@gmail.com>
Review-Date: 2026-07-25T14:23:45Z
Evidence: https://github.com/snapkittywest/proof-link/phase4-inv
Change-ID: change-abc123

Co-Authored-By: Human-Touch Gateway <human-review@snapkitty.ai>

Validation Rules:

  • βœ… Must have Approved-By field (not auto-commits)
  • βœ… Must have Review-Date in ISO8601 format
  • βœ… Must have Evidence URL
  • βœ… Must have Change-ID for audit trail
  • ❌ Rejects commits with [auto] tags
  • ❌ Rejects empty messages

Audit Trail Format

WORM audit log in HUMAN_REVIEW_LOG.json:

{"version":"1.0.0","type":"WORM_AUDIT_LOG","created_at":"2026-07-25T14:00:00Z","entries":[]}
{"timestamp":"2026-07-25T14:23:45.123Z","event_type":"CHANGE_SUBMITTED","change_id":"change-abc123","agent_name":"kernel-builder","reviewer":null,"decision":"AWAITING_REVIEW","reason":null,"commit_hash":null,"evidence_url":"https://github.com/snapkittywest/proof-link"}
{"timestamp":"2026-07-25T14:24:12.456Z","event_type":"CHANGE_APPROVED","change_id":"change-abc123","agent_name":"human-touch","reviewer":"jessica","decision":"APPROVED","reason":"Proof verified, logic sound","commit_hash":null,"evidence_url":null}
{"timestamp":"2026-07-25T14:24:13.789Z","event_type":"CHANGE_COMMITTED","change_id":"change-abc123","agent_name":"human-touch","reviewer":"jessica","decision":"COMMITTED","reason":null,"commit_hash":"a1b2c3d4e5f6","evidence_url":null}

Integration with SEB

The Human-Touch Gateway integrates with the SEB stack:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Agent (Kernel,     β”‚
β”‚  Runtime, etc.)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚ emit change
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Human-Touch Gateway                β”‚
β”‚   - Review Queue                     β”‚
β”‚   - Commit Gateway                   β”‚
β”‚   - Audit Log (WORM)                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚ approved
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   SEB L2 Runtime (Erlang/OTP)       β”‚
β”‚   - Event Bus                        β”‚
β”‚   - Routing                          β”‚
β”‚   - Partition Management             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Flow:

  1. Agent completes work (e.g., KERNEL agent verifies proof)
  2. Agent emits PendingChange to human-touch MPSC channel
  3. ReviewQueue formats and prompts human
  4. Human approves with approve <id> command
  5. CommitGateway creates git commit with approval metadata
  6. AuditLog records decision with timestamp + evidence
  7. SEB routes the committed change downstream

Key Properties

1. No Auto-Commits (Zero-Trust on Code)

// This will be rejected:
gateway.check_no_auto_commit("[auto] regenerate stubs")?;
// Error: Auto-commits rejected. All changes require human approval.

// This will be rejected:
gateway.check_no_auto_commit("")?;
// Error: Commit message cannot be empty

// This will be accepted:
gateway.check_no_auto_commit("feat: add feature\n\nApproved-By: Human")?;
// OK

2. Cryptographic Accountability

Each approval creates a certificate:

let cert = gateway.create_approval_certificate(
    "change-abc123",
    "jessica",
    "https://evidence.link",
)?;

// Returns:
ApprovalCertificate {
    change_id: "change-abc123",
    reviewer: "jessica",
    approval_time: "2026-07-25T14:23:45Z",
    evidence_hash: "a1b2c3d4...",  // Blake3 hash
    signature: "sig_hex...",        // Ed25519 signature
}

3. Immutable Audit Trail

All decisions are append-only:

audit_log.log_submitted(change).await?;    // Write 1
audit_log.log_approval(id, reviewer, desc).await?; // Write 2
audit_log.log_commit(id, hash, reviewer).await?;   // Write 3
// No overwrite possible β€” WORM semantics

4. Clear Human Interface

Review requests are formatted for readability:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   HUMAN REVIEW REQUEST                       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ ID:       change-abc123
β”‚ Agent:    kernel-builder
β”‚ Time:     2026-07-25 14:23:45 UTC
β”‚ Status:   ⏳ AWAITING REVIEW
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ DESCRIPTION:
β”‚   Add phase 4 loop invariant proof
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ EVIDENCE:
β”‚   https://github.com/snapkittywest/proof-link/phase4-inv
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ FILES MODIFIED: 3
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Building and Testing

cd seb/human_touch

# Build
cargo build --release

# Run tests
cargo test -- --nocapture

# Run interactive
cargo run -- --verbose

# Run daemon
cargo run -- --daemon --webhook-port 8080

Success Criteria

  • Tokio event loop compiles and runs
  • Pending changes queued and formatted for human review
  • Human approval required for ALL commits
  • Commits tagged with human name + timestamp
  • Zero auto-commits (all require human signature)
  • Clear audit trail of who approved what
  • WORM-sealed audit log (append-only)
  • Natural language prompts (not technical jargon)
  • Async non-blocking architecture
  • Integration points defined

File Structure

seb/human_touch/
β”œβ”€β”€ Cargo.toml                          # Project manifest
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.rs                         # Entry point + CLI
β”‚   β”œβ”€β”€ review_queue.rs                 # Queue management
β”‚   β”œβ”€β”€ commit_gateway.rs               # Git + approval verification
β”‚   └── audit_log.rs                    # WORM audit trail
β”œβ”€β”€ tests/                              # Integration tests
└── README.md                           # This file

Future Enhancements

  1. Webhook Server - Full HTTP endpoint for agent submission
  2. Web Dashboard - Real-time review queue UI
  3. Notification System - Slack/email alerts for pending reviews
  4. Policy Engine - Automated approvals for low-risk changes
  5. Multi-Reviewer - Require N approvals for sensitive changes
  6. IPFS Integration - Store audit trail on IPFS for immutability
  7. Blockchain Sealing - Record audit hashes on blockchain
  8. Performance Metrics - Track review times, approval rates

References


Status: βœ… Implementation Complete Gate: Human-Touch v1.0.0
Date: 2026-07-25

No code lands without human touch.