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
impl Context
Sourcepub fn load_from(path: &Path) -> Context
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.
Sourcepub fn save_to(&self, path: &Path) -> Result<()>
pub fn save_to(&self, path: &Path) -> Result<()>
Save the context to an explicit file path.
Normalises labels first:
- Trim whitespace from each label.
- Drop blank labels.
- 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.
Sourcepub fn load_global(paths: &ContextPaths) -> Context
pub fn load_global(paths: &ContextPaths) -> Context
Load the global context from the given resolved paths.
Sourcepub fn load_worktree(paths: &ContextPaths) -> Option<Context>
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.
Sourcepub fn save_global(&self, paths: &ContextPaths) -> Result<()>
pub fn save_global(&self, paths: &ContextPaths) -> Result<()>
Save to the global context path.
Sourcepub fn save_worktree(&self, paths: &ContextPaths) -> Result<()>
pub fn save_worktree(&self, paths: &ContextPaths) -> Result<()>
Save to the per-worktree context path. Errors if called from a Primary scope.
Sourcepub fn merge_layers(layers: &[&Context]) -> EffectiveContext
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,Nonedeletes an inherited key. Effective params are string-only.
Sourcepub fn effective(
start_dir: &Path,
user_layer: Option<&Path>,
) -> EffectiveContext
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.
Sourcepub fn effective_with_parts(
start_dir: &Path,
user_layer: Option<&Path>,
) -> (ContextPaths, Option<Context>, Context, Option<Context>, EffectiveContext)
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).