# Emberfold: agent guide

> Portable, inspectable context continuity: prepare the conversation, decisions, corrections, protected passages, and source references an agent carries into its next model request.

[Agent index](https://hivemagnus.com/llms.txt) · [Repository](https://github.com/ChefTaco/emberfold) · [Current instructions](https://github.com/ChefTaco/emberfold#cli-and-http)

## Choose an interface

- TypeScript library: `@hivemagnus/emberfold` for storage-independent integration in your application.
- CLI: `@hivemagnus/emberfold-cli` for JSON input/output.
- Optional authenticated HTTP wrapper: `@hivemagnus/emberfold-server`.
- Hermes context-engine plugin: runs locally and reuses Hermes's configured compression model.

Ardent already imports the library at its own pin: Ardent 3.8.0 and later pin `@hivemagnus/emberfold` 0.7.0 (Hive 3.22.0 stages Ardent 3.9.0; Ardent 3.7.0 pinned 0.6.0 and Ardent 3.6.0 pinned 0.4.0), the Hermes plugin 0.2.0 pins 0.4.0, and the examples below use 0.7.0. Installing an additional service is unnecessary for that integration; see the [Ardent guide](https://hivemagnus.com/guides/ardent.md). In a [Hive](https://hivemagnus.com/guides/hive.md) installation, the `full` profile also runs the optional Emberfold HTTP service; Hive 3.22.0 pins it at 0.7.1 (since 3.21.3).

## Prerequisites

Node.js 24.22.3+ in the 24 series or 26.13.1+ in the 26 series, and npm. The synthetic dry run below requires no model credentials or running services.

## Try a synthetic CLI dry run

In a new working directory, create this synthetic input:

```bash
cat > conversation.json <<'EOF'
{
  "schema_version": 1,
  "namespace": "demo:conversation",
  "instructions": "Help with a sample task.",
  "history": [],
  "exchanges": [],
  "current": [{ "id": "message-1", "role": "user", "content": "Continue the task." }],
  "budget": { "context_tokens": 16000, "output_reserve_tokens": 4000 }
}
EOF
npx --package @hivemagnus/emberfold-cli@0.7.0 emberfold prepare --input conversation.json --dry-run
```

Expected result: JSON on stdout with `fits: true`, `compacted: false`, and zero protected spans verified for this input. Dry runs make no model calls and do not write output files. Diagnostics go to stderr. Exit codes are 0 success, 2 invalid input, 3 budget exhaustion, and 4 provider/tokenizer unavailable or deadline exceeded.

For real compression, supply a summarizer/provider configuration explicitly. There is no implicit cloud fallback. The library caller retains authoritative source history and controls publication; historical summaries remain unverified data.

## Use the TypeScript library

In an existing TypeScript project:

```bash
npm install @hivemagnus/emberfold@0.7.0
```

The repository's minimal API example:

```typescript
import { prepareContext } from '@hivemagnus/emberfold';

const result = await prepareContext({
  schema_version: 1,
  namespace: 'example:conversation',
  instructions: 'Current application instructions',
  history: [], exchanges: [],
  current: [{ id: 'message-1', role: 'user', content: 'Continue the task.' }],
  budget: { context_tokens: 16000, output_reserve_tokens: 4000 }
});
```

Supply a summarizer adapter when older exchanges need compression. Optional adapters are exported from `@hivemagnus/emberfold/adapters`. Consult the contracts and operations guide before adding provider configuration or the HTTP wrapper. HTTP offers `POST /v1/prepare`, `/v1/checkpoints/validate`, `/v1/checkpoints/rebuild` and `/v1/recall`, authenticated Prometheus `GET /metrics`, and metadata-only `/health/live`, `/health/ready`, `/healthz` and `/readyz` on your own configured server.

From 0.5.0, an `http` provider with `api_key_env` must use an `https:` URL unless its host is loopback; otherwise the service and CLI fail at startup with `Invalid provider URL: a provider credential requires HTTPS unless the host is loopback`. The Codex child process receives only an allowlisted environment (`HOME`, `PATH`, user, locale, time zone, temporary and XDG directories, CA and proxy settings, `CODEX_*`, and `OPENAI_API_KEY`/`OPENAI_BASE_URL` only with `auth_mode: "apiKey"`); move anything else a Codex setup needs into Codex's own configuration or a `CODEX_*` name. The HTTP service writes HiveCommon JSON request logs with the matched route instead of the raw URL, and accepts Oathweave client-credentials tokens alongside its static bearer only when an `oathweave` configuration block is set. 0.5.0 has no migration, because Emberfold is stateless; a downgrade to 0.4.0 needs any `oathweave` block removed first. 0.5.1 changes no behaviour: the service's static bearer check uses HiveCommon 0.10.0's digest comparison, with the same rule (the whole `Authorization` header must be exactly `Bearer <token>`), and a downgrade to 0.5.0 is safe. In a Hive installation the suite configures no credentialed HTTP provider.

## Context dispositions and the attention manifest

Ardent fits each model request to its budget with the library's `@hivemagnus/emberfold/compat` entry, a deterministic fitter that is separate from the summarizing `prepare` engine behind the CLI, the HTTP service and the Hermes plugin. Two reports say what that fitter did with each source message:

- **Dispositions, from 0.6.0.** `describeModelContext(original, fitted)` describes a completed fit as an `emberfold-context/1` record: for every source message its index, role, SHA-256 and tool call ID, and whether it was `retained`, `checkpointed` (the system message rewritten with a checkpoint), `shortened` (a tool result cut to an excerpt) or `omitted`.
- **Attention manifest, from 0.7.0.** `fitWithManifest(...)` takes the same arguments as `fitModelMessages` and returns the same fit plus `manifest`, an `emberfold-attention-manifest/1` record written while the fitter decides, not reconstructed afterwards. Per source message it gives the disposition, reason codes (for example `protected-instruction`, `objective`, `recency-window`, `budget-pressure`, `oldest-first`, `checkpoint-summarized`, `tool-result-truncated`), the removal rank, the character budget at decision time and replay references: index, message SHA-256, tool call IDs, the removed transaction's digest as listed in the checkpoint, and the kept excerpt's offsets and digest for a shortened tool result. It lists every dropped or shortened candidate, flags those carrying tool results or user text as possibly neglected, and records each budget attempt. `AttentionManifestSchema` (root and `compat` entries) and [`contracts/AttentionManifest.schema.json`](https://github.com/ChefTaco/emberfold/blob/v0.7.1/contracts/AttentionManifest.schema.json) describe it.

Both records state their limit: they describe request construction and context selection, never model-internal attention. 0.7.0 does not change fitting: `fitModelMessages`, `compactModelMessages` and `describeModelContext` return exactly what they did in 0.6.0, and neither release changes the CLI or the HTTP service beyond the version they report; the published Hermes plugin is still `0.2.0`. A consumer switches its fit call to `fitWithManifest` to record reasons. Ardent 3.8.0 and later do, and pass the manifest as `attention` in the `prepared` model-boundary event when a plugin observes the request, which is how [Lucent](https://hivemagnus.com/guides/lucent.md) gets it; requests without an observer are fitted exactly as before. See the README's [attention manifest](https://github.com/ChefTaco/emberfold/blob/v0.7.1/README.md#attention-manifest) and the [changelog](https://github.com/ChefTaco/emberfold/blob/v0.7.1/CHANGELOG.md).

## Optional Hermes plugin

The repository README pins Hermes plugin `0.2.0` ([release `hermes-v0.2.0`](https://github.com/ChefTaco/emberfold/releases/tag/hermes-v0.2.0)) to a reviewed source revision; the plugin is versioned separately and pins core `0.4.0`, so later tool results are no longer over-truncated and provider failures carry stable codes. Plugins `0.1.1` and `0.1.0` are superseded. The next plugin release, `0.2.1`, pins core `0.5.1` and is not published yet; install `0.2.0` until it is. With Hermes already installed, follow its full onboarding guide:

```bash
hermes plugins install ChefTaco/emberfold/integrations/emberfold-hermes --ref f77445764f57482bc5a7f14bbd5e1d5aa4c95401 --enable
hermes emberfold setup
hermes emberfold status --json
```

Setup has separate dependency and configuration/model-check consent steps; if the dependencies were skipped, `hermes emberfold setup --install-deps` installs the pinned lockfile. Installation alone is not activation; restart the existing gateway and verify a real session as documented. No Emberfold account, remote service, or Hermes fork is required.

## Full instructions

- [API contracts](https://github.com/ChefTaco/emberfold/blob/main/contracts/openapi.json)
- [Operations and provider setup](https://github.com/ChefTaco/emberfold/blob/main/docs/OPERATIONS.md)
- [Hermes onboarding and rollback](https://github.com/ChefTaco/emberfold/blob/main/integrations/emberfold-hermes/README.md)
- [Preservation and security](https://github.com/ChefTaco/emberfold/blob/main/SECURITY.md)
- [Repository instructions](https://github.com/ChefTaco/emberfold/blob/main/AGENTS.md)

## Source review

Reviewed 2026-11-05 against tag `v0.2.1`, commit `f97b7eec1083cbbab79361f6360b8b8412f50bc9`: [README](https://github.com/ChefTaco/emberfold/blob/f97b7eec1083cbbab79361f6360b8b8412f50bc9/README.md), [CLI package manifest](https://github.com/ChefTaco/emberfold/blob/f97b7eec1083cbbab79361f6360b8b8412f50bc9/packages/cli/package.json), and [Node requirements](https://github.com/ChefTaco/emberfold/blob/f97b7eec1083cbbab79361f6360b8b8412f50bc9/package.json). Core, CLI and server `0.2.1` are on npm as `latest`, and core and CLI are pinned intentionally. The CLI invocation uses the published package's `emberfold` executable with the documented `prepare --input ... --dry-run` arguments; run with `0.2.1`, the synthetic example above exits 0 with the expected result and output identical to `0.1.0`. Follow current docs for later versions. License: Apache-2.0.

Release update, 2026-12-02: [Hive 3.21.3](https://github.com/ChefTaco/hive/releases/tag/v3.21.3) pins Emberfold 0.7.1. The product image includes OpenSSL 4.0.4. This upgrade requires no data migration from 0.7.0. [Tagged changelog](https://github.com/ChefTaco/Emberfold/blob/v0.7.1/CHANGELOG.md)

Earlier release records for this guide are kept in the site repository's [emberfold release records](https://github.com/ChefTaco/HiveMagnus/blob/main/docs/release-records/emberfold.md); what each Emberfold release changed is in its [changelog](https://github.com/ChefTaco/emberfold/blob/main/CHANGELOG.md).
