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

@simulacra-ai/session

v0.0.8

Published

Session persistence for the Simulacra conversation engine with pluggable file, in-memory, and database storage

Readme

Simulacra Session

The session package makes Simulacra conversations durable. Conversations are stateful, but that state lives in memory and disappears when the process exits. The session manager handles saving, loading, and labeling sessions with pluggable storage backends. Sessions can be resumed across process restarts, forked into branches, and automatically saved as the conversation progresses.

Installation

npm install @simulacra-ai/core @simulacra-ai/session

Quick Start

import { Conversation } from "@simulacra-ai/core";
import { FileSessionStore, SessionManager } from "@simulacra-ai/session";

// assuming provider is already configured

// create a conversation
using conversation = new Conversation(provider);

// create a session manager backed by the filesystem
const store = new FileSessionStore("./sessions");
using session = new SessionManager(store, conversation);

// start a new session
session.start_new("my first session");

// conversation happens, messages are saved automatically
await conversation.prompt("Hello!");

With auto_save (default true), messages are persisted after each model response without any manual save calls.

SessionManager

The SessionManager coordinates a conversation with a storage backend. It handles the full lifecycle of sessions, from creation through saving to disposal.

new SessionManager(store, conversation, options?)

The constructor accepts the following options.

Option|Type|Default|Description -|-|-|- auto_save|boolean|true|Save after every message_complete event auto_slug|boolean|true|Derive a label from the first user message

Methods

The session manager exposes the following methods.

Method|Description -|- start_new(label?)|Begin a new session, returns the session ID load(id?)|Load a session by ID, or the most recent if omitted save(metadata?)|Persist current messages and metadata fork(parent_id, options?)|Create a child session branching from a parent, returns the new session ID list()|List all sessions from the store delete(id)|Remove a session rename(id, label)|Change a session's label

Events

The session manager emits events as sessions are loaded and saved.

Event|Payload|When -|-|- load|{ id, messages }|Session loaded from store save|{ id, messages }|Session written to store lifecycle_error|{ error, operation, context? }|Infrastructure or lifecycle failure dispose|(none)|Manager disposed

Auto-Slug

When auto_slug is enabled, the session manager derives a label from the first ~50 characters of the first user message, trimmed to a word boundary. This runs once on the first save. Explicitly setting a label via start_new(label) or rename() takes precedence.

Child Sessions

When a child conversation is spawned (via orchestration, checkpoints, or spawn_child), the session manager automatically creates a child session backed by a detached fork. Child sessions auto-save independently and are disposed when the child conversation ends. This means orchestration subagents, checkpoint summaries, and other child conversations all get their own persistent session history without any manual setup.

Checkpoint children have auto_slug disabled since their sessions are internal.

Session Storage

A SessionStore is the storage backend that a SessionManager reads from and writes to. The store handles listing, loading, saving, and deleting sessions. Three stores are included out of the box.

FileSessionStore persists sessions as JSON files on disk. Each session is a single {id}.json file. Child session relationships are indexed using hard links under {parent-id}-forks/ directories.

const store = new FileSessionStore("./data/sessions");

InMemorySessionStore is a non-persistent store for testing and development. Sessions live in a Map and are lost on process exit.

const store = new InMemorySessionStore();

DrizzleSessionStore persists sessions in a relational database using Drizzle ORM. It works with any database that Drizzle supports (PostgreSQL, MySQL, SQLite). The store does not import drizzle-orm itself. Instead, it accepts an adapter object with list, load, upsert, and delete functions that wrap Drizzle queries against the application's table.

import { DrizzleSessionStore } from "@simulacra-ai/session";

const store = new DrizzleSessionStore({
  list: () =>
    db.select().from(sessionsTable).orderBy(desc(sessionsTable.updated_at)),
  load: async (id) => {
    const [row] = await db
      .select({ metadata: sessionsTable.metadata, messages: sessionsTable.messages })
      .from(sessionsTable)
      .where(eq(sessionsTable.id, id));
    return row;
  },
  upsert: (row) =>
    db.insert(sessionsTable).values(row).onConflictDoUpdate({
      target: sessionsTable.id,
      set: { metadata: row.metadata, messages: row.messages, updated_at: row.updated_at },
    }),
  delete: async (id) => {
    const result = await db.delete(sessionsTable).where(eq(sessionsTable.id, id));
    return result.rowCount > 0;
  },
});

The DrizzleSessionRow and DrizzleSessionAdapter types are exported for reference when defining a table schema and adapter. See the JSDoc on DrizzleSessionRow for example PostgreSQL and SQLite table definitions.

Custom storage backends (databases, cloud storage, key-value stores) can be built by implementing the SessionStore interface. The extensibility guide covers the interface, implementation notes, and includes a full example.

License

MIT