Skip to content

@context-chef/core

The core context compiler — history compression, tool pruning, memory, VFS offloading, snapshot/restore, and multi-provider adapters, with no framework dependency. Use it when you drive an LLM SDK (OpenAI / Anthropic / Gemini) directly and want full control over the compilation pipeline.

npm versionnpm downloads

Installation

bash
npm install @context-chef/core zod

Quick Start

typescript
import { ContextChef } from "@context-chef/core";
import { z } from "zod";

const TaskSchema = z.object({
  activeFile: z.string(),
  todo: z.array(z.string()),
});

const chef = new ContextChef({
  janitor: {
    contextWindow: 200000,
    compressionModel: async (msgs) => callGpt4oMini(msgs),
  },
});

const payload = await chef
  .setSystemPrompt([
    {
      role: "system",
      content: "You are an expert coder.",
      _cache_breakpoint: true,
    },
  ])
  .setHistory(conversationHistory)
  .setDynamicState(TaskSchema, {
    activeFile: "auth.ts",
    todo: ["Fix login bug"],
  })
  .withGuardrails({
    enforceXML: { outputTag: "response" },
    prefill: "<thinking>\n1.",
  })
  .compile({ target: "anthropic" });

const response = await anthropic.messages.create(payload);

What's inside

The full API is documented across the guide, one page per concern:

ModuleGuide page
Janitor — history compression, compact(), ensureValidHistoryHistory Compression
planCompaction / compactHistory / summarizeHistoryDurable Compaction
contextManagement: { strategy: 'server' }Server-Side Context Management
Offloader / VFS — offload, cleanupAsync, reconcileAsyncOffloading & VFS
Pruner — flat mode, blocklist, namespaces, deferLoadingTool Management
Memory — stores, tools, memoryPlacementMemory
Skill — SKILL.md loading, renderSkill, delivery modelsSkills
withGuardrails — XML contract + prefillGuardrail
snapshot() / restore()Snapshot & Restore
Events, compile({ signal }), concurrency, onBeforeCompileEvents & Hooks
Input/target adapters, adapterRegistry, openai-responsesAdapters

Utilities

  • estimate(text) / estimateObject(obj) — rough token estimation (replaces the removed TokenUtils).
  • objectToXml(obj) — the XML serializer behind dynamic state (replaces the removed XmlGenerator).
  • getAdapter(name) / adapterRegistry — adapter lookup and registration (replaces the removed AdapterFactory).
  • ensureValidHistory(messages) — sanitize a message array to satisfy LLM API invariants.
  • getRecallToolDefinition() / chef.resolveRecall(uri) — the recall tool for archived/offloaded content.