ainl-context-compiler 0.1.0

LLM context-window assembly: multi-segment, role-aware, question-aware prompt orchestration for AINL hosts. Phase 6 of SELF_LEARNING_INTEGRATION_MAP. Distinct from `ainl-context-freshness` which gates tool execution based on repo-knowledge currency.
Documentation

AINL Context Compiler — LLM context-window assembly

Phase 6 of SELF_LEARNING_INTEGRATION_MAP.md.

Multi-segment, role-aware, question-aware prompt orchestration with progressive-enhancement capability tiers (heuristic → LLM-driven anchored summarization → embedding-based relevance).

Boundary vs ainl-context-freshness

These two crates share a name prefix but solve different problems:

Crate Lifecycle phase "Context" means
ainl-context-freshness Pre-tool execution policy gate the agent's knowledge of the world (repo/index state vs HEAD)
ainl-context-compiler (this crate) Prompt assembly / window management the LLM's input context window (prompt bytes about to be sent)

ainl-context-compiler consumes ainl-context-freshness as a per-segment rank-down signal (stale segments are ranked lower) — see [relevance::HeuristicScorer].

See docs/ainl-crates-overview.md for the broader ainl-* family map.

Design tiers (auto-detected at runtime)

  • Tier 0 — Heuristic (always available): question-token overlap × recency × freshness; per-segment compression via [ainl_compression].
  • Tier 1 — Anchored summarization (M2): when a [summarizer::Summarizer] is injected, older history collapses into a structured AnchoredSummary (Factory.ai pattern).
  • Tier 2 — Embedding rerank (M3): when an [embedder::Embedder] is injected, segments are reranked by cosine similarity to the latest user message.

Each tier auto-degrades on per-call failure; the system never blocks on optional capabilities.

Telemetry sink (canonical pattern from §15.4)

Mirrors [ainl_compression::CompressionTelemetrySink] exactly. Hosts implement [ContextEmissionSink] once and pass it via [orchestrator::ContextCompiler::with_sink]; everything downstream just emits structured events.

Telemetry field names come from ainl_contracts::telemetry constants prefixed CONTEXT_COMPILER_* so dashboards, Prometheus exporters, and CI gates reference them consistently across hosts.