@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.
Installation
bash
npm install @context-chef/core zodQuick 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:
| Module | Guide page |
|---|---|
Janitor — history compression, compact(), ensureValidHistory | History Compression |
planCompaction / compactHistory / summarizeHistory | Durable Compaction |
contextManagement: { strategy: 'server' } | Server-Side Context Management |
Offloader / VFS — offload, cleanupAsync, reconcileAsync | Offloading & VFS |
Pruner — flat mode, blocklist, namespaces, deferLoading | Tool Management |
Memory — stores, tools, memoryPlacement | Memory |
Skill — SKILL.md loading, renderSkill, delivery models | Skills |
withGuardrails — XML contract + prefill | Guardrail |
snapshot() / restore() | Snapshot & Restore |
Events, compile({ signal }), concurrency, onBeforeCompile | Events & Hooks |
Input/target adapters, adapterRegistry, openai-responses | Adapters |
Utilities
estimate(text)/estimateObject(obj)— rough token estimation (replaces the removedTokenUtils).objectToXml(obj)— the XML serializer behind dynamic state (replaces the removedXmlGenerator).getAdapter(name)/adapterRegistry— adapter lookup and registration (replaces the removedAdapterFactory).ensureValidHistory(messages)— sanitize a message array to satisfy LLM API invariants.getRecallToolDefinition()/chef.resolveRecall(uri)— the recall tool for archived/offloaded content.