Selvedge

by masondelan

374 downloads
Not rated
GitHub Website

About

Decision provenance for AI-coded codebases: the why, and what was already tried and rejected. Exports and imports Agent Trace v0.1.0, so captured history round-trips with the emerging open standard for AI code attributi

Details

Author
masondelan
Downloads
374
Categories
Developer Tools, Other, AI

- Append-only event log: entity, change type, diff, reasoning, verdict — rejected paths stay queryable forever (prior_attempts)
- 8 MCP tools at a CI-verified 3,705-token schema tax; deterministic, templated retrieval (no LLM in the path)
- Entity-level attribution (users.email, env/STRIPE_SECRET_KEY, deps/stripe) and changesets across many entities
- Delivery hooks (v0.3.10): a relevance-gated SessionStart digest and an advisory PreCompact heads-up — read-only, fail-open, quiet when there's nothing to say
- selvedge export --format markdown: a deterministic, diff-stable digest to commit next to .selvedge/
- Agent Trace v0.1.0 export and import
- Local SQLite, zero external dependencies, first-class .selvedge/config.toml

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Selvedge
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Install via pip install selvedge, then run selvedge setup — the wizard configures Claude Code, Cursor, and Copilot in one pass. Ask selvedge blame <entity> for the most recent change and its reasoning, or check prior attempts on an entity before re-implementing something the team may already have killed.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "selvedge": {
            "selvedge": {
                "command": "uvx",
                "args": [
                    "--from",
                    "selvedge",
                    "selvedge-server"
                ]
            }
        }
    }
}

McpServers

{
    "selvedge": {
        "command": "uvx",
        "args": [
            "--from",
            "selvedge",
            "selvedge-server"
        ]
    }
}

Long-term memory for AI-coded codebases — including what was already tried and rejected.

Line attribution tells you who wrote something. Selvedge tells your agent whatnotto write next: the approaches this codebase already tried, reverted, and why. It's agit blamefor AI agents, for thewhyrather than which model touched which line — captured live, by the agent, as the change happens, so nothing downstream has to guess at it.

Selvedge is a local MCP server. AI coding agents (Claude Code, Cursor, Copilot) call it as they work to log structured change events with reasoning. Your data stays in a SQLite file under.selvedge/next to your code.

Local-first by default, team-server by choice, zero-LLM always.

Six months ago, your AI agent added a column calleduser_tier_v2. You don't know why.git blamepoints to a commit fromclaude-codewith a generated message that says "Update schema." The session that made the change is long gone — and so is the prompt that produced it.

$ selvedge blame user_tier_v2 user_tier_v2 Changed 2025-10-14 09:31:02 Agent claude-code Commit 3e7a991 Reasoning User asked to add a grandfathering flag for legacy free-tier users during the pricing migration. Stores the original tier so we can backfill discounts without touching billing history.

That reasoning wascaptured by the agent in the moment— written into Selvedge from the same context that produced the change. Not inferred from the diff afterward by a second LLM. Not a hand-typed commit message.

Selvedge has two audiences. Same tool, samepip install, same SQLite file under.selvedge/. Different scale of pain.

Teams running long-term, AI-coded codebases.When the project is big enough that you (or someone else) will touch it again in six months, twelve months, three years — but most of it was written by an agent whose context evaporated the day each PR shipped.git blametells you what changed. Selvedge tells youwhy— even after the agent session, the prompt template, the developer who asked for it, and the model version are all long gone. This is the original use case: production codebases, schema decisions, migrations, dependency changes that need an audit trail that survives turnover.

Solo developers using Claude Code on everyday projects.Side projects, weekend builds, the small internal tool you keep poking at. You don't need enterprise governance — you just need to remember why you (or your agent) did the thing you did yesterday, last week, last sprint. Runselvedge initonce. Add four lines to yourCLAUDE.md. From then on,selvedge blameis muscle memory — a way to talk to your past self when your past self was an LLM.

If you've ever come back to your own AI-built project and thought "what was thisforagain?", Selvedge is the missing piece.

Human-written code leaks intent everywhere — commit messages, PR descriptions, inline comments, the Slack thread that preceded it. AI-written code doesn't. The agent has perfect clarity about why it made each decision, but that context lives in the prompt and evaporates when the conversation ends.

Six months later, your team is debugging a schema decision with no trail.git blametells youwhatchanged andwhen. It can't tell youwhy.

