toolpath
Core types, builders, and query operations for Toolpath provenance documents.
Overview
This crate provides the type system for Toolpath -- a format for tracking artifact transformation provenance. It contains:
- Types:
Document,Graph,Path,Step,ArtifactChange, and all supporting structures - Builders: Convenient constructors and builder methods for constructing documents
- Serde: Full serialization/deserialization with
#[serde(untagged)]document discrimination - Query: Graph traversal and filtering operations on step DAGs
This is the gravity well of the workspace. All other crates depend on toolpath; it depends on nothing except serde and serde_json.
Types
Document (enum: Graph | Path | Step)
Graph
graph: GraphIdentity { id }
paths: Vec<PathOrRef> -- inline Path or $ref
meta?: GraphMeta
Path
path: PathIdentity { id, base?, head }
steps: Vec<Step>
meta?: PathMeta
Step
step: StepIdentity { id, parents, actor, timestamp }
change: HashMap<String, ArtifactChange>
meta?: StepMeta
Building documents
use ;
// Build a step
let step = new
.with_parent
.with_raw_change
.with_intent
.with_vcs_source;
// Build a path
let path = new;
// Branch from another path's step
let base = toolpath;
Query operations
The query module provides graph traversal and filtering over step slices:
use query;
// Walk the parent chain from head
let ancestors = ancestors;
// Find abandoned branches
let dead_ends = dead_ends;
// Filter by actor type
let human_steps = filter_by_actor;
let agent_steps = filter_by_actor;
// Filter by artifact
let main_rs = filter_by_artifact;
// Time range
let recent = filter_by_time_range;
// Summaries
let all_files = all_artifacts;
let all_actors = all_actors;
let index = step_index; // id -> &Step
Serialization
Documents roundtrip through JSON:
use Document;
let doc = from_json?;
let json = doc.to_json_pretty?;
The Document enum uses #[serde(untagged)] and discriminates by structure: it tries Graph (has graph + paths), then Path (has path + steps), then Step (has step + change).