Skip to main content

Context

Struct Context 

Source
pub struct Context {
    pub flow_id: Option<String>,
    pub labels: Vec<String>,
    pub params: BTreeMap<String, Option<String>>,
}
Expand description

Active context written by tracevault context set and read by the CC hook.

Stored as pretty-printed JSON at .visdom/context.json. BTreeMap is used for params so keys are always in sorted order on disk, giving stable, human-readable diffs.

Fields§

§flow_id: Option<String>§labels: Vec<String>

Deduplicated, non-empty labels. Duplicates are removed on save (first occurrence wins); blank/whitespace-only entries are dropped.

§params: BTreeMap<String, Option<String>>

Stored params. Some(v) sets a value; None is a delete tombstone that removes an inherited key from a lower-precedence layer during the merge. On disk, Some("v") serializes as "v" and None as null.

Implementations§

Source§

impl Context

Source

pub fn load_from(path: &Path) -> Context

Load the context from an explicit file path.

  • Missing file → Context::default() (silent).
  • Malformed JSON → Context::default() + a warning printed to stderr.

Use ContextPaths::global_path() or ContextPaths::worktree_path() to obtain the correct path for the current worktree context.

Source

pub fn save_to(&self, path: &Path) -> Result<()>

Save the context to an explicit file path.

Normalises labels first:

  1. Trim whitespace from each label.
  2. Drop blank labels.
  3. Deduplicate: first occurrence wins.

Creates the parent directory (including worktrees/<key>/) if it does not exist.

Use save_global or save_worktree for scope-aware saves.

Source

pub fn load_global(paths: &ContextPaths) -> Context

Load the global context from the given resolved paths.

Source

pub fn load_worktree(paths: &ContextPaths) -> Option<Context>

Load the per-worktree context (if in a linked worktree and the file exists).

Returns None when:

  • In a primary checkout (no per-worktree path).
  • In a linked worktree but the per-worktree file does not yet exist.

Returns Some(ctx) only when the file exists and was successfully (or partially) loaded.

Source

pub fn save_global(&self, paths: &ContextPaths) -> Result<()>

Save to the global context path.

Source

pub fn save_worktree(&self, paths: &ContextPaths) -> Result<()>

Save to the per-worktree context path. Errors if called from a Primary scope.

Source

pub fn merge_layers(layers: &[&Context]) -> EffectiveContext

Fold layers low→high into the effective context.

  • flow_id: highest layer that sets a non-null value wins.
  • labels: union across layers, deduped, low→high stable order.
  • params: JSON merge-patch per layer — Some(v) sets/overrides, None deletes an inherited key. Effective params are string-only.
Source

pub fn effective( start_dir: &Path, user_layer: Option<&Path>, ) -> EffectiveContext

Load user (if given) + global + per-worktree and return the merged effective context that the hook stamps.

Source

pub fn effective_with_parts( start_dir: &Path, user_layer: Option<&Path>, ) -> (ContextPaths, Option<Context>, Context, Option<Context>, EffectiveContext)

Like effective, returning each layer separately (for show). Tuple: (paths, user, global, worktree, effective).

Trait Implementations§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Self

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 Context

Source§

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

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

impl Default for Context

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Context

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 PartialEq for Context

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for Context

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 Context

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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