Selvedge captures the why — live, by the agent itself, as the change is made.The diff is git's job. The why is Selvedge's.

The memory comes to the agent, and the store gets its dials.Two themes, shipped together because the config half is what the rest needed to read settings from.

Delivery.Selvedge already blocked re-edits of reverted entities. What was missing was delivery when there is nothing to veto. Two new hooks:

- SessionStartinjects a compact digest as a session begins — decisions due for a revisit, entities that were tried and reverted, recent changesets.
- PreCompactfires just before context compaction destroys this session's reasoning and names the watched entities you edited but never logged.

Both are quiet when they have nothing to say, size-capped, read-only, and templated. Neither can block anything — PreCompact deliberately declines the veto the hook API offers it. This is the answer to a measured failure mode: two 2026 papers recorded pull-model memory tools going unused entirely (zero voluntary memory operations across 114 turns against a pre-seeded store) while deterministic injection landed every time.

selvedge export --format markdownrenders the store as a reviewable digest to commit next to it, so captured intent shows up in a pull request instead of hiding inside a binary. Deterministic — regenerating with no new events is a zero-line diff.

Config..selvedge/config.tomlis now first-class, with a canonical precedence chain thatselvedge doctorprints per setting. It brings:

- selvedge prune --include-events— the first path that can delete captured reasoning, so it needsbotha confirmation andSELVEDGE_DESTRUCTIVE=1. Neither alone is enough, because--yesin a cron entry defeats a prompt and a shell profile defeats an env var. Events retention defaults to never.
- Event-size bounds(diff_bytes,reasoning_bytes) that truncate loudly — a marker in the text, a warning at write time, a count inselvedge stats.
- Secret-shape warningsatlog_change, extendable viaredaction_patterns, plus adoctorrow that scans what's already stored. Warn, never reject.

Also:five review issues closed. The enforcement hook's allow path is40% faster(33.6 ms → 20.1 ms per gated call) andSELVEDGE_HOOK_DISABLE=1finally short-circuits before the imports it was documented to skip;log_changeno longer discardsrevisit_after/constraint/stale_whenon renames and supersedes; the CLI's--jsonand the MCP tools now return identical structures; and the Docker image no longer ships the maintainer's own database. Tests 826 → 984.

Fixes a broken install, and lands a full code-quality pass.mcp2.0.0 (released 2026-07-28) removedmcp.server.fastmcp, and Selvedge declaredmcp>=1.0.0with no upper bound — so anypip install selvedgeafter that date pulled 2.0.0 andselvedge-serverfailed at import. This release pins the dependency.If your server stopped starting, this is why — upgrade.

It ships alongside a review that put nine independent passes over the codebase and then tried todisproveevery finding before acting on it. Seventeen confirmed defects fixed. The ones you would actually have noticed:

- The enforcement hook stopped blocking things it shouldn't.Reading a tracked file —cat,git diff,pytest,ruff check— was blocked, and the remediation the error message told you to run was blocked by the same gate, so there was no way out from the CLI. Two more paths fed the same false blocks: a commented-out line of SQL counted as a real deletion, and any commit message merely containing the word "revert" marked every file it touched as reverted.
- Lookups got fast at scale.The main entity read was scanning every row — measured 7.4 ms → 0.35 ms at 100k events, and the hook had been taking seconds on large stores.
- selvedge setupcan no longer delete parts of yourCLAUDE.md, an interrupted backup can no longer destroy your last good one, and upgrading while two Selvedge processes are running no longer crashes with an error that looked like database corruption.

Tests went 739 → 826. No schema change and no tool-surface change, so this isdrop-in for anyone on 0.3.9.x.

AI agents call Selvedge as they work. Selvedge captures thewhyinto a durable, queryable store and emits it back out — asAgent Tracerecords for cross-tool readers, as observability metadata that links into Sentry/Datadog stack traces, and as compliance artifacts for SOC 2 and EU AI Act audits.

Selvedge doesnotreplacegit(line-level what/when), PR review tools (review-time quality), agent observability (LLM call traces), or general-purpose code-host AI features. It sits between them — the provenance-as-first-class-citizen layer that everything else references.

There's a fast-growing "git blame for AI agents" category. Here's where Selvedge fits — and where it deliberately doesn't.

