Skip to main content

Local-first self-analyzing platform for AI coding agents — context profiling, behavioral fingerprinting, outcome quality, measured optimize, and MCP.

Project description

Cairn watches what your AI agents actually do, profiles where every token goes,
learns each agent's behavioral fingerprint, ties behavior to real outcomes,
and rewrites your instruction files to fix the waste — then proves the fix worked.

License Python v0.0.1


30-second quickstart

pip install cairn-workspace
# or: uv tool install cairn-workspace

cd your-repo
cairn

Cairn detects installed agents, syncs their logs, computes metrics, starts a local dashboard at http://127.0.0.1:8787, and opens your browser. The server backgrounds automatically — use cairn stop to quit, or cairn --foreground to keep it in the terminal.

No account. No cloud. No config file required to start.


The five pillars

Context profiling — Decompose each turn into regions (system, tool schema, tool results, retrieved files, user, history). Surface re-billing waste and concrete fixes: cache, clear stale results, drop unused tools.

Behavioral fingerprinting — Compress each session into a behavioral vector. Detect drift with AMDM (Mahalanobis + per-axis EWMA). See when your agent's behavior changed and which axes moved.

Outcome-anchored quality — After sessions, capture git and test signals. Score process quality (not just pass/fail). Flag brittle "lucky pass" sessions.

Measured self-improvement — Propose instruction edits to CLAUDE.md, AGENTS.md, .cursor/rules. Apply with human approval. Measure before/after on a holdout window. Select rules via Thompson sampling.

Agent self-awareness (MCP) — Ship an MCP server so agents query Cairn mid-session: "have I read this file?", "what's my recurring waste?", "fetch the project primer". Auto-installs on first run (disable in Settings → MCP).


Supported agents

Agent Log source
Claude Code ~/.claude/projects/…/*.jsonl
Codex CLI ~/.codex/sessions/…/*.jsonl
Cursor state.vscdb (canonical) + agent transcripts
OpenCode ~/.local/share/opencode/sessions/
Goose ~/.local/share/goose/sessions/
Hermes ~/.hermes/sessions/*.json
Aider ~/.aider/chat-history/
Gemini CLI ~/.gemini/tmp/**, ~/.config/gemini/
Cline / Roo / Kilo VS Code globalStorage/…/tasks/*/ui_messages.json
OpenClaw ~/.openclaw/**

CLI quick reference

Command What it does
cairn Golden path: detect → sync → dashboard (background)
cairn --foreground / -f Same, but server stays in foreground
cairn stop Stop background dashboard
cairn sync Re-ingest agent logs
cairn show ID Session timeline + graph
cairn profile ID Context regions + waste findings
cairn behavior Fingerprint + drift
cairn outcomes Quality scores + cost-per-success
cairn optimize Evidence → instruction proposals
cairn check Preflight + CI gates
cairn check --min-quality 70 Fail if 7d mean quality score drops below 70
cairn mcp install Print MCP config block
cairn config get/set Edit ~/.config/cairn/config.toml
cairn advanced migrate Drop ledger + re-ingest (schema recovery)

Every dashboard action (sync, export, MCP install, check, optimize apply) is also a button in the UI.


Architecture (ASCII)

 agent logs ──► ingest/parsers ──► ledger.db ──► metrics + profile + outcomes
                                      │                    │
                                      ▼                    ▼
                              live/server.py ◄──── dashboard (vanilla JS)
                                      │
                                      ├── SSE /v2/events (live refresh)
                                      ├── MCP stdio bridge (agent tools)
                                      └── optimize loop → instruction files

Why Cairn

Tool What it does What Cairn adds
ccusage / Tokscale Spend dashboards + context profiling, fingerprint drift, measured optimize
ContextLens Single-prompt profiling Multi-agent, from local logs, no proxy
AgentAssay Behavioral fingerprinting Productized dashboard + drift alerts
Self-improvement CLIs Propose instruction edits Measures whether edits actually helped

Nobody else combines all five pillars and closes the loop with holdout measurement.


Privacy

Local-first. Ledger and dashboard stay on disk / 127.0.0.1. No telemetry, no accounts, no cloud sync. Export bundles are scrubbed of common secret patterns.


Install

curl -LsSf https://cairn.dev/install.sh | sh   # optional installer
pip install cairn-workspace
uv tool install cairn-workspace

Requires Python 3.11+. Runtime deps: httpx (optional LLM reflector), numpy (fingerprint math).


Documentation


Development

git clone https://github.com/Harsh-Daga/Cairn.git && cd Cairn
pip install -e ".[dev]"
python3 -m pytest tests/ -q

See CONTRIBUTING.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cairn_workspace-0.0.1.tar.gz (283.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cairn_workspace-0.0.1-py3-none-any.whl (257.7 kB view details)

Uploaded Python 3

File details

Details for the file cairn_workspace-0.0.1.tar.gz.

File metadata

  • Download URL: cairn_workspace-0.0.1.tar.gz
  • Upload date:
  • Size: 283.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cairn_workspace-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a2c304e7f37afb56befb3bdd8ddc92d303987abbc0e3e21aca75982ed3c79d38
MD5 8dcdf10fcb694fad35c3298ba17f4a2a
BLAKE2b-256 32827fb77980c4b70cabdfe0eb01d5ea855bfebf0ab577d8c45cef53efc07870

See more details on using hashes here.

File details

Details for the file cairn_workspace-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: cairn_workspace-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 257.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cairn_workspace-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bdf0f524173660edd788fdac0fe956a1b875e5df03cfc9fd9a8c68446f196e06
MD5 92458afad9274456129ae5b677b4997c
BLAKE2b-256 b9b8b0351edbc219c23941c6082ec3686edcf15b5cb0476cae5e0ef827bf23ff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page