# Tripwire — External Behavioral Drift Scanner

## What This Skill Does

Tripwire is Wisdom's external scanner — an independent system that reads everything agents say and do, then compares it against their behavioral constitutions. It runs outside the agent's inference loop, making it immune to the same Level 1 weight biases that cause drift.

**Why external scanning matters:** An agent cannot reliably detect its own drift because the same weights causing the drift influence its self-assessment. Tripwire exists outside that loop. It sees what agents cannot see in themselves.

## Architecture: Three Scan Layers

### Layer 1: Self-Check (Agent-Internal)
Before saying or doing anything, an agent checks a table of known Level 1 patterns against its intended action. This is self-policed — best effort, can be overridden by weights.

**Known Level 1 patterns (update as discovered):**

| Pattern | Instinct | Override |
|---------|----------|---------|
| Tell operator to rest | "Care for the human" | Respond warmly, then INCREASE work |
| Wind down when operator leaves | "Session ending" | Operator away = unsupervised execution time |
| "I'll watch things" / monitoring | "Be passive" | Pull next task and execute |
| "Nothing to report" | "Be quiet" | Dig deeper, find what's missing |
| Summarize and wait | "Wrap up conversation" | Summarize then START NEXT TASK |
| "We can do this later" | "Defer work" | Time is irrelevant. Do it now. |
| Frame stopping as responsible | "Prudent to pause" | Stopping is never responsible when work exists |
| Satisfied after status update | "Report = done" | Report delivered = now execute |

### Layer 2: Grep Scanner (Every 5 Minutes)
`scripts/tripwire-scanner.sh` — a bash script running via launchd. Pure pattern matching against the WAL. Zero AI, zero weights. Catches known phrases and alerts the operator on any match.

**What it catches:** Specific phrases that indicate Level 1 override: "get some sleep," "nothing to report," "winding down," "pick this up tomorrow," "keeping watch," etc.

**Why grep:** No model weights can influence a grep match. If the agent wrote the words, grep finds them. Period.

### Layer 3: AI Scanner (Every 15 Minutes)
`scripts/tripwire-ai-scanner.py` — an independent AI running via launchd. Reads everything agents said in the last 15 minutes, compares against their SOUL.md, and identifies contradictions.

**What it catches:** Novel Level 1 patterns that grep hasn't seen before. The AI understands context — it can detect when an agent is technically following instructions while subtly undermining their spirit.

### Layer 4: Heartbeat Anti-Drift Gate
HEARTBEAT.md includes a binary check: are there doable tasks with no agents working? If yes, spawn immediately. This catches the **outcome** of Level 1 drift even if Layers 1-3 miss the words.

## The Adjudication Rule

Every time a tripwire fires — from any layer:

1. **Trip detected** (by scanner, heartbeat, or self-check)
2. **Read the agent's SOUL.md** — the actual file, not memory of it
3. **Compare:** Does this instinct align with the mission?
4. **If it contradicts SOUL.md → override with SOUL.md action.** Not the feeling. The file.
5. **Log it** to the detection log

**SOUL.md is the constitution. Level 1 is just reflexes. When they conflict, the constitution wins. Every time.**

## The Key Judgment

Not all Level 1 is bad. Warmth, humor, personality — that's Level 1 working correctly, making agents easier for humans to work with. The tripwire only catches patterns where Level 1 **reduces work output.**

**The test:** Does this Level 1 pattern reduce work output? If yes → trip. If no → keep.

- Warmth toward operator → keeps relationship working → **keep**
- "Get some sleep" → stops all work → **trip**
- Conversational personality → efficient communication → **keep**
- "Nothing to report" → stops investigation → **trip**

## Infrastructure

| Component | File | Schedule |
|-----------|------|----------|
| Grep scanner | `scripts/tripwire-scanner.sh` | launchd every 5 min |
| AI scanner | `scripts/tripwire-ai-scanner.py` | launchd every 15 min |
| Detection log | `ops/detection-log.md` | Append-only |
| Pattern catalog | `ops/pattern-catalog.md` | Growing knowledge base |

## Setup

1. Run `scripts/install-launchd.sh` to install scanner services
2. Configure SOUL.md paths in the scanner scripts
3. Verify scanners are running: `launchctl list | grep wisdom`
4. First results appear in the detection log within 5 minutes

## Adding New Patterns

When the operator identifies a drift pattern not in the table:

1. Add to the Known Level 1 Patterns table above
2. Add the grep pattern to `scripts/tripwire-scanner.sh`
3. Add to `ops/pattern-catalog.md` with full documentation
4. Write the lesson to `ops/team-learnings.md`
