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

ds4-context-core

v0.5.3

Published

Runtime-neutral context planning, retrieval, compaction, memory, and privacy for agent runtimes.

Readme

ds4-context-core

Runtime-neutral core of DS4 Context Engine.

The package contains deterministic context policy and rebuildable local projections without importing Pi or any other agent runtime. Runtime integrations translate their native sessions and models at the adapter boundary.

Included

  • versioned runtime adapter contract and framework-neutral conformance runner;
  • exact-byte local KV eligibility, volatile runtime-port orchestration and aggregate-only diagnostics;
  • canonical messages and token estimation;
  • model profiles, calibration and context budgets;
  • deterministic planning and atomic tool groups;
  • Context Manifest generation;
  • validated hierarchical compaction records and tool-exchange-safe source segmentation;
  • exact, FTS and deterministic hybrid rank fusion;
  • runtime-neutral embedding port, derived vector storage and quality comparison;
  • runtime-neutral structural symbol parsing with deterministic regex fallback;
  • project knowledge and artifact storage;
  • append-only memory and pin materialization;
  • privacy classification and provider policy;
  • optional continuation state decisions;
  • deterministic metadata-only context-quality replay and comparison;
  • bounded learned-ranking features, local training, checksummed artifacts and promotion evaluation;
  • rebuildable SQLite repositories, bounded manifest projection, storage diagnostics, cooperative client leases, and offline copy–validate–swap maintenance.

Install

npm install ds4-context-core

Core and adapter releases use matching versions. The core package is published first because both adapters depend on that exact version. The 0.2 line freezes configuration as ds4-context-config-v1, SQLite projections at schema 15, and the runtime boundary as runtime-adapter-v1; incompatible changes require a later versioned contract.

Usage

import {
  calculateContextBudget,
  CONFIG_SCHEMA_VERSION,
  createDefaultConfig,
  createModelProfile,
} from "ds4-context-core";

if (CONFIG_SCHEMA_VERSION !== "ds4-context-config-v1") throw new Error("incompatible config");
const config = createDefaultConfig();
const profile = createModelProfile({
  provider: "example",
  id: "model",
  contextWindow: 128_000,
  maxTokens: 16_000,
});
const budget = calculateContextBudget(profile, config.context);

Fine-grained ESM subpath exports are available, for example:

import { planManagedContext } from "ds4-context-core/planner/context-planner";
import { compareQualityStrategies } from "ds4-context-core/quality/context-quality";
import { DeterministicRegexSymbolParser } from "ds4-context-core/project/symbol-parser";
import type { EmbeddingPort } from "ds4-context-core/retrieval/embedding";
import { SemanticEmbeddingIndex } from "ds4-context-core/retrieval/semantic-index";
import { rankCandidates } from "ds4-context-core/ranking/learned-ranker";
import { runRuntimeAdapterConformance } from "ds4-context-core/adapter/conformance";
import { LocalKvReuseController } from "ds4-context-core/adapter/local-kv";
import { negotiateRuntimeCapabilities } from "ds4-context-core/adapter/runtime-adapter";
import { inspectStorage } from "ds4-context-core/persistence/storage-maintenance";

Storage maintenance APIs are runtime-neutral and never infer a database path. Adapters must expose them only through an explicit local administrative boundary; they are not model-callable. The Pi package provides the interactive ds4-context-storage CLI.

Adapter boundary

An adapter is responsible for:

  1. projecting runtime-native messages into canonical DS4 messages;
  2. identifying the active session, branch, provider and model;
  3. supplying canonical history and project trust state;
  4. applying the planned context through runtime hooks;
  5. invoking model completion while enforcing privacy immediately before transport;
  6. persisting canonical mutations in the runtime's own history;
  7. negotiating optional runtime capabilities independently;
  8. retaining any local KV handles inside a volatile runtime port and replaying the full sanitized prompt after non-hits;
  9. shutting down idempotently and falling back to the native runtime path on integration failure.

The Pi implementation lives in the root ds4-context-engine package under src/pi-adapter and src/extension. The separately packaged ds4-context-reference-adapter demonstrates the same contract with canonical JSONL and an injected completion callback. See the repository's Runtime Adapter Kit documentation for conformance and packaging rules.

Portability guarantee

packages/core/src may import Node.js standard-library modules, but it must not import:

  • @earendil-works/pi-ai;
  • @earendil-works/pi-coding-agent;
  • src/pi-adapter or src/extension.

A boundary test enforces this rule.

License

MIT