pub struct ContextEntry {Show 15 fields
pub uri: String,
pub kind: String,
pub title: Option<String>,
pub provenance: EntryProvenance,
pub tier: Tier,
pub relevance: f64,
pub confidence: f64,
pub discovered_by: Vec<Discovery>,
pub depth: usize,
pub cost_tokens: u64,
pub cost_bytes: u64,
pub version: Option<String>,
pub status: Option<String>,
pub required: bool,
pub facts: BTreeMap<String, String>,
}Expand description
One thing the compiler decided a session should be given: what it is, how it was reached, what it costs, and how far the compiler trusts it.
Notably, it does not carry the prose. The identifier is here and the body is not,
because the body belongs to the object and objects.get serves it whole; copying it
would put the layer in the answer twice and flatten the structure into text before
anything had decided what to keep. An entry is a decision about an object, not a copy of
one.
Three of the scalars are derived from discovered_by rather than independent of it, and
a reader can check them: confidence is the highest of any path’s, depth the shortest,
and a discovered_by of length above one is the evidence that deduplication happened.
required is the veto — a blocking rule, the policy, the scope, or a seed — and it is
the one field that overrides the budget.
use majordomus_cli::devcontext::{tokens_for, ContextEntry, Selector, Tier};
use serde_json::json;
// one ADR, reached twice: once along a declared edge and once by matching the intent
let e: ContextEntry = serde_json::from_value(json!({
"uri": "majordomus://adr/0052",
"kind": "adr",
"title": "The episode is the boundary",
"provenance": {
"path": ".ai/repo/adrs/0052.md", "directory": ".ai/repo/adrs",
"source_class": "adr", "section": "adrs", "bytes": 8_192,
},
"tier": "decision",
"relevance": 0.82,
"confidence": 1.0,
"discovered_by": [
{"selector": "relation", "reason": "in force over this scope",
"via": "majordomus://issue/I0301", "edge": "governed_by",
"depth": 1, "confidence": 1.0, "weight": 0.9},
{"selector": "intent_match", "reason": "the intent's words occur in it",
"depth": 2, "confidence": 0.4, "weight": 0.4},
],
"depth": 1,
"cost_tokens": 2_048,
"cost_bytes": 8_192,
"version": "2026-09-11",
"status": "accepted",
"required": false,
})).unwrap();
assert_eq!(e.tier, Tier::Decision);
// the cost is the estimate over the measured bytes, and the answer carries both halves
assert_eq!(e.cost_tokens, tokens_for(e.cost_bytes));
// the derived scalars agree with the paths they are derived from
let best = e.discovered_by.iter().map(|d| d.confidence).fold(0.0_f64, f64::max);
assert_eq!(e.confidence, best);
assert_eq!(e.depth, e.discovered_by.iter().map(|d| d.depth).min().unwrap());
// two paths for one entry: the record that four things pointing here is one entry
assert_eq!(e.discovered_by.len(), 2);
assert_eq!(e.discovered_by[0].selector, Selector::Relation, "best path first");
// and the prose is not here: the identifier is how a caller gets the body
assert!(e.uri.starts_with("majordomus://"));Fields§
§uri: StringThe canonical identifier: majordomus://<kind>/<identity>, unique in the answer.
kind: StringThe kind the layer declared for it.
title: Option<String>Its title, when it has one.
provenance: EntryProvenanceWhere it lives.
tier: TierWhich tier’s budget it is spent from.
relevance: f640.0 to 1.0, deterministic for a given tree and request. The order within a tier.
confidence: f64The highest confidence of any path that reached it.
discovered_by: Vec<Discovery>Every path that reached it, best first. Length above one is the evidence that deduplication happened.
depth: usizeThe shortest number of hops from a seed.
cost_tokens: u64Estimated tokens: the file’s bytes divided by BYTES_PER_TOKEN, never fewer
than one. An estimate, said to be one.
cost_bytes: u64The file’s bytes, the measured half of the cost.
version: Option<String>The version or date the object states about itself, when it states one: a rule’s
version, an ADR’s date, an issue’s updated_at.
status: Option<String>The status word the object declares, when it declares one.
required: boolTrue when a blocking rule, a policy or the scope: never dropped for budget.
facts: BTreeMap<String, String>Facts worth carrying about this entry that are not the object’s prose — a rule’s class, an issue’s milestone, the commits an issue’s evidence names.
Trait Implementations§
Source§impl Clone for ContextEntry
impl Clone for ContextEntry
Source§fn clone(&self) -> ContextEntry
fn clone(&self) -> ContextEntry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ContextEntry
impl Debug for ContextEntry
Source§impl<'de> Deserialize<'de> for ContextEntry
impl<'de> Deserialize<'de> for ContextEntry
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for ContextEntry
impl JsonSchema for ContextEntry
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl PartialEq for ContextEntry
impl PartialEq for ContextEntry
Source§fn eq(&self, other: &ContextEntry) -> bool
fn eq(&self, other: &ContextEntry) -> bool
self and other values to be equal, and is used by ==.