Why "rejected paths" matter — the one that isn't copyable.The expensive failure isn't forgetting why a column exists. It's an agent confidently re-implementing something the team already killed for a good reason, six months after everyone who knew that left the context window. None of the line-attribution tools above surface rejected paths at all, and it isn't a feature gap they can close in a release — a line-oriented store has no notion of an entity that persisted across a try → revert → retry cycle. Seedocs/demos/prior-attempts.md.

Why determinism matters.Selvedge's reasoning is the agent's own intent, written from the same context window that produced the change. There is no model anywhere in the storage or retrieval path, so the same query returns the same answer today and in two years, across model versions. Tools that infer reasoning post-hoc are running a second LLM that never saw the original prompt: what it produces is paraphrase, and re-running it can produce different categories for the same change. As a Hacker News commenter put it about a competing approach,"grep won't find your commit because you rejected 'oauth-library'… unless there is deterministic enforcement"(0x457).

Determinism alone is no longer a separator — OpenLore is deterministic-native too, and says so. The compound that separates isappend-only testimony: reasoning the agent wrote itself, kept in a store where a rejection is a first-class record rather than an inactive status to be swept up.

Why "entity-level" matters.Most tools attributelines. Selvedge attributesthings you actually search for:users.email,env/STRIPE_SECRET_KEY,api/v1/checkout,deps/stripe. The first question aftergit blameis usually"what's the history of this column", not"what's the history of lines 40–48 of users.py".

Why "captured live" matters.Not a differentiator on its own — every tool here claims some flavour of it — but it's themechanismthat makes the reasoning trustworthy. Writing at the moment of the change, from the context that produced it, is the reason there's no second model in the path to hallucinate an explanation. An emptyreasoningfield is itself an honest signal: the agent didn't have one.

Comparison current as of 2026-08-05; OpenLore at v2.1.8 / 265★, verified against its source. Corrections welcome as an issue.

Why "changesets" matter.A Stripe billing rollout touches theuserstable, two new env vars, three new API routes, one dependency, and four functions across the codebase. Tag every event withchangeset:add-stripe-billingand you can pull the entire scope back later — even if the original PR was broken into eight smaller ones over a month.

Selvedge ↔ Agent Trace.Agent Traceis an open AI code-attribution wire format published by Cursor (RFC, Jan 2026). Its original GitHub home went 404 in August 2026 and the multi-vendor momentum behind it has faded, but the spec and schema still resolve at agent-trace.dev, frozen at v0.1.0. Sincev0.3.9,selvedge export --format agent-traceemits Agent Trace v0.1.0 records andselvedge import --format agent-tracereads them back — a portable, documented interchange format for file/line AI attribution, with reasoning and entity-level provenance carried in each record'sdev.selvedgemetadata. The mapping is indocs/agent-trace-interop.md; Selvedge vendors the schema and has no runtime dependency on the upstream project.

Claude Code — install the plugin (recommended)

Two commands, inside Claude Code. No priorpip install— the plugin bootstraps the server itself viauvx(orpipx):

/plugin marketplace add masondelan/selvedge /plugin install selvedge@selvedge

That's the whole agent-facing surface in one step:

- theMCP server— 8 tools (log_change,prior_attempts,blame,diff,history,changeset,search,stale_decisions);
- askillthat tells the agentwhento call them — before editing a tracked entity, after any substantive change;
- thePreToolUse enforcement hook— schema/migration edits are blocked untilprior_attemptshas been checked this session, with the prior reasoning in the block message;
- slash commands/selvedge:status,/selvedge:blame <entity>,/selvedge:history,/selvedge:prior-attempts <entity>.

The store (.selvedge/selvedge.db) creates itself on the first logged change. Two optional extras stay CLI-side: the post-commit hook that stamps each event with its commit hash (selvedge install-hook), and — if you want theselvedgecommand on your own shellPATHpip install selvedge, which the launcher then prefers overuvxfor an exact pinned version.

Plugin orselvedge setupfor Claude Code? Pick one.Both wire the MCP server; running both registers it twice. The plugin is the lighter path and the one that updates itself. If you're on the plugin and only want the post-commit commit-hash stamping, runselvedge install-hookon its own.

Cursor, Copilot, Windsurf, Codex CLI, Gemini CLI, and the rest:

pip install selvedge cd your-project selvedge setup

