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

context-kernel

v0.6.1

Published

Platform-agnostic context kernel for routing, budget management, policy guards, and audit trails.

Downloads

108

Readme

context-kernel sits between inbound agent context and the model call. It helps you classify requests, choose a route, trigger compaction, apply policy guards, extract memory candidates, and emit audit events before generation starts.

What it is good for

Use it when you are building:

  • agent backends that need routing, guardrails, and memory hooks
  • OpenClaw or OpenClaw-like runtimes that need a reusable pre-generation control layer
  • multi-model systems where some requests should stay local and others should escalate
  • compliance-sensitive assistants that need structured audit events
  • multi-agent systems that benefit from shared-memory, snapshots, or utility scoring modules

What it is not

context-kernel is not a full agent framework, vector database, orchestration platform, or autonomous runtime. It is the decision layer in front of those systems.

Core capabilities

  • Input classification - text vs multimodal, plus task types like chat, code, memory, admin, urgent
  • Route selection - map classifications to local or premium model lanes
  • Budget signaling - trigger compress: true when token thresholds are exceeded
  • Policy enforcement - quiet hours, action allowlists, secret detection, and PII guard
  • Memory hooks - extract memory candidates with writeback hints
  • Versioned memory snapshots - compact and retain context history over time
  • Audit events - emit lifecycle events like started, classified, routed, and completed
  • Adapters - OpenClaw, HTTP, and file-backed storage surfaces
  • Utilities - deduplication, priority scoring, eviction, snapshots, shared-memory pools, and bulk helpers

Install

npm install context-kernel

Quick start

import { ContextKernel } from "context-kernel";

const kernel = new ContextKernel({
  router: {
    tokenCompressionThreshold: 10_000,
    allowPremiumEscalation: true,
    routeMap: {
      textDefault: "local_text",
      multimodal: "local_vision",
      urgent: "premium",
      codeHighContext: "premium",
    },
  },
  policy: {
    postOnlyMode: false,
    rules: [
      { id: "safe-actions", kind: "action_allowlist", actions: ["send", "post", "tool_call"] },
    ],
  },
});

const decision = await kernel.decide({
  sessionId: "sess-001",
  timestamp: new Date().toISOString(),
  messages: [{ role: "user", content: "Help me refactor this repo" }],
  estimatedTokens: 12_000,
});

console.log(decision.taskType);  // "code"
console.log(decision.route);     // "premium"
console.log(decision.compress);  // true

Mental model

The kernel does not execute the model call for you. It returns a grounded decision object your runtime can act on.

{
  inputKind: "text",
  taskType: "code",
  route: "premium",
  compress: true,
  policyVerdicts: { ... },
  memoryCandidates: [ ... ],
  actions: [ ... ]
}

Main API surface

new ContextKernel(config, hooks?)

Creates the decision engine.

await kernel.decide(input)

Evaluates one inbound request and returns a KernelDecision.

Adapters

import { fromOpenClawEnvelope } from "context-kernel/adapters/openclaw";
import { fromHttpEnvelope } from "context-kernel/adapters/http";

Schemas

import { kernelInputSchema, kernelConfigSchema } from "context-kernel/schemas";

Common use cases

1. Route expensive requests selectively

Keep normal chat local, but escalate urgent or high-context code tasks.

2. Apply policy before tool execution

Use quiet hours, secret regex checks, and action allowlists before downstream workers act.

3. Extract memory candidates without hardcoding heuristics everywhere

Let the kernel suggest what belongs in user memory or durable workspace memory.

4. Add observability to agent decisions

Emit structured events so you can inspect why a route or block happened.

5. Reuse context utilities outside the kernel

Use exported modules like deduplication, priority scoring, snapshots, and shared-memory pools independently.

Included modules

Core runtime pieces

  • ContextKernel
  • MemoryManager
  • compaction helpers
  • identity drift helpers
  • Zod schemas

Utility modules

  • deduplicateEntries() / findDuplicate()
  • scoreEntries() / topK()
  • evict()
  • snapshot store helpers
  • shared-memory registry helpers
  • audit trail helpers
  • bulk context-store helpers
  • PII scanning helpers

CLI

npx context-kernel --config ./kernel.config.json --input ./input.json
npx context-kernel --snapshots ./kernel-data
npx context-kernel --delete-snapshot 0.2.0 --storage ./kernel-data

Example configs

  • examples/kernel.config.json
  • examples/preset.openclaw.json
  • examples/preset.generic.json
  • examples/input.json

Current limits

Today the package is strongest as a library for agent builders, not a turnkey platform. A few things are intentionally left to the host runtime:

  • actual model execution
  • vector retrieval infrastructure
  • long-term persistent backends beyond provided adapters
  • workflow orchestration and retries
  • product-specific policy semantics

Who should use this

Use context-kernel if you want a reusable, testable place for:

  • model routing rules
  • token-budget decisions
  • preflight safety policy
  • memory extraction contracts
  • traceable agent decisions

If you just need a chatbot wrapper, this is probably too low-level.

Links

  • Architecture: ARCHITECTURE.md
  • Changelog: CHANGELOG.md
  • Security: SECURITY.md
  • Release notes / roadmap: ROADMAP_v0.7.0.md

Built with teeth. 🌑