The engine

Core

@inixiative/foundry-core is the engine. Primitives, zero opinions, no external service deps. Every agent, every orchestration pattern in Foundry is assembled from these pieces. Open-source, MIT, usable on its own.

The hero primitive

Context layers are independent token caches.

A layer is not a slice of one shared context window. It's a small token-capped cache with its own source, its own warm-up, and its own eviction. The harness assembles the layers a message needs, diffs against what's already hydrated, and injects only the delta. Same-hash layers are skipped.

docs

Project conventions, architecture notes, ADRs. Warmed from Markdown.

convention

Learned patterns the Warden has earned. Accumulates over time.

security

Threat model + hard stops. The Warden's guard mode consults it.

architecture

Module boundaries and dependency rules. Keeps layers from leaking.

memory

Long-lived operator notes. Survives session resets.

thread-state

Per-thread reconciled signal. Sole writer: the Librarian.

Layer definitions live in .foundry/settings.json. Each has maxTokens, one or more sources, and an owner agent. Add a layer; the Cartographer learns when to route it.

The rest of the engine

Primitives.

Everything in core is a small, composable piece. Assemble them into your own harness, or use the opinionated one in @inixiative/foundry.

ContextStack

Ordered set of layers. Hashes for delta-aware hydration — identical slices skip re-injection.

Thread

A conversation unit wrapped with layers, middleware, and a trace. Many threads per harness.

Harness

The session substrate. Wraps Claude Code with flow stages: pre-message, dispatch, post-action.

MiddlewareChain

Tiered dispatch pipeline. Retry, permissions, token-budget — all middleware, all composable.

SignalBus

Cross-agent messaging. Wardens emit, Librarian reconciles, Herald watches across threads.

Trace

Spans for every stage. Makes the flow inspectable in the viewer, not just readable in logs.

TokenTracker

Per-agent budgets with hard and soft caps. Enforced at the middleware layer, not after the fact.

CapabilityGate

Provider-agnostic permission flags. Unattended, supervised, restricted, browser — one policy set.

HookRegistry

Lifecycle hooks for cross-cutting concerns. Plan mode, pre-tool gates, post-action observers.

InterventionLog

Every correction the operator makes, attributed and timestamped. Feedstock for the Oracle loop.

Use it on its own

import { Harness, ContextStack, ContextLayer, Thread } from "@inixiative/foundry-core";

const stack = new ContextStack([
  new ContextLayer({ id: "docs", maxTokens: 2000, sources: [/* ... */] }),
]);

const harness = new Harness({ stack, provider: /* your LLMProvider */ });
const thread = harness.thread({ id: "t1" });
await thread.send("what's the coverage rule?");

Core has no external service deps. Bring your own provider, your own adapters, your own agents. If you want opinions, upgrade to @inixiative/foundry.

License

@inixiative/foundry-core is MIT. Use it however you want.