That's it.selvedge setupis an interactive wizard: it detects which AI tools you have (Claude Code, Cursor, Copilot), writes the MCP entry into each one's config, drops the canonical agent-instructions block into your project's prompt file (CLAUDE.md/.cursorrules/copilot-instructions.md), installs the PreToolUse enforcement hook into.claude/settings.json(Claude Code only — blocks schema/migration edits untilprior_attemptshas been checked;--skip-enforcement-hookto opt out), runsselvedge init, and installs the post-commit hook. Every modified file gets a.bakwritten next to it before any change reaches disk. Re-running is a no-op.

For CI bootstrap ordevcontainer.jsonpostCreateCommand:

Verify the wiring— open a second terminal in the same project:

Make any change in your AI tool — add a column, rename a function, add an env var.selvedge watchshould print the new event within a second of the agent callinglog_change. If nothing arrives, runselvedge doctorfor a single-command health check that tells you which step is silently broken.

selvedge status # recent activity + missing-commit count selvedge diff users # all changes to the users table selvedge diff users.email # changes to a specific column selvedge blame payments.amount # what changed last and why selvedge history --since 30d # last 30 days of changes selvedge history --since 15m # last 15 minutes ('m' = minutes) selvedge changeset add-stripe-billing # all events for a feature/task selvedge search "stripe" # full-text search selvedge stats # log_change coverage report (per-agent) selvedge import migrations/ # backfill from migration files selvedge export --format csv # dump history to CSV

If you don't want to run the wizard, the four manual steps it automates:

Selvedge is a standard stdio MCP server, so it works with any MCP client — Claude Code, Cursor, Windsurf, Codex CLI, Gemini CLI, and more. SeeWorks with any MCP clientfor the exact config per client. For Claude Code:

claude mcp add selvedge -- selvedge-server

Point--installat whichever prompt file your client reads — the block itself is identical across clients:

This installs the canonical agent-instructions block, sentinel-bracketed (<!-- selvedge:start -->/<!-- selvedge:end -->) so future--installcalls update the bracketed region without disturbing anything else in the file. Or pipe it:

Prefer to copy-paste? The same block is one click away on the website:selvedge.sh/prompt-block— with a copy button and notes on what your agent does with it.

That's the same four steps the wizard runs.

Selvedge is a standard stdio MCP server — its launch command isselvedge-server, put on yourPATHbypip install selvedge. Any MCP-capable client can run it. Pick yours:

claude mcp add selvedge -- selvedge-server

Or commit a project-level.mcp.jsonso your whole team gets it:

{ "mcpServers": { "selvedge": { "command": "selvedge-server" } } }

Docs:https://code.claude.com/docs/en/mcp

.cursor/mcp.json(project) or~/.cursor/mcp.json(global):

{ "mcpServers": { "selvedge": { "command": "selvedge-server" } } }

Cursor's newer schema also accepts an explicit"type": "stdio"; thecommand-only form works too (Cursor infers stdio fromcommand). Docs:https://cursor.com/docs/mcp

{ "mcpServers": { "selvedge": { "command": "selvedge-server" } } }

Windsurf hot-reloads the file — no restart needed. The in-appPlugins → View raw configbutton opens the exact file Cascade reads. Docs:https://docs.windsurf.com/windsurf/cascade/mcp

[mcp_servers.selvedge] command = "selvedge-server"

Or runcodex mcp add selvedge -- selvedge-server. Docs:https://developers.openai.com/codex/config-reference

~/.gemini/settings.json(or.gemini/settings.jsonper project):

{ "mcpServers": { "selvedge": { "command": "selvedge-server" } } }

Or rungemini mcp add -s user selvedge selvedge-server. Docs:https://github.com/google-gemini/gemini-cli/blob/main/docs/tools/mcp-server.md

Most clients share the same JSON shape — point yours at:

{ "mcpServers": { "selvedge": { "command": "selvedge-server" } } }

Ifselvedge-serverisn't found, use its absolute path (which selvedge-server).

Selvedge runs as an MCP server. AI agents in tools like Claude Code call Selvedge's tools as they work — logging structured change events to a local SQLite database.

- Whatchanged (entity path, change type, diff)
- When(timestamp)
- Who(agent, session ID)
- Why(reasoning — captured from the agent's context in the moment)
- Where(git commit, project)

The diff is git's job. Thewhyis Selvedge's.

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.