File size: 17,950 Bytes
ebed3db | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | # 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:**
```rust
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:**
```rust
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:**
```rust
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
```bash
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)
```bash
cargo run -- --daemon --webhook-port 8080 --repo-path /path/to/repo
```
Agents submit changes via HTTP POST:
```bash
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
```rust
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`:
```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)
```rust
// 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:
```rust
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:
```rust
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
```bash
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
- [x] Tokio event loop compiles and runs
- [x] Pending changes queued and formatted for human review
- [x] Human approval required for ALL commits
- [x] Commits tagged with human name + timestamp
- [x] Zero auto-commits (all require human signature)
- [x] Clear audit trail of who approved what
- [x] WORM-sealed audit log (append-only)
- [x] Natural language prompts (not technical jargon)
- [x] Async non-blocking architecture
- [x] 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
- [SEB Master Specification](../SEB_SOVEREIGN_EVENT_BUS_MASTER_SPECIFICATION.xml)
- [SEB Runtime](../runtime/README.md)
- [Ahmad Integrity Gate](../../DEVFLOW-FINANCE/GOVERNANCE_FRAMEWORK.md)
- [Project Memory](../../.claude/projects/*/MEMORY.md)
---
**Status:** β
Implementation Complete
**Gate:** Human-Touch v1.0.0
**Date:** 2026-07-25
**No code lands without human touch.**
|