System Architecture

Litmus — how the bad boy is wired

A background Mac app and a local AI server, cooperating over one loopback port. Two models, two jobs, zero data leaving the machine. Here's the whole shape on one page.

Swift + SwiftUI/AppKit app Python FastAPI server on-device Ā· no cloud loopback :8765
01

The two-process map

The thing you see (the 🧠 menu-bar icon) is a lightweight app. The brains live in a separate, always-on server. The app never holds a model — it just sends text and draws the answer. Keeping them apart means the app can rebuild or crash without ever reloading a multi-gigabyte model.

App🧠 Menu-bar agentbackground
Capture⌘B hotkey → grabs your highlighted text (via a silent copy)
Guardsskip secrets, blanks, and overlapping scans
Overlaythe floating verdict card + mini brain
MenuDeep-scan Ā· Capture Region Ā· Pause Ā· Quit
ServerLocal AI servicelaunchd Ā· 24/7
DetectorLlama-3.2-3B (4-bit) — names the tactic + confidence
TRIBE v2Meta fMRI model — predicts the cortical response
Baseline"normal" brain reference to compare against
Atlasgroups the response into readable brain systems

Two OS processes Ā· one JSON conversation over 127.0.0.1 Ā· nothing else on the network

02

What happens when you use it

Two paths. The fast one runs on every ⌘B. The slow one is opt-in from the menu, because rendering a brain map is heavy.

⌘BDetect — the everyday path~0.6s
1Highlight text, press ⌘Bā–¶ 2Gate: manipulation at all?ā–¶ 3if no → "no manipulation āœ“"ā–¶ 4if yes → name the tacticā–¶ 5Card pops up with confidence
🧠Deep-scan — where it lands in cortex~15s–2min
1Pick Deep-scan from menuā–¶ 2Send to /brainmapā–¶ 3TRIBE predicts cortexā–¶ 4Compare vs normalā–¶ 5Brain systems light up on the card
03

Two models, two jobs

The core design decision: the detector is the judge, the brain model is the illustrator. They're never swapped — proven by experiment that the text model detects better, and the brain model can only show, not decide.

The Detector

Judge Ā· always resident
Model
Llama-3.2-3B Instruct (4-bit)
Job
Names the persuasion tactic + a real confidence
Size
~2 GB, stays loaded for speed
Speed
~2–3s per verdict
Why
The better detector — text beats the brain map

TRIBE v2

Illustrator Ā· loaded on demand
Model
Meta's fMRI foundation model
Job
Predicts where in cortex the words land
Size
~7 GB, loaded & freed per scan
Speed
~15s warm, ~2min cold
Why
Never a detector — visceral picture only
The honesty rule baked into the wiring

TRIBE only sees the cortex, not deep structures like the amygdala. So the UI says "engages your value / language-evaluation cortex," never "fires your fear center." The architecture is built to never overclaim.

04

Where each piece lives

The codebase, at a glance — what each part is responsible for.

App Ā· Swift (Sources/)
App/AppDelegate
The orchestrator — menu bar, permissions, ⌘B handling, the shared guard gate.
Capture/PasteboardCapture
Grabs your selection with a silent copy, then restores your clipboard.
Capture/Region Ā· OCR
Screenshot a region and read its text (the deferred path).
Hotkey/HotkeyMonitor
The global ⌘B listener that doesn't steal the keystroke.
Classifier/RemoteClassifier
Talks to the server — the seam between app and AI.
Overlay/OverlayController
The floating verdict card + brain glow, and its timing.
Taxonomy/Taxonomy
The tactic names + plain-English mechanisms (no anatomy).
Support/SensitiveText
Screens out passwords, keys, and card numbers before analysis.
Server Ā· Python (server/)
server.py
The FastAPI service — both endpoints, the scoring, the brain pipeline.
tribe_events.py
Feeds text to TRIBE without audio, and the anti-deadlock hardening.
build_baseline.py
Builds the "normal brain" reference from 30 neutral sentences.
apply_patches.py
Makes TRIBE run on Apple Silicon and kills the Google-upload leak.
experiments/
The A1–A7 research scripts that proved the whole approach.
tests/ Ā· bench/
Labeled eval + accuracy harness, pytest suite, latency bench — the 86.1% report card.
launchd agent
Keeps the server alive 24/7 and respawns it on crash.
05

The stack

Swift Ā· SwiftUI Ā· AppKit Python Ā· FastAPI Ā· uvicorn MLX 4-bit (Apple GPU) Llama-3.2-3B Instruct TRIBE v2 Ā· PyTorch Ā· Metal Vision OCR Ā· ScreenCaptureKit launchd Ā· self-signed cert 100% on-device
06

Performance & testing

The detector is fast and now has a real report card.

~0.6s per ⌘B (was ~4s) gate PR-AUC 0.93 Ā· recall 0.78 macro-F1 0.37–0.49 Ā· ECE ~0.19 ~62% 3B Ā· 82.3% 14B Ā· ~73% top-2 (external)
Two-stage gate
A yes/no "is this manipulation?" first — stops greetings/facts/reviews being forced into a tactic.
External test set
300 independently-labeled examples across 6 vectors (dark-patterns + fallacy + clickbait) — the honest, never-tuned-on number.
bench_full.py
Macro-F1 + Wilson/bootstrap CIs, per-class, confusion, MCC, gate PR-AUC, and confidence calibration (ECE).
pytest suite
Contract, behavior, benign + realistic guards, taxonomy-drift, robustness, dark-pattern + interpersonal recall.

Measured honestly, then fixed — twice. On self-authored data it looked ~80% accurate; on 300 external, never-tuned-on examples it's 61% — up from 38% two sprints ago. Two fixes got it there, and they target different stages. First the gate: a diagnostic (gate_diag.py) traced a recall miss to e-commerce dark patterns the gate read as plain facts (fake social-proof nudges, scarcity, countdown timers, clickbait); teaching the gate each family — guarded so neutral stats/clocks/news stay benign — lifted gate recall 0.56 → 0.78 with no precision cost (PR-AUC 0.93). Then the technique label: stage-2 was collapsing everything into false-urgency, so it now routes by the primary lever — limited supply → FOMO, a deadline clock → false-urgency, other people's activity → social-proof, a reward or curiosity hook → dopamine, a name/credential → authority — which took accuracy 44 → 61% (macro-F1 0.18 → 0.37) with the gate untouched. Confidence can be Platt-calibrated (ECE → 0.10) but ships off so the % reads assertively — a deliberate choice. The taxonomy spans 14 vectors in two families: broadcast persuasion + an interpersonal family (guilt-tripping, love-bombing, blame-shifting/DARVO, gaslighting) — validated at 88% on a curated behavioral set. Two further levers on the 3B — few-shot exemplars and a LoRA fine-tune — both landed at the same ~62% (statistically tied): that was the small 4-bit model's ceiling, not the method's. Scaling the on-device model proved it — 3B 62% → 8B 69% → 14B 79%, and the 14B with few-shot reaches 82.3% (an opt-in high-accuracy mode; the fast 3B stays the default). Self-consistency voting looked like a win but was a confound (+0 once the test labels were cleaned), and the fine-tune never beat prompting. And since manipulation is usually two techniques at once, scored as top-2 the number is ~73% on the 3B and near 90% on the 14B — the honest question is "did we name it," not "which single label."

Litmus Ā· architecture overview Ā· detection = local Llama-3.2-3B Ā· interpretation = TRIBE v2 Ā· everything on-device, zero telemetry.
Companion to the full field manual (origins, experiments, and pivots). Repo: github.com/devansh-gr/Litmus. Updated 2026-08-07.