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

@mediagato/brain

v0.1.4

Published

Local-first PGlite brain — state, memories, steering, spore seeding. Shared engine across Companion, Mr. Mags, and any MEDiAGATO product that needs persistent local memory.

Readme

@mediagato/brain

A local-first PGlite memory engine. State, memories, steering, and spore seeding — all on the user's machine. Same Postgres dialect as the SaaS-side brain, no translation layer.

Why this exists

Intelligence data — memories, learned patterns, personal context — should live on the user's machine, not on a server. This package is the substrate that makes that real:

  • PGlite for the database (Postgres compiled to WASM, runs in-process)
  • Five tables mirroring how a brain thinks: state, memories, steering, review_lessons, brain_meta
  • Layer distinction between instance (user-created) and pattern (template-seeded)
  • Spore seeding for one-time setup with profession-specific patterns

It is the load-bearing engine across MEDiAGATO products that need persistent local memory: Companion (worker fleet brain), Mr. Mags (memory-only product for Claude Desktop, free for teachers forever — mrmags.org), and any future tool that wants the same primitive.

Install

npm install @mediagato/brain

Usage

const brain = require('@mediagato/brain');

// Initialize against any directory; a 'brain/' subdir is created inside it.
await brain.init(process.env.HOME);

// State — key/value config
await brain.setState('profession', 'teacher');
const profession = await brain.getState('profession');
// { value: 'teacher', layer: 'instance', updated_at: '2026-04-27T...' }

// Memories — filename-keyed long-form content
await brain.setMemory('lesson_plan_template.md', '# Lesson Plan\n...');
const note = await brain.getMemory('lesson_plan_template.md');

// Spore seed — one-time setup with pattern-layer templates
await brain.seedFromSpore({
  state: [{ key: 'subject_default', value: 'biology' }],
  memories: [{ filename: 'rubric.md', content: '# Rubric template' }],
  steering: [{ id: 'tone', name: 'Tone', content: 'Plain language.' }],
});

// Idempotent — re-seeding never overwrites user data
await brain.isSeeded();  // → timestamp string after first seed

// Cleanup on app quit
await brain.close();

API

Lifecycle

  • init(dataDir) — open the database under dataDir/brain/. Returns the underlying PGlite instance.
  • dbPath() — return the on-disk path of the database.
  • close() — close the database and release file handles.

Brain identity

  • getName() — returns the brain's name. Default: 'Bob'.
  • setName(name) — set the brain's name.

State

  • getState(key) — return { value, layer, updated_at } or null.
  • setState(key, value, updatedBy?) — upsert. updatedBy defaults to 'brain'.
  • getAllState() — return all rows ordered by key.
  • deleteState(key) — remove the row.

Memories

  • getMemory(filename) — return { content, layer, updated_at } or null.
  • setMemory(filename, content, updatedBy?, layer?) — upsert. Layer defaults to 'instance'.
  • getAllMemories() — return metadata for all memories (filename, layer, updated_at).

Spore seed

  • seedFromSpore(sporeData) — idempotent insert of pattern-layer templates. Pass { state, memories, steering }. Returns the count of rows attempted.
  • isSeeded() — return the seed timestamp or null.

Schema

CREATE TABLE state (
  key TEXT PRIMARY KEY,
  value TEXT NOT NULL,
  updated_by TEXT,
  updated_at TEXT NOT NULL,
  layer TEXT DEFAULT 'instance',
  anonymizable BOOLEAN DEFAULT true
);

CREATE TABLE memories (
  filename TEXT PRIMARY KEY,
  content TEXT NOT NULL,
  updated_by TEXT,
  updated_at TEXT NOT NULL,
  layer TEXT DEFAULT 'instance',
  anonymizable BOOLEAN DEFAULT true
);

CREATE TABLE steering (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL,
  content TEXT NOT NULL,
  mode TEXT NOT NULL DEFAULT 'always',
  match_pattern TEXT,
  priority INTEGER DEFAULT 0,
  enabled BOOLEAN DEFAULT true,
  layer TEXT DEFAULT 'instance',
  created_at TEXT NOT NULL,
  updated_at TEXT NOT NULL
);

CREATE TABLE review_lessons (
  id SERIAL PRIMARY KEY,
  task_type TEXT NOT NULL,
  rule TEXT NOT NULL,
  source_item_id INTEGER,
  layer TEXT DEFAULT 'instance',
  created_at TEXT NOT NULL
);

CREATE TABLE brain_meta (
  key TEXT PRIMARY KEY,
  value TEXT NOT NULL
);

License

MIT — see LICENSE.