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

log-narrator

v1.0.0

Published

A generic, stateful extraction and detection package that converts heterogeneous operational events into normalized entities, signals, and narratives for explainable higher-order detection.

Readme

log-narrator

A generic, stateful extraction and detection package that converts heterogeneous operational events into normalized entities, signals, and narratives for explainable higher-order detection.

Install

npm install log-narrator

For Redis-backed production mode (optional):

npm install ioredis

Core Concepts

| Concept | Description | |---|---| | CanonicalEvent | A normalized event mapped from a raw source payload | | Entity | A normalized object (user, file, session, etc.) with external IDs | | Signal | An atomic derived observation (burst access, cross-location, etc.) | | Narrative | A stateful, correlated interpretation built from multiple signals over time | | Finding | A finalized conclusion emitted from a satisfied narrative |

Pipeline Stages

raw event → canonical event → entity extraction → signal detection
         → stateful correlation → narrative rule evaluation → finding

Quick Start

import {
  Pipeline, Registry, MemoryStateStore,
  EventMapper, EntityExtractor, SignalDetector, NarrativeRule,
} from "log-narrator";

// 1. Define an event mapper
const mapper: EventMapper = {
  sourceType: "my-app",
  map(raw) {
    const r = raw as any;
    return {
      id: r.id,
      type: "resource.accessed",
      timestamp: r.timestamp,
      actor: { id: r.userId, type: "user" },
      target: { id: r.resourceId, type: "file" },
      source: "my-app",
      raw: r,
    };
  },
};

// 2. Define entity extractors, signal detectors, narrative rules...

// 3. Build registry
const registry = new Registry()
  .registerMapper(mapper)
  .registerExtractor(myExtractor)
  .registerDetector(myDetector)
  .registerNarrativeRule(myRule);

// 4. Create pipeline (in-memory for dev)
const state = new MemoryStateStore();
const pipeline = new Pipeline(registry, state);

// 5. Process events
const result = await pipeline.process(rawEvent);
console.log(result.signals);     // atomic signals detected
console.log(result.narratives);  // correlated narratives
console.log(result.findings);    // finalized conclusions

// 6. Listen to events
pipeline.on("narrative:satisfied", (n) => console.log("Narrative!", n));
pipeline.on("finding:emitted", (f) => console.log("Finding!", f));

Redis Mode (Production)

import Redis from "ioredis";
import { Pipeline, Registry, RedisStateStore } from "log-narrator";

const redis = new Redis();
const state = new RedisStateStore(redis, "myapp:");
const pipeline = new Pipeline(registry, state);

// Call sweep periodically to expire stale narratives
setInterval(() => pipeline.sweep(), 10_000);

Narrative Rules

Rules declare which signal combinations, over what time window, constitute a narrative:

const rule: NarrativeRule = {
  narrativeType: "likely_ai_driven_access",
  windowSeconds: 30,
  condition: {
    requiredSignals: ["burst_access", "cross_location_access", "missing_navigation"],
    // anyOfSignals, absentSignals, minSignalCount, custom() also supported
  },
  confidence: 0.85,
  buildSummary(signals, entities) {
    return `Detected ${signals.length} signals indicating AI-driven access.`;
  },
  toFinding(narrative) {
    return { /* ... */ };
  },
};

Condition operators

| Field | Meaning | |---|---| | requiredSignals | All must be present (AND) | | anyOfSignals | At least one present (OR) | | absentSignals | None may be present (NOT) | | minSignalCount | Minimum signal count in window | | custom | Async predicate for advanced logic |

Narrative Lifecycle

Narratives progress through: openaccumulatingsatisfied / expired / closed / merged

Call pipeline.sweep() periodically to expire stale narratives.

Architecture

┌─────────────┐
│  Raw Events  │
└──────┬──────┘
       │  EventMapper (pluggable, per-source)
       ▼
┌─────────────────┐
│ Canonical Events │
└──────┬──────────┘
       │  EntityExtractor (pluggable)
       ▼
┌──────────┐
│ Entities │
└──────┬───┘
       │  SignalDetector (pluggable, stateful)
       ▼
┌─────────┐
│ Signals │
└──────┬──┘
       │  StateStore (Memory / Redis)
       │  NarrativeRule (pluggable)
       ▼
┌────────────┐     ┌──────────┐
│ Narratives │────▶│ Findings │
└────────────┘     └──────────┘

License

MIT