memorylint

vsuperpowers-bridge-v1.9.0

Evidence-driven instruction drift checker: audits agent memory files for boundary, reality, conflict, and redundancy drift.

Community extension — Independently maintained. Use at your own discretion. Learn more

MemoryLint

Evidence-driven instruction drift checker for Spec Kit.

MemoryLint audits long-lived agent instruction files — AGENTS.md, .specify/memory/constitution.md, CLAUDE.md, .cursor/rules/, and other sources — to detect boundary violations, stale references, conflicts, and redundancies. Every finding is backed by concrete evidence so reviewers can trust the report before applying any changes.

The current implementation includes executable helpers for all three surfaces:

  • scripts/audit_workspace.py
  • scripts/apply_report.py
  • scripts/load_agents_state.py

Problem Statement

In Spec-Driven Development (SDD), AI agents rely on long-lived instruction files:

  1. AGENTS.md: Infrastructure rules, environment setup, and workflow standards.
  2. .specify/memory/constitution.md: Architecture decisions, code paradigms, and safety constraints.
  3. Additional sources: CLAUDE.md, .cursor/rules/, README.md, workflow configs.

Over time, these files drift:

  • Boundary drift: Architecture rules leak into AGENTS.md, or workflow rules end up in the constitution.
  • Reality drift: Rules reference scripts, tools, or directories that no longer exist.
  • Conflict drift: Two files give contradictory instructions.
  • Redundancy drift: The same rule appears in multiple files, risking future divergence.

Solution: Evidence-Driven Drift Checking

MemoryLint follows a strict pipeline that separates audit from apply:

┌─────────────────────┐
│ Instruction Inventory│  Scan all long-lived instruction sources
└──────────┬──────────┘
           ▼
┌─────────────────────┐
│ Rule Classification  │  Categorise each rule (8 categories)
└──────────┬──────────┘
           ▼
┌─────────────────────┐
│ Evidence Binding     │  Attach file/command proof to every finding
└──────────┬──────────┘
           ▼
┌─────────────────────┐
│ Drift Detection      │  Detect boundary, reality, conflict, redundancy
└──────────┬──────────┘
           ▼
┌─────────────────────┐
│ Drift Report         │  Structured, reviewable report (read-only)
│                     │  Markdown + memorylint-report.json
└──────────┬──────────┘
           ▼
┌─────────────────────┐
│ Human Apply Gate     │  3-tier: report-only / safe-fixes / all-approved
└──────────┬──────────┘
           ▼
┌─────────────────────┐
│ Post-Apply Validation│  Integrity checks + automatic rollback on failure
└─────────────────────┘

Commands

CommandTypePurpose
speckit.memorylint.auditHookableScan instruction files and generate an evidence-bound Drift Report. Read-only — never modifies files.
speckit.memorylint.applyManualApply approved fixes from a previous audit report. Supports three apply modes with post-apply validation and rollback.
speckit.memorylint.load-agentsHookableMandatory gate: load AGENTS.md into context before planning to prevent rule drift.

Hook Integration

This extension registers the following Spec Kit lifecycle hooks:

HookCommandRequired?Purpose
before_constitutionauditOptionalGenerate a boundary report before constitution generation
after_constitutionauditOptionalCheck for conflicts between constitution and AGENTS.md
before_planload-agentsMandatoryLoad AGENTS.md to enforce core rules before plan generation

Key design constraint: hooks only run read-only operations. The apply command is never wired to a hook — it is always an explicit user action.

Canonical Ownership Matrix

MemoryLint now applies one canonical ownership matrix during audit:

CategoryCanonical OwnerNotes
architecture.specify/memory/constitution.mdeditor rules may restate, but do not own
domain.specify/memory/constitution.mdmanifests and docs may reflect, but do not own
infrastructureroot AGENTS.mdnested/editor sources may scope or mirror
workflowroot AGENTS.mdnested/editor sources may scope or mirror
toolingroot AGENTS.mdtool-specific files may add local detail
personal_preferenceroot AGENTS.mdeditor-specific restatements are secondary

This matrix is what drives recommended_destination, redundancy cleanup, and constitution handoff generation.

Agent-Context Coexistence

