npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cortex-graph

v0.1.1

Published

Dual-Layer Codebase Knowledge Graph & Episodic Memory Engine for AI Coding Agents

Readme

Cortex

Dual-Layer Codebase Knowledge Graph & Episodic Memory Engine for AI Coding Agents.

License: MIT TypeScript Model Context Protocol


What is Cortex?

AI coding agents (Claude Desktop, Cursor, Cline, Devin) suffer from context amnesia:

  1. Context Window Decay: Multi-turn debugging sessions truncate past messages, causing the agent to forget earlier architectural decisions, failed attempts, and project rules.
  2. Context Bloat & Token Burn: Ingesting entire codebases (50,000+ tokens) into every prompt causes attention dilution, slow inference, and high API costs.
  3. Flat Search Blindness: Traditional text search (grep) and flat vector embeddings do not understand code hierarchy or why past changes were made.

Cortex solves this by constructing a local, self-evolving Dual-Layer Knowledge Graph that sits directly in your repository:

  • Layer 1 (Structural Codebase Topology): AST symbol interfaces, exports, imports, and cross-file dependencies.
  • Layer 2 (Episodic Intent Memory): Verified architectural decisions, gotchas, user invariants, and past bug-fix constraints.

When an agent executes a prompt, Cortex extracts a 2-hop causal subgraph and compresses it into a laser-focused < 2,500 token Context Slice, achieving a 97% reduction in context window footprint.

flowchart TD
    Prompt["1. User Prompt: 'Refactor Auth Route'"] --> Engine[Cortex Context Compactor]
    
    subgraph Cortex Dual-Layer Knowledge Graph
        AST["Layer 1: Structural AST Graph (Files / Types / Exports)"]
        Memory["Layer 2: Episodic Intent Memory (Decisions / Gotchas)"]
        AST <-->|Causal Edges| Memory
    end
    
    Cortex --> Engine
    Engine --> Slice["2. Compacted Context Slice (< 2,500 Tokens)"]
    Slice --> Agent["3. AI Coding Agent (Cursor / Claude / Cline)"]

Core Capabilities

  • Sub-2.5k Token Context Compactor: Converts 50k+ tokens of raw file churn into an ultra-dense, deterministic context slice containing exact blueprints, interfaces, and past decisions.
  • Append-Only Event Ledger: Memory updates record to chronological delta logs in .cortex/ledger/. Multiple developers and branches merge in Git with zero merge conflicts.
  • 3-Tier Verification Protocol: New agent insights start in tentative status and are promoted to verified status only when test suites pass (exit code 0), preventing hallucinated notes from poisoning memory.
  • Dynamic Blast Radius Calculator: Maps direct and indirect downstream file dependencies before an agent performs breaking refactors.
  • Drop-in Model Context Protocol (MCP): Native stdio server compatible with Claude Desktop, Cursor IDE, Cline, and Windsurf.

Quickstart

1. Initialize Cortex in Your Repository

npx cortex-memory init

This scans your codebase AST, detects your framework, extracts design system invariants, and writes .project-cortex.json.

2. Query Compact Context Slice

npx cortex-memory context "auth.service.ts"

3. Record an Architectural Decision

npx cortex-memory decision "Token Revocation Strategy" "Use Redis key TTL of 86400s instead of Postgres query." src/services/auth.ts src/db/redis.ts

4. Calculate Downstream Blast Radius

npx cortex-memory blast src/db/postgres.ts

Model Context Protocol (MCP) Integration

Add Cortex to your claude_desktop_config.json or .cursor/mcp.json:

{
  "mcpServers": {
    "cortex-memory": {
      "command": "npx",
      "args": ["-y", "cortex-memory", "mcp"]
    }
  }
}

Exposed MCP Tools:

  • cortex_get_context: Returns a compacted < 2,500 token markdown slice for a prompt or file query.
  • cortex_record_decision: Saves an architectural decision attached to affected files in project memory.
  • cortex_record_gotcha: Records an edge-case warning or constraint to prevent repeating mistakes.
  • cortex_blast_radius: Analyzes upstream and downstream affected files before code refactoring.
  • cortex_sync: Re-indexes AST to synchronize with recent code edits.

Architecture Overview

.
├── .cortex/
│   ├── graph.json            # Active Knowledge Graph cache
│   └── ledger/               # Append-only chronological delta logs (Git-safe)
├── bin/
│   └── cortex.js             # CLI Entrypoint
├── src/
│   ├── ast/                  # Tree-sitter & AST code scanner
│   ├── graph/                # Dual-layer graph engine & context compactor
│   ├── mcp/                  # Model Context Protocol stdio server
│   └── cli.ts                # Command line interface
├── web/                      # Interactive Visualizer Studio & Landing Page
└── package.json

License

MIT License (c) 2026 Bhavuk Arora. Designed for autonomous software engineering.