Skip to main content

ContextEntry

Struct ContextEntry 

Source
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: String

The canonical identifier: majordomus://<kind>/<identity>, unique in the answer.

§kind: String

The kind the layer declared for it.

§title: Option<String>

Its title, when it has one.

§provenance: EntryProvenance

Where it lives.

§tier: Tier

Which tier’s budget it is spent from.

§relevance: f64

0.0 to 1.0, deterministic for a given tree and request. The order within a tier.

§confidence: f64

The 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: usize

The shortest number of hops from a seed.

§cost_tokens: u64

Estimated tokens: the file’s bytes divided by BYTES_PER_TOKEN, never fewer than one. An estimate, said to be one.

§cost_bytes: u64

The 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: bool

True 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

Source§

fn clone(&self) -> ContextEntry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ContextEntry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ContextEntry

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl JsonSchema for ContextEntry

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for ContextEntry

Source§

fn eq(&self, other: &ContextEntry) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ContextEntry

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ContextEntry

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more