Skip to main content

GraphContext

Struct GraphContext 

Source
pub struct GraphContext {
    pub items: Vec<ContextItem>,
    pub dropped_items: usize,
}
Expand description

The graph context handed to one file’s review.

GraphContext::none is the diff-only arm, and build_prompt renders no context section for it, so the baseline prompt carries no vestigial heading promising something that is not there.

§What is in it, and why those and not the rest

The menu roteiro review already computes is governing ADRs, callers, callees, blast radius and authored drift. The arm takes two of those and records the omission of the others as a decision:

  • Governing ADR and blueprint sections (authored). The one thing a per-file reviewer structurally cannot obtain: a decision written in another file that the code under review contradicts. This is contract-drift’s defining shape and the authored layer’s whole purpose.
  • The file’s own doc surface outside the diff (derived). build_prompt instructs the model to stay silent unless both halves of a conflict are visible, and a -U3 diff shows at most three lines either side. A doc comment at the top of a file and the code that betrays it 700 lines down are never both in the hunks. The graph holds each symbol’s doc comment, so this makes the promise-half visible without pasting the file.
  • Callers, callees and blast radius are deliberately excluded. Measured on this repository a single changed symbol carries dozens of caller keys, and their bodies would dominate the prompt — the failure mode above, bought knowingly. Recorded here so the absence reads as a decision rather than an oversight, and so a later arm that adds them knows it is changing a pre-registered variable.

Fields§

§items: Vec<ContextItem>

The items, in the order they are rendered.

§dropped_items: usize

Items dropped by GraphContext::fit to stay inside the cap.

Counted rather than silently absorbed, for the same reason Prompt::dropped_tokens is: a run that quietly shed the context it was measuring would report the graph arm as having been tested when it was partly the diff-only arm wearing its name.

Implementations§

Source§

impl GraphContext

Source

pub fn none() -> Self

No context — the diff-only arm.

Source

pub fn is_empty(&self) -> bool

Whether any context is present.

Source

pub fn tokens(&self) -> usize

Estimated tokens this context will cost, by estimate_tokens over the text build_prompt actually renders — label, provenance tag and body.

Source

pub fn fit(items: Vec<ContextItem>, diff_tokens: usize) -> Self

Drop whole items, lowest-priority last-first, until the context fits the cap for a diff of diff_tokens.

Whole items, never a truncated one. A half-quoted ADR is worse than no ADR: it reads as a complete statement of a decision and is not one, so a model can be handed a promise whose exception was cut off and report the code as contradicting it. build_prompt makes the same choice for the same reason and truncates only the diff.

Callers pass items in priority order — most valuable first — because this drops from the tail.

Trait Implementations§

Source§

impl Clone for GraphContext

Source§

fn clone(&self) -> GraphContext

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 GraphContext

Source§

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

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

impl Default for GraphContext

Source§

fn default() -> GraphContext

Returns the “default value” for a type. Read more
Source§

impl Eq for GraphContext

Source§

impl PartialEq for GraphContext

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for GraphContext

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
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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

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.