The upstream agent-context extension (a full opt-in as of Spec Kit 0.12) maintains a machine-generated managed block in agent context files, delimited by <!-- SPECKIT START --> / <!-- SPECKIT END -->. MemoryLint treats that block as off-limits:

  • Rule extraction skips every managed block across all configured context_files (resolved from .specify/extensions/agent-context/agent-context-config.yml, reading plural context_files then singular context_file; defaults to the markers above). Files are also filtered defensively if they physically contain the start marker.
  • No finding or edit ever targets a managed-block line, so agent-context updates and MemoryLint fixes do not fight over the same lines.
  • An unterminated block fails safe (skipped to end of file) with a warning.
  • apply already refuses to write when a target file changed since the audit (whole-file staleness check) — common when agent-context rewrites its block between audit and apply — and directs you to re-run the audit.

MemoryLint works identically whether or not agent-context is enabled.

Apply Modes

ModeBehaviour
report-onlyDefault. Re-display the report summary without making changes.
apply-safe-fixesApply only high-confidence, non-architectural fixes: dead reference removal, deduplication, formatting.
apply-all-approvedApply every fix the user has explicitly approved. Requires confirmation.

After applying, MemoryLint validates:

  1. AGENTS.md structural integrity (critical sections preserved).
  2. Constitution rule preservation (no accidental deletions).
  3. Hook reference consistency (all extension.yml hooks still valid).
  4. Repository validation commands pass.

If any validation fails, all changes are automatically reverted.

Report Contract

Every audit produces two synchronized outputs:

  • A human-readable Markdown Drift Report for review.
  • A fenced memorylint-report.json artifact that tools can parse.

The JSON artifact is the authoritative input for speckit.memorylint.apply. It includes schema_version, source_metadata, instruction_map, findings, and metrics. source_metadata records SHA-256 hashes for scanned files so the apply gate can reject stale reports before changing anything.

Executable findings may also include:

  • edits: line-scoped file operations used by the apply gate
  • manual_handoff: constitution-targeted handoff material that must be reviewed by a human

Rule Classification

Every rule is classified into one of eight categories:

CategoryMeaning
infrastructureCI, packaging, release mechanics, build/test commands
architectureDirectory layout, module boundaries, design patterns
workflowGit hygiene, review process, commit conventions
domainProduct behaviour, Spec Kit hook semantics
toolingCLI tools, language runtimes, editor config
personal_preferenceStyle choices that do not affect correctness
obsoleteReferences something that no longer exists
conflictContradicts another rule

Audit Metrics

Every audit report now emits run-time metrics that match the executable output:

MetricPurpose
Total instruction sources scannedShows workspace coverage
Total rules cataloguedShows extracted rule inventory size
Total findingsShows total actionable/non-actionable drift
High-confidence findingsIndicates directly evidenced findings
Medium-confidence findingsIndicates heuristic findings that need review
Low-confidence findingsIndicates weak-evidence findings
Files that would be modified by suggested actionsPowers safe preview and apply gating

Longitudinal trust KPIs such as false-positive rate or destructive surprise edits remain release-evaluation signals, not per-run report fields.

Regression Corpus

MemoryLint includes a regression corpus of nine fixture repos under tests/fixtures/:

FixtureTests
clean-repoZero findings baseline
bloated-agentsBoundary drift detection
stale-commandReality drift detection
conflicting-rulesConflict drift detection
redundant-rulesRedundancy drift detection
missing-constitutionGraceful handling of absent files
monorepo-nestedNested instruction file support
multi-sourceMulti-tool instruction scanning
post-apply-breakageApply safety validation

The fixture corpus is executable. memorylint/scripts/scan_fixtures.py --check re-runs the real audit core against every fixture and compares the normalized findings with each fixture's expected-findings.json.

Design

See DESIGN.md for the product boundary, trust model, audit/apply pipeline, machine-readable report contract, and release criteria.

Installation

Install from ZIP (Recommended)

specify extension add memorylint --from https://github.com/RbBtSn0w/spec-kit-extensions/releases/download/memorylint-v1.8.0/memorylint.zip

Install from GitHub Repository (Development)

git clone https://github.com/RbBtSn0w/spec-kit-extensions.git
cd spec-kit-extensions
specify extension add --dev ./memorylint

Requirements

  • Spec Kit: >=0.5.1

License

MIT — see LICENSE.

Stats

25 stars

Version

superpowers-bridge-v1.9.0release
Updated 19 days ago

Install

Using the Specify CLI

specify extension add memorylint --from https://github.com/RbBtSn0w/spec-kit-extensions/releases/download/memorylint-v1.5.1/memorylint.zip

Owners

License

MIT