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

@wolfx/pi-magic-context

v0.38.0

Published

Pi and OMP coding agent extension for Magic Context — cross-session memory and context management

Readme

Magic Context — Pi / OMP extension

Cross-session memory and context management for Pi coding agent and Oh My Pi (OMP). The same extension package runs on both hosts and shares its SQLite database with the OpenCode plugin.

Requires Pi >= 0.74.0 or OMP >= 17.1.7.


What it does

Magic Context is a context engine that keeps long Pi sessions productive by:

| Feature | What it does | |---|---| | Tagging + drops | Tags every assistant/user/tool message with §N§ so you can drop specific turns later via ctx_reduce | | Historian | Background subagent compresses old conversation into compartments + facts at threshold pressure or commit boundaries | | <session-history> injection | Prepends compressed history into the system prompt every turn so the agent never loses context | | Project memories | Persistent cross-session knowledge store with embedding-based semantic search | | Dreamer | Scheduled background subagent that consolidates, verifies, archives, and improves stored memories | | /ctx-aug | On-demand sidekick that augments the next turn with relevant memories | | Auto-search hint | When user prompts mention previously-discussed topics, appends a compact memory hint | | Note nudges | Surface deferred intentions at natural work boundaries (commit, todo completion, historian publication) | | Cross-harness sharing | Memories written from OpenCode appear in Pi (and vice versa) for the same project |


Installation

The fastest path is the unified Magic Context CLI — --harness pi selects the Pi-specific setup pipeline (registers the extension with Pi, writes a sensible magic-context.jsonc, and verifies your model picks):

npx @wolfx/magic-context@latest setup --harness pi

This handles everything for you:

  1. Adds npm:@wolfx/pi-magic-context to Pi's packages array in ~/.pi/agent/settings.json (the same place pi install writes to)
  2. Creates ~/.config/cortexkit/magic-context.jsonc with defaults
  3. Prompts you for historian, dreamer, sidekick, and embedding model choices
  4. Warns about provider-specific gotchas (e.g. GitHub Copilot reasoning models need an explicit thinking_level)

If you'd rather register the Pi extension package directly with Pi (skipping the wizard), use Pi's own installer:

pi install npm:@wolfx/pi-magic-context

This adds the extension to ~/.pi/agent/settings.json but won't write magic-context.jsonc for you — create the shared config manually at ~/.config/cortexkit/magic-context.jsonc (see Configuration below).

To check installation health later:

npx @wolfx/magic-context@latest doctor --harness pi

Oh My Pi (OMP)

Use the OMP-specific setup path. It installs the package through OMP's plugin manager, disables OMP native compaction and automatic memory to prevent duplicate context managers, and verifies the effective project plugin state:

npx @wolfx/magic-context@latest setup --harness omp

Manual installation is also supported:

omp plugin install @wolfx/pi-magic-context
omp config set compaction.enabled false
omp config set memory.backend off

Verify with:

npx @wolfx/magic-context@latest doctor --harness omp

OMP's legacy Pi loader maps @earendil-works/* imports to its bundled @oh-my-pi/* runtime. Magic Context also re-invokes the current host executable for historian, dreamer, and sidekick children, so OMP children remain OMP processes.


Configuration

Magic Context reads the shared CortexKit config (project overrides user):

  1. $cwd/.cortexkit/magic-context.jsonc
  2. ~/.config/cortexkit/magic-context.jsonc

Session discovery follows the active host. Relative pi.subagent_extensions are deliberately isolated by host: plain Pi resolves them from ~/.pi/agent, while a positively identified OMP process uses PI_CODING_AGENT_DIR when set and otherwise derives the active ~/.omp config/profile agent directory.

Minimal config

{
  "$schema": "https://raw.gitcode.com/wolfx/magic-context/raw/custom/assets/magic-context.schema.json",
  "enabled": true,
  "historian": {
    "model": "anthropic/claude-haiku-4-5"
  },
  "embedding": {
    "provider": "local"
  }
}

