🧠the-brain

Identity Anchor

Stable self-vector preventing catastrophic forgetting

The Identity Anchor plugin maintains a stable representation of your core coding identity across multiple training runs.

Why It Matters

Without an anchor, repeated LoRA training can cause catastrophic forgetting — the model drifts away from your fundamental preferences and coding style.

How It Works

  1. Capture: Watches SELECTION_PROMOTE for short, high-surprise declarative statements
    • Language-agnostic structural detection: 20-200 char fragments with surpriseScore ≥ threshold
    • No English keywords needed — works for Polish, Japanese, Chinese, any language
  2. Vectorize: Builds a self-vector from fragments with embeddings (requires ≥3 for stability)
  3. Detect Drift: Before each training run, computes cosine similarity between current and baseline
  4. Boost: If drift exceeds threshold, repeats anchor fragments N times in training data

Configuration

{
  "plugins": [
    {
      "name": "@the-brain-dev/plugin-identity-anchor",
      "enabled": true,
      "config": {
        "driftThreshold": 0.3,
        "boostFactor": 5,
        "maxAnchorFragments": 20
      }
    }
  ]
}

How It Integrates

During overnight training, the Identity Anchor injects boosted fragments before MLX training:

DEEP_CONSOLIDATE hook fires

Identity Anchor: computeDrift()
  ↓ drift > 0.3?
Identity Anchor: getBoostedFragments()

MLX Trainer: [boostedFragments, ...trainingData]

Regression Fingerprinting (Phase 2)

The Identity Anchor now includes a HarnessFingerprintStore for tracking per-model per-benchmark performance over time. This enables the-brain to serve as a cognitive layer for meta-harness systems.

How It Works

  1. Auto-update: ON_INTERACTION hook detects lm-eval source interactions and updates fingerprints
  2. Welford's algorithm: Running mean and std per model/benchmark/metric — no raw data storage needed
  3. Anomaly detection: >2σ from baseline triggers anomaly flag (>3 samples required for confidence)
  4. Drift detection: Sliding window Z-score against historical baseline

Custom Hooks

HookPurpose
identity-anchor:predictRegressionPredict expected score ranges for a model+benchmark pair
identity-anchor:assessSurpriseCompare observed score against fingerprint — returns z-score and anomaly flag
identity-anchor:getFingerprintsGet all stored performance fingerprints
identity-anchor:detectDriftCheck if a model is systematically degrading on a benchmark
identity-anchor:fingerprintSummaryHuman-readable summary of all stored fingerprints

Persistence

Fingerprints are stored at ~/.the-brain/identity/harness-fingerprints.json. The store is auto-saved when dirty and loaded on daemon start.

Multi-User Mode

In team mode, each user gets a dedicated identity file at ~/.the-brain/identity/{userId}.json. The identity-anchor:switchUser(userId) hook swaps active user state, and SELECTION_PROMOTE saves to the correct per-user file based on interaction metadata.

MCP Integration

These hooks are exposed via MCP tools (brain_predict_regression, brain_record_run, brain_get_fingerprint, etc.) for use by external meta-harness systems like AHE and Meta-Harness.

On this page