Expand description
Typed dependency-tree and explain models for cabin tree and
cabin explain.
cabin metadata already exposes the loaded package state as
a deterministic JSON document. This crate adds two
complementary, lower-bandwidth views on the same loaded
PackageGraph + lockfile + active patch / source-replacement
state:
-
build_treereturns aTreeNodeshowing every package in the loadedPackageGraphreachable from the selected primary packages, with edges tagged bycabin_core::DependencyKindand provenance pulled from the lockfile / active patch set. Renderers (render_tree_human/render_tree_json) turn the typed tree into either a stable text drawing or a structured JSON document; the JSON document shares its package shape withcabin metadata. -
explain_package/explain_target/explain_source/explain_feature/explain_build_configeach return a typedExplanationanswering “why is X selected”, “where does X come from”, “which feature lit up X”, and “what does the build configuration look like for X”. Each variant carries only structured data so callers can render either a human-readable summary (render_explanation_human) or a stable JSON document (render_explanation_json).
Crate boundaries:
- this crate must not run the resolver, parse manifests, or plan builds; it consumes the typed values the orchestration layer hands it;
- it must not perform I/O. The orchestration layer in
cabinis responsible for loading the workspace, the lockfile, and the active patch set; this crate works purely on those typed inputs; - it must not invent new identity for packages. Provenance
comes from
cabin_workspace::PackageKind, the lockfile, the patch set, and the source-replacement settings.
§Determinism contract
Every output produced by this crate is deterministic across runs:
- tree children are sorted by
(dependency_kind, package_name, package_version); - explanation paths are sorted by
(length, joined name sequence); - JSON keys are emitted in struct-declaration order;
- paths surfaced through the API are not normalized here — that is the orchestration layer’s job.
Anything that mutates the inputs is the orchestration layer’s responsibility; this crate only reads them.
Modules§
- cabin_
feature_ per_ package_ view - Stand-in module that names the per-package feature view this
crate consumes through a thin
&FeatureViewparameter. The orchestration layer (cabin) already builds the typedcabin_feature::FeatureResolution; rather than depending on the full crate from a query-only library, we accept an abstract view object so the orchestration layer can adapt the existing types into our shape without leaking the resolver crate boundary.
Structs§
- Explain
Step - One step in a
PackageExplanation::pathschain. - Feature
Explanation - Explain a feature’s enablement: declared, enabled, what it implies, and which root pulled it in if any.
- Package
Explanation - Explain why a package is in the resolved graph, who pulled it in, and which dependency edge introduced it.
- Source
Explanation - Explain where a package’s source bytes came from.
- Target
Explanation - Explain a target’s owning package, kind, language summary,
and dependency edges.
cabin explain target <name>only considers targets in the selected package closure. - Tree
Inputs - Per-call options for
build_tree. Mirrors the same dependency-kind filtercabin tree --kind ...exposes, plus the optionalLockfile/ patch / vendor / source-replacement inputs used to color provenance. - Tree
Node - One node in a dependency tree rooted at a selected primary
package. Children are deduplicated per traversal: the first
occurrence of a
(name, version)carries the full subtree; subsequent occurrences are marked withTreeNode::repeated.
Enums§
- Explain
Error - Errors produced by the explain queries. Wording is stable so integration tests can match on substrings.
- Explanation
- Typed explanation chain returned by every
cabin explainquery. Renderers read the variant to choose the layout; the JSON output is a tagged union so downstream tooling sees the query kind without re-parsing. - Source
Provenance - Provenance label for one node in a
TreeNodeor one step in anExplanation::Packagechain.
Functions§
- build_
tree - Build a deterministic
TreeNodeforest rooted at every index inroots. Returned as a single root-less synthetic vector with the documented sort key applied at every level so renderers can iterate without re-sorting. - explain_
build_ config cabin explain build-config <package>returns the package’s resolvedcabin_core::BuildConfiguration. The orchestration layer already knows how to render it throughBuildConfiguration::as_json, so this crate just looks it up.- explain_
feature - Build a
FeatureExplanationforpackage/feature. The query string must contain a single/separating the package name from the feature name; an unrecognized shape is rejected withExplainError::InvalidFeatureQuery. - explain_
package - Build a
PackageExplanationforname. ReturnsExplainError::PackageNotFoundwhen the name is not in the resolved graph; returnsExplainError::AmbiguousPackageNameif a future graph gains multiple packages with the same name from distinct sources (today the resolver enforces unique names). - explain_
source - Build a
SourceExplanationfor the named package. - explain_
target - Build a
TargetExplanationfortarget_name, scoped to the selected packages. ReturnsExplainError::TargetNotFoundif the name does not exist in any selected package, with a list of candidate names for the diagnostic. - render_
explanation_ human - Render an
Explanationas a concise human-readable summary suitable for terminal output. - render_
explanation_ json - Render an
Explanationas a stable JSON document. - render_
tree_ human - Render a
TreeNodeforest as a human-readable Unicode drawing. Output is deterministic: every level sorts by(edge_kind, name, version)before this rendering runs, so callers can compare two renderings byte-for-byte. - render_
tree_ json - Render the forest as a stable JSON document.