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

@slorenzot/memento-core

v2.1.0

Published

Core memory engine for Memento with bun:sqlite, FTS5 search, semantic search, soft delete, merge, journal, and export

Readme

@slorenzot/memento-core

NPM Version License: CC BY-NC-ND 4.0 TypeScript

Core memory engine with SQLite FTS5 search, session management, and observation persistence for AI coding agents.

🚀 Installation

# Using Bun (recommended)
bun add @slorenzot/memento-core

# Using npm
npm install @slorenzot/memento-core

💡 Basic Usage

TypeScript

import { MemoryEngine } from '@slorenzot/memento-core';

// Initialize memory engine
const memory = new MemoryEngine('./data/memento.db');

// Create an observation
const observation = await memory.createObservation({
  title: 'Architecture decision',
  content: 'Use SQLite as the database engine',
  type: 'decision',
  topicKey: 'architecture',
  projectId: 'my-project'
});

console.log('Observation saved:', observation);

Shell/Bun

# Run TypeScript script with memory engine
bun run memory-script.ts

🔧 Core API

Main Class

MemoryEngine(dbPath?: string)

Memory engine constructor.

Parameters:

  • dbPath (optional): Path to the SQLite database file. Default: './data/memento.db'

Example:

const memory = new MemoryEngine('./custom/path.db');

Observation Methods

createObservation(data)

Creates a new observation in memory.

Parameters:

{
  title: string;
  content: string;
  type: 'decision' | 'bug' | 'discovery' | 'note';
  topicKey?: string | null;
  projectId: string;
  sessionId?: number;
  metadata?: Record<string, unknown>;
}

Returns: Promise<Observation>

Example:

const observation = await memory.createObservation({
  title: 'Bug found',
  content: 'Server connection error',
  type: 'bug',
  projectId: 'project-123',
  metadata: { severity: 'high', priority: 1 }
});

search(params)

Searches observations using FTS5 full-text search.

Parameters:

{
  query?: string;
  type?: 'decision' | 'bug' | 'discovery' | 'note';
  projectId?: string;
  topicKey?: string;
  limit?: number;
  offset?: number;
}

Returns: Promise<SearchResult>

Example:

const results = await memory.search({
  query: 'database architecture',
  type: 'decision',
  projectId: 'project-123',
  limit: 10
});

console.log(`Found ${results.total} observations:`);
results.observations.forEach(obs => console.log(obs.title));

getObservation(id)

Gets an observation by its ID.

Parameters:

  • id: Numeric ID of the observation

Returns: Promise<Observation | null>

Example:

const observation = await memory.getObservation(123);
if (observation) {
  console.log('Observation found:', observation.title);
}

updateObservation(id, updates)

Updates an existing observation.

Parameters:

  • id: Numeric ID of the observation
  • updates: Object with fields to update

Returns: Promise<Observation>

Example:

const updated = await memory.updateObservation(123, {
  title: 'Updated title',
  content: 'Modified content'
});

deleteObservation(id)

Deletes an observation by its ID.

Parameters:

  • id: Numeric ID of the observation

Returns: Promise<void>

Example:

await memory.deleteObservation(123);
console.log('Observation deleted');

Session Methods

createSession(data)

Creates a new session for conversation tracking.

Parameters:

{
  projectId: string;
  metadata?: Record<string, unknown>;
}

Returns: Promise<Session>

Example:

const session = await memory.createSession({
  projectId: 'my-project',
  metadata: { agent: 'claude', userId: 'user-123' }
});

console.log('Session started:', session.uuid);

getSession(id)

Gets a session by its ID.

Parameters:

  • id: Numeric ID of the session

Returns: Promise<Session | null>

Example:

const session = await memory.getSession(456);
if (session) {
  console.log('Session found:', session.uuid);
}

endSession(id)

Ends an active session.

Parameters:

  • id: Numeric ID of the session

Returns: Promise<Session>

Example:

const endedSession = await memory.endSession(456);
console.log('Session ended:', endedSession.endedAt);

Close Method

close()

Closes the database connection.

Returns: void

Example:

// On application cleanup
memory.close();

📝 Core Types

interface Observation {
  id: number;
  uuid: string;
  sessionId: number;
  title: string;
  content: string;
  type: 'decision' | 'bug' | 'discovery' | 'note';
  topicKey: string | null;
  projectId: string;
  createdAt: Date;
  metadata: Record<string, unknown>;
}

interface Session {
  id: number;
  uuid: string;
  projectId: string;
  startedAt: Date;
  endedAt: Date | null;
  metadata: Record<string, unknown>;
}

interface SearchParams {
  query?: string;
  type?: Observation['type'];
  projectId?: string;
  topicKey?: string;
  limit?: number;
  offset?: number;
}

interface SearchResult {
  observations: Observation[];
  total: number;
}

⚡ Practical Examples

Example 1: Complete Memory Workflow

import { MemoryEngine } from '@slorenzot/memento-core';

const memory = new MemoryEngine('./memory.db');

// Create session for tracking
const session = await memory.createSession({
  projectId: 'my-app',
  metadata: { agent: 'claude' }
});

// Save observations during work
await memory.createObservation({
  sessionId: session.id,
  title: 'Server configuration',
  content: 'Use Express.js with security middleware',
  type: 'decision',
  projectId: 'my-app',
  topicKey: 'backend'
});

await memory.createObservation({
  sessionId: session.id,
  title: 'Authentication bug',
  content: 'JWT not expiring correctly',
  type: 'bug',
  projectId: 'my-app',
  topicKey: 'security'
});

// Search for related decisions
const decisions = await memory.search({
  type: 'decision',
  projectId: 'my-app'
});

console.log('Decisions made:', decisions.observations);

// End session
await memory.endSession(session.id);

// Close connection
memory.close();

Example 2: Advanced Search

import { MemoryEngine } from '@slorenzot/memento-core';

const memory = new MemoryEngine('./memory.db');

// Complex search with multiple filters
const results = await memory.search({
  query: 'database architecture',
  type: 'decision',
  projectId: 'my-app',
  limit: 5,
  offset: 10
});

console.log(`Total results: ${results.total}`);
results.observations.forEach((obs, index) => {
  console.log(`${index + 1}. ${obs.title}`);
  console.log(`   ${obs.content.substring(0, 100)}...`);
  console.log(`   Type: ${obs.type} | Topic: ${obs.topicKey}`);
});

memory.close();

⚠️ Restrictive License

This package is under CC BY-NC-ND 4.0 License:

  • Personal and educational use permitted
  • Share with attribution to the author
  • Commercial use NOT permitted
  • Modifications or forks NOT permitted

Author: Soulberto Lorenzo ([email protected])

🔄 Dependencies

Main Dependencies

  • zod - Schema validation
  • nanoid - Unique ID generation

Peer Dependencies

  • bun v1.0+ (recommended)
  • node v20+ (compatible)

🛠️ Development

# Clone the project
git clone https://github.com/slorenzot/memento.git
cd memento/packages/core

# Install dependencies
bun install

# Development
bun run dev

# Build
bun run build

# Tests
bun test

📋 Changelog

[0.1.0] - 2024-04-04

  • Added: Initial version of the memory engine
  • Added: SQLite with FTS5 for full-text search
  • Added: Session and observation management
  • Added: Full TypeScript support

👤 Author

Soulberto Lorenzo

📄 License

This package is licensed under Creative Commons Attribution-NonCommercial-NoDerivs 4.0 International.

View Full License


⚠️ Important: This package has a restrictive license. Please respect the CC BY-NC-ND 4.0 license terms.

📖 Spanish version (Versión en español)