Contexel 0.1.17

dotnet add package Contexel --version 0.1.17
                    
NuGet\Install-Package Contexel -Version 0.1.17
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Contexel" Version="0.1.17" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Contexel" Version="0.1.17" />
                    
Directory.Packages.props
<PackageReference Include="Contexel" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Contexel --version 0.1.17
                    
#r "nuget: Contexel, 0.1.17"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Contexel@0.1.17
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Contexel&version=0.1.17
                    
Install as a Cake Addin
#tool nuget:?package=Contexel&version=0.1.17
                    
Install as a Cake Tool

Contexel

Deterministic, dependency-free context shaping for code-writing agents — the C# build of contexel (also on PyPI and npm).

Tool calls return verbose, duplicated, sometimes hostile data. Contexel sits at the tool → context boundary and shapes it: select the fields that matter, drop duplicates, gate by provenance, quarantine injection patterns, rescore by relevance, truncate, rank, and trim to a token budget — every stage a pure function over List<Dictionary<string, object?>>, every run reproducible, every drop attributable in an audit record.

This package is a parity port, not a re-imagining. The Python implementation is canon; all three languages run their test suites against the same golden vectors (parity/vectors.json, generated by Python), so the same records, policy, and budget produce the same shaped output. Because .NET preserves the int/float distinction, the C# port has a stricter parity envelope than the TypeScript one. Design and boundaries: ADR-002.

Install

dotnet add package Contexel     # zero runtime dependencies, net8.0

Sixty seconds

using Contexel;
using Rec = System.Collections.Generic.Dictionary<string, object?>;

var raw = await SearchTool(userQuery);   // a batch of verbose results

using var t = Trace.Begin(idField: "url");
var r = Stages.Select(raw, new[] { "title", "url", "snippet" });
r = Stages.Dedupe(r, "url");
r = Stages.Rescore(r, userQuery, new[] { "title", "snippet" });
r = Stages.TruncateField(r, "snippet", maxTokens: 120);
r = Stages.Rank(r, "score", desc: true);
r = Stages.TrimToBudget(r, maxTokens: 1500, minRecords: 1);

Console.WriteLine(t.Report());   // per-stage: records in -> out, tokens before -> after
var audit = t.Audit();           // policy fingerprints + which stage dropped which IDs

Or pin the policy at the tool boundary, so the model never sees raw output:

var pipe = new Pipeline(
    new Stage("select", r => Stages.Select(r, new[] { "path", "line", "snippet" })),
    new Stage("dedupe", r => Stages.Dedupe(r, new[] { "path", "line" })),
    new Stage("trim_to_budget", r => Stages.TrimToBudget(r, 2000)));

var searchCode = Shaped.Wrap(pipe, (string query) => Repo.Search(query));
// async tools are awaited, then shaped — same policy, every call

The eight stages

Stage What it does
Select keep only the listed fields
Dedupe drop duplicates by key or whole-record fingerprint (type-aware: 1, 1.0, "1", true all distinct)
Allowlist fail-closed provenance gate (missing field reads as null, kept only if null is explicitly allowed)
Quarantine drop or flag records matching injection patterns; custom patterns extend the built-ins — replacePatterns: true is the explicit opt-out
Rescore batch BM25 relevance with word-boundary matching and in-order proximity bonus
Rank stable sort by field or key function; missing-field records sort last
TruncateField cut one field to a token budget, suffix
TrimToBudget keep records until the budget is spent; minRecords guarantees the best records survive a too-small budget

Plus Merge for combining sources, Pipeline/Stage with stable policy fingerprints, Trace/Audit for the governance record, and Tokens.Scoped (AsyncLocal) for concurrency-safe per-tenant token accounting.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.17 0 7/28/2026