Skip to main content

cargo_crosscut/
types.rs

1use std::path::PathBuf;
2
3use serde::{Deserialize, Serialize};
4
5// ── Project layout (compartmentalization) ───────────────────────────────────
6
7/// A logical subunit of a project for compartmentalized analysis.
8///
9/// Large projects are split into compartments so that each analysis pass
10/// operates on a bounded slice of the source tree, keeping within model
11/// context-window limits.
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct Compartment {
14    /// Human-readable label (e.g. `"yh-core"`, `"yh-cli + yh-mcp"`).
15    pub label: String,
16    /// Relative paths from project root to the directories this compartment covers.
17    pub paths: Vec<PathBuf>,
18    /// Estimated lines of source code.
19    pub estimated_loc: usize,
20}
21
22/// Cross-boundary analysis tile spanning two compartments.
23///
24/// Overlap tiles are read-only analysis units — they produce findings
25/// but never modify code directly. Findings are routed to the owning
26/// compartment for remediation.
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct OverlapTile {
29    /// Human-readable label (e.g. `"yh-core <> yh-cli"`).
30    pub label: String,
31    /// Index of the left compartment in the `compartments` vec.
32    pub left_idx: usize,
33    /// Index of the right compartment in the `compartments` vec.
34    pub right_idx: usize,
35    /// Union of both compartments' relative paths.
36    pub paths: Vec<PathBuf>,
37    /// Combined estimated LOC.
38    pub estimated_loc: usize,
39    /// Number of direct Cargo dependency edges crossing this boundary.
40    pub dependency_edges: usize,
41    /// Scheduling priority derived from coupling strength.
42    pub priority: OverlapPriority,
43}
44
45/// Priority classification for overlap tile scheduling.
46#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
47pub enum OverlapPriority {
48    /// No dependency edges and no indirect coupling — skip by default.
49    None,
50    /// Indirect coupling only (shared transitive workspace deps).
51    Low,
52    /// 1–2 direct dependency edges between compartments.
53    Medium,
54    /// 3+ direct dependency edges — strong coupling, analyze first.
55    High,
56}
57
58/// A directed dependency edge between two crates: `from` depends on `to`.
59/// Names are crate directory names (e.g. `"yh-core"`, `"yh-cli"`).
60#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct ConnectomeEdge {
62    pub from: String,
63    pub to: String,
64}
65
66/// Result of analyzing a project's structure for compartmentalization.
67#[derive(Debug, Clone, Serialize, Deserialize)]
68pub enum ProjectLayout {
69    /// Project is small enough to handle as a single unit.
70    Whole,
71    /// Project should be split into compartments for analysis.
72    Compartmentalized {
73        compartments: Vec<Compartment>,
74        /// Overlap tiles for cross-boundary analysis (empty if ≤1 compartment).
75        overlap_tiles: Vec<OverlapTile>,
76        /// Workspace dependency graph (crate-level directed edges).
77        connectome: Vec<ConnectomeEdge>,
78        /// Total estimated LOC across all compartments.
79        total_loc: usize,
80    },
81}