For the full configuration reference (including dreamer, sidekick, auto-search, and experimental features), see CONFIGURATION.md in the main repository — OpenCode, Pi, and OMP share the same schema.


Slash commands

All commands trigger triggerTurn: false (never sent to the LLM):

| Command | What it does | |---|---| | /ctx-status | Live token breakdown + queued ops + cache state | | /ctx-flush | Force-process pending ops queue | | /ctx-recomp | Rebuild compartments from raw history (heavy operation) | | /ctx-wrapup [messages_to_keep] | Compact older live history while keeping the newest N messages raw | | /ctx-dream | Trigger a dream run on demand | | /ctx-aug | Augment your next prompt with sidekick-retrieved memories |


Storage

Magic Context stores everything in a single shared SQLite database at:

~/.local/share/cortexkit/magic-context/context.db

This is the same database the OpenCode plugin and OMP extension use. Tables are scoped by:

  • harness column ('pi' or 'opencode') for session-scoped data; OMP intentionally uses 'pi'
  • project_path (resolved git root) for project-scoped data (memories, embeddings, dreamer runs)

Memories and dreamer state are shared across all three harnesses for the same project; per-session tagging stays correctly attributed.

Storage failures are fatal — Magic Context will refuse to register hooks rather than run with ephemeral state, since that would let context grow unbounded across restarts.


Cross-harness coherence

For semantic search to work across harnesses, every host must use the same embedding model. Magic Context detects a mismatch on Pi or OMP startup and warns:

WARN embedding model mismatch detected for project ...:
stored vectors use "openai-compatible:Qwen/Qwen3-Embedding-8B" but Pi is configured with "local:Xenova/all-MiniLM-L6-v2".
Cross-harness search will return zero results until vectors are re-embedded.

Configure embedding once in the shared ~/.config/cortexkit/magic-context.jsonc; OpenCode, Pi, and OMP all read it. Use $cwd/.cortexkit/magic-context.jsonc only when that project intentionally needs an override.


Tools available to the agent

| Tool | Action set | Purpose | |---|---|---| | ctx_search | n/a | Search memories + raw session history; returns ranked results with previews | | ctx_memory | write, delete | Manage project memories explicitly (most writes happen via dreamer instead) | | ctx_note | read, write, update, dismiss | Defer intentions for later — surfaced via note nudges at work boundaries | | ctx_expand | start/end, message, verbose | Recover complete messages or expand a compressed conversation range | | ctx_reduce | drop | Queue tagged turns for cache-safe removal from the live context |

ctx_note, ctx_expand, and ctx_reduce are session-scoped and are exposed in primary Pi/OMP sessions. Magic Context omits them from ephemeral --no-session child processes, where they would otherwise target the hidden child session; ctx_reduce is additionally omitted when compaction is disabled.


Architecture & implementation

This package is part of the magic-context monorepo. Pi and OMP share the same adapter layer and core implementation:

| Pi-specific module | Responsibility | |---|---| | context-handler.ts | Pi pi.on("context", ...) adapter — tags, drops, runs nudges and auto-search | | subagent-runner.ts | Re-invokes the current Pi/OMP host with --print --mode json --no-session; resolves relative allowlisted extensions from plain Pi's ~/.pi/agent or an identified OMP host's active agent directory; and applies per-agent tool isolation | | tools/ | Pi pi.registerTool wrappers around the shared tool implementations | | commands/ | Pi pi.registerCommand wrappers for the five /ctx-* slash commands | | dreamer/ | Pi-side adapter for the shared dreamer scheduler | | system-prompt.ts | Pi before_agent_start injector for <session-history>, <project-memory>, <project-docs> | | config/ | Shared CortexKit config loader with legacy Pi migration fallback |

The unified @wolfx/magic-context CLI exposes separate pi and omp setup/doctor pipelines while both use this runtime adapter.

For deeper architectural detail, see the main repo's ARCHITECTURE.md.


License

MIT — see LICENSE.