Contextia proves one narrow thing well: given a workspace, a declared budget, and a small set of explicit sources, the library builds a deterministic context bundle and can write one safe journal entry when asked.
- Workspace conventions such as
AGENTS.mdandMEMORY.mdare discovered deterministically. - Manual sources are included in a stable order.
drop-tailcompaction omits trailing sources when the declared budget would be exceeded.- Journal persistence only accepts allowlisted, developer-readable fields.
- Start with
createContextBundle(workspacePath). - Add one manual source.
- Set
budgetand optionalcompactionPolicy: { strategy: "drop-tail" }. - Optionally set explicit ordering controls (
kindWeights,groupRanks,sourceOverrides). - Build and inspect
included,omitted, andorderingRationale. - Optionally call
writeJournalEntry(...)once to persist a safe operational record.
import { createContextBundle } from "contextia";
const bundle = await createContextBundle("/path/to/workspace")
.setBudget(10_000)
.addManualSource({
id: "manual:brief",
label: "Brief",
content: "Keep deterministic ordering explicit.",
priority: 50,
group: "reference",
})
.setOrdering({
kindWeights: { convention: 0, manual: 1 },
groupRanks: { reference: 0, optional: 50 },
sourceOverrides: { "manual:brief": { rank: 0 } },
})
.build();buildContextBundle(options) is still available as a soft-migration wrapper. It maps legacy options to the builder internally and preserves deterministic behavior when ordering is omitted.
Legacy call:
await buildContextBundle({
workspacePath,
budget: 10_000,
manualSources: [{ id: "manual:brief", label: "Brief", content: "x", priority: 50 }],
});Builder equivalent:
await createContextBundle(workspacePath)
.setBudget(10_000)
.addManualSource({ id: "manual:brief", label: "Brief", content: "x", priority: 50 })
.build();- Example file:
examples/canonical-context-bundle.ts - Run it from a workspace root that contains
AGENTS.mdandMEMORY.mdbecause it usesprocess.cwd()asworkspacePath. - Example:
cd test/fixtures/workspace-basicbun ../../../examples/canonical-context-bundle.ts
createContextBundle(workspacePath)buildContextBundle(options)writeJournalEntry(options)
bun testbun run typecheckbun run build