pub struct Context {
pub flow_id: Option<String>,
pub labels: Vec<String>,
pub params: BTreeMap<String, String>,
}Expand description
Active context written by tracevault context set and read by the CC hook.
Stored as pretty-printed JSON at .tracevault/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, String>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_effective(global: &Context, worktree: Option<&Context>) -> Context
pub fn merge_effective(global: &Context, worktree: Option<&Context>) -> Context
Compute the effective context by merging global and per-worktree contexts:
flow_id: worktree wins if set, otherwise falls back to global.labels: global ∪ worktree (dedup, global-first order, stable).params: global then worktree overwrites keys (worktree takes precedence).
Sourcepub fn effective(start_dir: &Path) -> Context
pub fn effective(start_dir: &Path) -> Context
Resolve paths from start_dir, load global + per-worktree, and return the
merged effective context. This is what the hook stamps.
Sourcepub fn effective_with_parts(
start_dir: &Path,
) -> (ContextPaths, Context, Option<Context>, Context)
pub fn effective_with_parts( start_dir: &Path, ) -> (ContextPaths, Context, Option<Context>, Context)
Like effective, but also returns the resolved paths, global, and per-worktree
contexts separately (for show to display all three).