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

@langecs/persist-fs

v0.2.0

Published

Filesystem persistence adapter for LangECS worlds — snapshots, history, time travel

Readme

@langecs/persist-fs

Filesystem persistence adapter for LangECS worlds. Every step boundary lands on disk as a JSON snapshot, so a world survives process death: kill it mid-conversation, start a new process, load, resume. Node-only (uses node:fs); for in-memory history and time travel without disk, core's MemoryAdapter has the same surface.

Install

npm i @langecs/persist-fs @langecs/core

ESM only, Node >= 20.

fsAdapter(options): FsAdapter

import { createWorld } from '@langecs/core';
import { fsAdapter } from '@langecs/persist-fs';

const world = createWorld({ id: 'records-world', persistence: fsAdapter({ dir: './.world' }) });

FsAdapter is a PersistenceAdapter with history/loadStep guaranteed:

interface FsAdapterOptions { dir: string }   // root directory; created on first save

interface FsAdapter extends PersistenceAdapter {
  save(snapshot: Snapshot): Promise<void>;
  load(worldId: string): Promise<Snapshot | null>;                       // newest snapshot
  history(worldId: string): Promise<{ step: number; savedAt: number }[]>;
  loadStep(worldId: string, step: number): Promise<Snapshot | null>;
}

The engine awaits save after every step barrier and once at run end, so the disk always reflects the latest consistent boundary — including pending work that has not fired yet (pendingPairs).

File layout

<dir>/
  <worldId>/
    step-000001.json    # one file per step boundary
    step-000002.json
    ...
    latest.json         # always mirrors the newest snapshot

All writes are atomic (unique tmp file in the same directory, then rename), so a reader never observes a partially-written snapshot. If a crash lands between the two writes and latest.json is missing, load() falls back to the newest step file. Missing directories are tolerated everywhere (loadnull, history[]).

Kill and resume

Condensed from the human-in-the-loop example, which demonstrates this across two real processes — the run parks as 'pending' on a tool-approval interrupt, the process exits, and a fresh process finishes the conversation:

/** Same world recipe in both processes; only the snapshot differs. */
function buildWorld(): World {
  const world = createWorld({ id: WORLD_ID, persistence: fsAdapter({ dir: DATA_DIR }) });
  world.register(MODEL_RESOURCE, fromAiSdk(openai('gpt-4o-mini')));   // resources are
  registerTools(world, recordTools());                                // never snapshotted
  return world;
}

// ── process 1 ───────────────────────────────────────────────────────────────
const world = buildWorld();
const agent = world.spawn(recordsAgent);
const result = await sendMessage(world, agent, 'Look up record 42, then delete it.');
result.status;     // 'pending' — delete_record needs approval; every boundary is on disk
process.exit(0);   // the kill. Nothing survives but the snapshot files.

// ── process 2 (brand new) ───────────────────────────────────────────────────
const adapter = fsAdapter({ dir: DATA_DIR });
const snapshot = await adapter.load(WORLD_ID);
const world2 = buildWorld();
world2.use(recordsAgent);   // register the agent's systems BEFORE load (core R19)
world2.load(snapshot!);     // entities, step counter, pending dirt — the lot (R36)

const [first] = world2.pending();   // the persisted AwaitingHuman interrupt
await world2.resume(first!.entity, true);   // approve; the tool finally executes

The order matters in process 2: world.use(agentDef) registers the agent's scoped systems without spawning, which world.load() needs to resolve the snapshot's components and pending pairs. Resources (models, tools) are behavior, not data — they are never in the snapshot and must be re-registered, which buildWorld() does.

History and time travel

One file per step means rewind-and-fork works straight from the directory listing (from this package's tests):

const snap1 = await adapter.loadStep('tt', 1);   // the world as it was after step 1

const fork = createWorld({ id: 'tt-fork' });     // a FRESH world, new worldId
fork.use(echo);                                  // same system registrations
fork.load(snap1!);
fork.step;                                       // 1
await fork.send(e.id, Input(['z']));             // diverge from there

// The original timeline — in memory and on disk — is untouched:
(await adapter.load('tt'))?.step;                // still 2

Give the fork its own persistence: adapter and it checkpoints its own history under its own worldId, side by side with the original. The time-travel example runs this end to end (with core's MemoryAdapter; the adapters are interchangeable).

See also